How can I find the last moving average crossover price x candle before in mql4?

How can I find the last moving average crossover price x candle before in mql4?

Manage alerts

Loading saved threads...

mqllearner · External communityPost link
External question — Stack Overflow Stack Exchange Author: mqllearner Original post: https://stackoverflow.com/questions/63891778 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to code a function which will return the price of the last moving average crossover. I will be really happy if anyone here helps me to achive this in mql4 code..
Quote
Report
Raphael Tunji · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Raphael Tunji Original post: https://stackoverflow.com/a/63892658 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. int manyCandles=1000, crossOverCandle; double theOpenPrice; for(int lastCandle=1; lastCandle<manyCandles; lastCandle++){ crossOverCandle=0; double firstMA = iMA(_Symbol,_Period,maPeriod,0,MODE_SMA,PRICE_CLOSE,lastCandle); double secondMA = iMA(_Symbol,_Period,maPeriod,0,MODE_SMA,PRICE_CLOSE,lastCandle); double firstMAlast = iMA(_Symbol,_Period,maPeriod,0,MODE_SMA,PRICE_CLOSE,lastCandle+1); double secondMAlast = iMA(_Symbol,_Period,maPeriod,0,MODE_SMA,PRICE_CLOSE,lastCandle+1); if(secondMAlast>firstMAlast && secondMA<firstMA){ theOpenPrice = Open[lastCandle]; crossOverCandle = lastCandle; Break; } } Comment("The last cross over happened on ",lastCandle," candle, the price was ",theOpenPrice); You can try the above code.
Quote
Report

Post Reply

Checking account access…
How can I find the last moving average crossover price x candle before in mql4? | Forex.com.bd