You are incorrectly using the iMA function. It returns a handle, not a value. You have to use CopyBuffer to get the values.
Please follow the links and reference the documentation.
Moving Average
Gets data of a specified buffer from a specified indicator into an array
Mathias Lisborg:
Hello guys.
I am in the process of developing a bot for MT5 but I simply cannot get it to work as I want.
It sells when it is above 55 and buys when it is below.
It should make a buy when it crosses EMA 55 with EMA 8, 13 and 21 and vice versa.
THANKS! :*
File is added below.
// declare global int EMA8, EMA13; double ema8_buff[], ema13_buff[]; //Buffer to store the EMA values void OnInit() { EMA8 = iMA(Symbol(), 0, 8, 0, MODE_EMA, PRICE_CLOSE); EMA13 = iMA(Symbol(), 0, 13, 0, MODE_EMA, PRICE_CLOSE); //rest of your code } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { CopyBuffer(EMA8, 0, 0, 2, ema8_buff); //Copy values from indicator initialized on init into buff CopyBuffer(EMA13, 0, 0, 2, ema13_buff); //if copying a lot of data, set Arrayasseries ArraySetAsSeries(ema8_buff, true); Print(" This is the value of the most recent ema 8 :", ema8_buff[0]); } //+------------------------------------------------------------------+NOT TESTED, NOT COMPILED
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
Hello guys.
I am in the process of developing a bot for MT5 but I simply cannot get it to work as I want.
It sells when it is above 55 and buys when it is below.
It should make a buy when it crosses EMA 55 with EMA 8, 13 and 21 and vice versa.
THANKS! :*
File is added below.