Q: How can I check if two indicators cross each other?
A:
In order to check for crossovers you need to compare two values. You will check the prior values against the current values. If 1 bar back Level1 was below Level2 And todays value of Level1 is above Level2 then we have a crossover. You now have the logic for Level1 crossing above Level2. You can just reverse the comparison sign to check for Level1 crossing below Level2. All of our indicators you can reference prior bars by encompassing a look back in brackets.
If needed, please see the following FAQ for examples:
http://www.omnitrader.com/omnitrader/proforum/thread-view.asp?threadid=1288&posts=1
So if we had two EMAs, say a 10 period and a 40 period EMA, and we wanted to know when they cross over, the logic would look like this.
If EMA(10)[1] < EMA(40)[1] AND EMA(10) > EMA(40) then
'Add code here to preform when the 10 period EMA crosses
'to the upside of the 40
ElseIF EMA(10)[1] > EMA(40)[1] AND EMA(10) < EMA(40) then
'Add code here to preform when the 10 period EMA crosses
'to the downside of the 40
End IF
[Edited by Matthew Greenslet on 10/12/2007 10:22 AM]
|