NexusFi: Find Your Edge


Home Menu

 





Cutting off extended Rectangle


Discussion in Sierra Chart

Updated
    1. trending_up 1,336 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Cutting off extended Rectangle

  #1 (permalink)
NaturePip
Cochrane Alberta Canada
 
Posts: 12 since Nov 2013
Thanks Given: 1
Thanks Received: 21

Hello Everyone:

Let me start by saying that I enjoy scripting but I am not all that good at it yet. I am currently writing a script and could use some advice.

MY script examines the close of the LAST candle on the chart and if it is lower than the low of candle previous candle, then it draws an extending rectangle around the previous candle. I have this part working fine.

The part I am not sure how to do is how to reference the rectangle once price comes up and intersects the low of the rectangle so I can then convert the extending rectangle to a regular rectangle to cut it off at this point. Should I use a persistent variable or an array? Also, how do I delete the reference or do I need to.... Not certain how to fully do this.

Below is the what I have written so far....


if (sc.GetBarHasClosedStatus(sc.Index) != BHCS_BAR_HAS_CLOSED)
return;

const float LastClosedCandle = sc.Close[sc.Index];
const float SecondLastCandleLow = sc.Low[sc.Index - 1];
const float SecondLastCandleHigh = sc.High[sc.Index - 1];


if (LastClosedCandle < SecondLastCandleLow)
{
double BeginTime = sc.BaseDateTimeIn[sc.Index - 1];
double EndTime = sc.BaseDateTimeIn[sc.Index];

const float LastCandleHigh = sc.High[sc.Index];

s_UseTool(Tool);

Tool.Clear();
Tool.AddAsUserDrawnDrawing = 1;
Tool.ChartNumber = sc.ChartNumber;
Tool.DrawingType = DRAWING_RECTANGLE_EXT_HIGHLIGHT;
Tool.BeginDateTime = BeginTime;
Tool.EndDateTime = EndTime;
Tool.BeginValue = SecondLastCandleLow;
Tool.EndValue = LastCandleHigh;
Tool.Color = COLOR_YELLOW;
Tool.LineWidth = 1;
Tool.LineStyle = LINESTYLE_DOT;
Tool.SecondaryColor = COLOR_YELLOW;
Tool.TransparencyLevel = 90;
Tool.AddMethod = UTAM_ADD_OR_ADJUST;

sc.UseTool(Tool);
}

Thank you... Any help with regards to the referencing of the rectangle when it is intersected would be greatly appreciated.

thanks,

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
50 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #2 (permalink)
Zambi
Scottsdale
 
Posts: 34 since Nov 2010
Thanks Given: 6
Thanks Received: 22

Hi NaturePip.

I'm not sure I understand the requirement. Since you're drawing a rectangle, its upper and lower PRICE values will remain unchanged even though it extends in TIME to whatever point. So you should be able to simply compare the current price to whatever your're setting Tool.BeginValue and Tool.EndValue to; in your case it's SecondLastCandleLow and LastCandleHigh.

(Things would have been tricky if you were drawing a sloping line (e.g. an extended Ray) where you don't know price touched by that ray at a certain point in time.)

That being said, why don't you use Subgraphs to store the values of SecondLastCandleLow and LastCandleHigh for every candle? If you don't want the subgraphs painted on chart, simply set their type to DRAWSTYLE_HIDDEN or DRAWSTYLE_IGNORE.

Let's say you assigned LastCandleHigh to sc.Subgraph[1]. For any candle on the chart, you can for example use the sc.CrossOver function to detect when price is crossing your (hidden) subgraph.

In addition, in Sierra there are multiple arrays attached to each subgraph array, which you can use to store values. So you can, for example, use those arrays to store the rectangle's Top and the rectangle's bottom for every candle on the chart. Again, detetcting intersections here would simply entail using the CrossOver() function.

I hope this helps.

Reply With Quote
  #3 (permalink)
NaturePip
Cochrane Alberta Canada
 
Posts: 12 since Nov 2013
Thanks Given: 1
Thanks Received: 21


Hello Zambia:

Just wanted to thank you very much for your input. I am not certain I have fully wrapped my head around what you are suggesting yet but let me play with your idea some more. I did try using subgraphs early on in the development of this study but did not have much success. However, I didn't try it the way you are suggesting. I think I also ran into some stumbling block with the drawing type....

In any event, I will try it again with your suggestion and let you know how I make out by posting my results here.

thank you

NaturePip

Reply With Quote
  #4 (permalink)
NaturePip
Cochrane Alberta Canada
 
Posts: 12 since Nov 2013
Thanks Given: 1
Thanks Received: 21

Hi Zambia:

I remember why I am not using Subgraph now. It is because there is NO horizontal rectangle or extended rectangle Draw Style under Subgraphs. There is a Fill Rectangle to Top and Bottom but that is not what I need. Therefore, if the drawing style does not exist, how do I use it?

That's why I am using the sc.UseTool function. Because under this function, there is a Rectangle and Extended Rectangle Draw Type.

Notice the distinction. Subgraphs use Draw STYLE and sc.UseTool use Draw TYPE.

Anyway, I am back to my original question of how to reference rectangle so I may modify the Tool.EndDateTime parameter to end the rectangle from drawing any further, once price hits the low of the rectangle (which would be the low of the candle I reference).

Like I said, I am not the best programmer and I am still very much learning my way around AsciL.

thanks again,

Reply With Quote
  #5 (permalink)
Zambi
Scottsdale
 
Posts: 34 since Nov 2010
Thanks Given: 6
Thanks Received: 22

Hi Nature

One way of doing this is to "name" each rectangle. One member you're not using in your code is .LineNumber, which allows you to assign an arbitrary number to each drawing.

Use a persistent variable to hold a counter, and increment that counter as each new rectangle is introduced to the chart. From then on, you can call each rectangle by its number, and change its settings (start, end, colour, etc).

So, when the conditions are true for creating a NEW rectangle, and before you draw that new rectangle, you reference the CURRENT most recent rectangle using its .LineNumber, and change its drawtype to a non-extending rectangle, and set its .EndDateTime.

P.S. Unless there's a specific need for using DateTime's to set beginning and end, I've always found it more manageable to set beginnings and endings using a bar index number.

Reply With Quote
  #6 (permalink)
NaturePip
Cochrane Alberta Canada
 
Posts: 12 since Nov 2013
Thanks Given: 1
Thanks Received: 21

Hi Zambia:

Thank you again for your response. I greatly appreciate it. I hope you and everyone else who I reading this post had, or is having, a wonderful holiday.

I have actually started working with .LineNumber persistent variable and have setup a counter for it that increments with each new rectangle created.

Couple things I should clarify.... first, regarding the bar index.... Once I create a new rectangle on my higher time frame, I want to copy it to the lower time frame. That's fine, I simply use the .ChartNumber to draw an additional rectangle to the chart I desire. (I tried copying the rectangle via Chart Settings - Copy, but that did not work, even though I used the .AddAsUserDrawnDrawing when I created the rectangle in my study). Anyway, during development of this COPY, I was in fact using the Bar Index instead of .DateTime. It worked great as long as I stuck to the one chart. However, the rectangles were not copying correctly to the lower time frame chart. The "Value" levels were correct, but not the "DateTime", on the lower time frame chart. That is why I had to use the .BeginDateTime and .EndDateTime. Once I made that switch, the rectangles appeared on both charts without any errors.

Second, regarding .LineNumber.... You said that before I create a NEW rectangle, I should reference the current most recent rectangle and set its .EndDateTime. However, I only want to set the .EndDateTime once price comes back up and HITS to low of the rectangle...which will always be value at my SecondLastCandleLOW variable.

Therefore, I require another persistent variable (ValueDown) that I will increment and hold the "LOW value" information for each newly created rectangle. Since the first persistent variable is just a "name" reference, I cannot use it to test the low of the rectangle. That is why I am thinking I need this second persistent variable.

I am concerned about setting up the second persistent variable since it will need to be a foating number and not an int, since the Value information has decimal places. I hope I can set it up as float. Otherwise, I don't know how I will test the low of the rectangle.

Then, prior to any other testing, I will setup a new if...then condition that will TEST whether price has hit the LOW of a rectangle and if true, then go to most recent current rectangle (via .LineNumber persistent variable) and set its .EndDateTime. Then I will De-increment both persistent variables.

Anyway, that is my current plan. Do not have it on paper yet, just the flow chart. I've never even setup a persistent variable before so hopefully that works. Please let me know what you think of my logic. I am more than happy to hear any suggestions or improvements to this script.

I will let you know how I do by posting my results here.

Thank you,

Reply With Quote





Last Updated on December 28, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts