MT4 Get sma price of candle open

 

Can anyone tell me how to get the sma price at candle open only, and I don't want the value to change. For example a new candle has opened and I have an sma20, I want to get the value of the sma20 at open only and not after it changes, not the normal sma20 price but only at candle open.

Regards.

 
sarahfoxwell: Can anyone tell me how to get the sma price at candle open only, and I don't want the value to change. For example a new candle has opened and I have an sma20, I want to get the value of the sma20 at open only and not after it changes, not the normal sma20 price but only at candle open. Regards.

On a chart or in MQL code?

If on the chart then simply apply a Simple Moving Average to the chart and choose the Open price instead of Close price.

If in coding then use the iMA() function with the PRICE_OPEN applied price and a MODE_SMA method.

iMA - Technical Indicators - MQL4 Reference
iMA - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iMA - Technical Indicators - MQL4 Reference
 
Fernando Carreiro #:

On a chart or in MQL code?

If on the chart then simply apply a Simple Moving Average to the chart and choose the Open price instead of Close price.

If in coding then use the iMA() function with the PRICE_OPEN applied price and a MODE_SMA method.

Hello, for the mql4 code, I do not think it is working correctly because at the 4 hour open of the new day candle today for EURUSD the sma 5 open price in mql4/mt4 says 0.9726, where other charts say 0.97416 area..


double sma5 = iMA(_Symbol, _Period, 5, 0, MODE_SMA, PRICE_OPEN, 0);

 
sarahfoxwell #: Hello, for the mql4 code, I do not think it is working correctly because at the 4 hour open of the new day candle today for EURUSD the sma 5 open price in mql4/mt4 says 0.9726, where other charts say 0.97416 area..
double sma5 = iMA(_Symbol, _Period, 5, 0, MODE_SMA, PRICE_OPEN, 0);

What other charts? Don't compare with other platforms. Forex is not a centralised exchange. Quotes are different between platforms, between brokers and even between different type of accounts.

 
Fernando Carreiro #:

What other charts? Don't compare with other platforms. Forex is not a centralised exchange. Quotes are different between platforms, between brokers and even between different type of accounts.

Multiple soures of charts all of them seem to be the same, this is different, I believe this is getting the previous closing value of the SMA.