futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:

We are here to help. Just let us know what you need.

We work extremely hard to keep things positive in our community.

We do not tolerate rude behavior, trolling, or vendors advertising in posts.

We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.

We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple.

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.

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.

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.

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.

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.

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.