anjan babu: I can get and identify current crossover by using 1 and 2 buffer of the two MA indicators.
You are identifying that using indexes one and two. Use a loop and look further back to find the previous cross.
double aPrev = …(i+1), aCurr = …(i), bPrev = …(i+1), bCurr = …(i); bool wasUp = aPrev > bPrev, isUp = aCurr > bCurr, isCross = isUp != wasUp;
Thanks William, I did something similar. I did manage to get crossover checks of previous bars with a loop as you said. But my code seem to ignore some of the crossovers and jump to the next crossover. I don't know if it is wrong with the code or the data.
// Function to check CrossOver string CrossOverCheck() { for(int i = 1; i<150; i++) { int prev_i = i+1; GetMA(i,prev_i); if (fasti > slowi && fastprev_i < slowprev_i) { Comment(" Bullish crossover happened in: ", i, "\n"); signal = "bull"; return signal; } else if (fasti < slowi && fastprev_i > slowprev_i) { Comment("Bearish crossover happened in: ", i, "\n"); signal = "bear"; return signal; } } return signal; }
I got it working William. I made silly mistake of having EMA selected in the expert and SMA on my chart which obviously didn't match. Now I have a good working function. I will let my Expert to plot MA so it doesn't cause confusion again.
Thanks
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I can get and identify current crossover by using 1 and 2 buffer of the two MA indicators. But i want to get the previous crossover and the corresponding X candle. Should i run the crossover check on every newBar and re assign a value on every tick?
please pardon my english