hi all,
I want to know how to make an indicator but only on the 100 last bar ?
this can working ?
FOR MyBars = 100 DownTO 0 Do
// and here I can execute my indicator and draw for exemple
//but only on the last 100 bars ?
Next
Best Reguards
JC_Bywan
tks you to your quick answer, so if I use the DEFPARAM CalculateOnLastBars for for exemple 20 bars, and I use For boucle from 0 to 100 bars, my For boucle can’t go more then 0 to 10 ?
DEFPARAM CalculateOnLastBars = 20
For X = 0 to 100 Do
// check somethink like on
MyCondition = Condition[X]
// I will be able to check only until the Condition[10]
// even the for For going to 100
I hope my question is clear
Best Reguards
On the description it said only on the indicators but is it valid for the screener ?
The question is clear only if you meant to write defparam calculateonlastbars=10 (instead of 20)
And no, in this case x still goes from 0 to 100 in its “for to next” loop, because it could be used for something else than condition[x] not related to a bar number… but the whole indicator including the loop is calculated only for the last 10 bars.
Then, if left to run live over more candles, values from “return” line are still only for last 10 bars, and graphic objects history (drawtext, drawsegment etc…) remain on all bars since launch.
You can try all sorts of mini-codes in a fast timeframe to experiment with it and grasp what it does. For exemple, you can use this in a 10s timeframe to quickly illustrate above lines:
defparam CALCULATEONLASTBARS=10
for x=0 to 20
text=barindex-x
DRAWTEXT("#text#", barindex, text)
next
DRAWVLINE(barindex)
return barindex, text
Actually, I think I just got what you meant with keeping =20… but the answer is the same: x still goes from 0 to 100 with the loop, because using it in a later line to recall a barindex won’t make this for/next loop stop. Your condition x bars ago at code launch is 0 when that’s more than 20 bars ago, and the calculated value it’s supposed to have if less than 20 bars ago, hence your split in 10 and 10 question I guess… but loop keeps going after 10 until 100. And if your code keeps running for more candles than candle launch, then conditions history gets populated candle by candle, and at some point you’ll have all 100 available.
The limit is: at launch, and after launch for values in “return” line as it keeps going. The rest (graphic objects, data history) is not deleted as it keeps going and more and more of it is available, unless relaunching the indicator therefore creating a new start point.
tks a lot for all your answer, I will try the mini programme and I think yes it’s the best way to learn,
I ask the question by any chance you never know, is there a page or a link with lots of mini program like that to test I think it is a very very good way to learn
Hi, probably not, I just make one up whenever I want to check something