Hi Nicolas,
I would like to code a condition which check previous bars whether the short term MA is above or below a long term MA. For example if I want the condition to check back 50 bars from the current bar if the 5MA is above the 10MA. Can you please help with the code. Thank you.
Create a variable that check if the shorter average is above the longer one:
test = average[5]>average[10]
Then use an offset of that condition 50 bars back in your code:
if test[50] then
// ... do something
endif
Just to clarify things a little. The current bar/candle is bar zero so if you want to check 50 bars back and the count includes the current bar then it would be test[49]. If you want to check 50 bars back and not include the current bar in the count back then it is test[50] you need.