Good morning,
is there anybody who knows if there’s an easier way to write this code, in which the actual close is > or < of a series of previous close like this?
close>close[1] and close>close[2] and close>close[3] and close>close[4] and close>close[5]....
I need to put in a backtest with a variable X, that is the last of the series,
if X is 5 then .....close>close[1] and close>close[2]....till close>close[5]
Thanks so much
Maxx
x = 5
count = 0
for i = 1 to x
if close > close[i] then
count = count + 1
endif
next
if count = x then
EDIT: Code is now corrected as discussed further down in this thread.
What about
IF close > highest[5](close[1]) THEN...
?
As usual I make the job harder than it needs to be! 🙂
As for the Vonasi’s code, ‘count’ variable should be reset to 0 before the FOR/NEXT loop, otherwise it will endlessly increase.
As for the Vonasi’s code, ‘count’ variable should be reset to 0 before the FOR/NEXT loop, otherwise it will endlessly increase.
So not only harder but it doesn’t work! Why do in one line what you can do in 8. I blame it on the heat…..
But don’t both code options fail to give the OP what he wants?
OP wanted close of bar 1 > close of bar 2 and close of bar 2 > Close of bar 3 etc … put another way 5 bars with a increasing value of Close?
OP wanted close of bar 1 > close of bar 2 and close of bar 2 > Close of bar 3 etc … put another way 5 bars with a increasing value of Close?
That is not what he wrote – he wrote this:
close>close[1] and close>close[2] and close>close[3] and close>close[4] and close>close[5]....
He always compared CLOSE, not CLOSE[previous bar].
Anyway, that would be
IF summation[5](close > close[1]) = 5 THEN....
That is not what he wrote – he wrote this:
Hahaha the heat is getting to all of us, I got it locked in my mind from initial reading (I should have reread) that he wanted an increasing value of close.
Cheers
…. and I first wrote that summation code that Robert just posted but then deleted my post when I realised my mistake and then went on to post a very complicated method that didn’t work! It is definitely the heat.
Thanks guys for the replies, yes Roberto’s code is correct, I have verified.
My mind was blocked too….actually it was so simple!
Maxx
CLOSE[previous bar]. Anyway, that would be
Code added to Snippet Link Library
Sorry for reviving this old topic, but after thinking it over and with a whole additional year experience… VONASI was right (apart from resetting count to 0 at line 2 as suggested by Nicolas).
My code always compares the current candle to the previous one, which is not exactly what maximus78 wanted. Indeed I believed using CLOSE without brackets would do, but summation reads it as being CLOSE[0], then it shifts both every iteration, so that the next one would be CLOSE[1] compared to CLOSE[2] and so on. CLOSE does NOT remain CLOSE[0] thus making a loop necessary.
VONASI was right
Finally almost thirteen months later I get the recognition that I deserve. I’ve had trouble sleeping at night ever since I posted something that was thought to be wrong. Thank goodness that nightmare is now over. 🙂
Strangely maximus78 was happy with your code Roberto so perhaps what he wanted and what he described were actually different things? It wouldn’t be the first time someone did that on the forums!