How to test if a statement is true in the last 10 candels?


Category:
0
0

Hi Pete,  I have this code that shows the change in direction of the candles is it possible to plot only the last 2 arrows? if not then plot  only in last ten candles? I don want to see then all over the chart. Thanks for your time

plot uptrendbreak = close > open and close[1] < open[1] and close [2] < open[2] and close[3] < open [3];
plot downtrendbreak = close < open and close[1] > open[1] and close[2] > open[2] and close[3] > open [3];
uptrendbreak.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uptrendbreak .SetDefaultColor(Color.GREEN);
downtrendbreak .SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downtrendbreak .SetDefaultColor(Color.RED);

Attachments:
Marked as spam
Posted by (Questions: 8, Answers: 23)
Asked on August 7, 2019 2:52 pm
93 views
0
Private answer

In order to do this you need to separate each of your plot statements into two pieces.

This:

plot uptrendbreak = close > open and close[1] < open[1] and close [2] < open[2] and close[3] < open [3];
plot downtrendbreak = close < open and close[1] > open[1] and close[2] > open[2] and close[3] > open [3];

Becomes this:

def brokenUptrend = close > open and close[1] < open[1] and close [2] < open[2] and close[3] < open[3];
plot uptrendbreak = IsNaN(close[-10]) and brokenUptrend;
def brokenDowntrend = close < open and close[1] > open[1] and close[2] > open[2] and close[3] > open[3];
plot downtrendbreak = IsNaN(close[-10]) and brokenDowntrend;

I think that should do it. I haven't tested it so give it a try and let us know if it works.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 7, 2019 3:37 pm
0
2 semiclon missing at the end of the def statements after i add that worked great and the last line was not necessary first 4 did the trick. Thanks Pete You are amazing !!
( at August 7, 2019 5:19 pm)
0
Thanks for confirming and advising me of those typo's. I just updated my answer to new visitors will get the version that works. Thanks!
( at August 7, 2019 6:44 pm)