Great job fixing most of the errors!
The last error is with the iATR function:
code
'iATR' - wrong parameters count GOLDEN BREAKOUT.mq5 123 20
built-in: int iATR(const string,ENUM_TIMEFRAMES,int) GOLDEN BREAKOUT.mq5 123 20
Explanation
In MQL5, iATR returns a handle to the ATR indicator, not the value itself.
To get the ATR value, you must:
- Create the handle with
iATR(_Symbol, PERIOD_D1, ATRPeriod);
- Use
CopyBuffer to get the value.
How to Fix
Replace this code:
mql5
double atr = iATR(_Symbol, PERIOD_D1, ATRPeriod, 1); // Wrong!
With this code:
mql5
double atr = 0.0;
int atr_handle = iATR(_Symbol, PERIOD_D1, ATRPeriod);
if(atr_handle != INVALID_HANDLE)
{
double atr_buffer[];
if(CopyBuffer(atr_handle, 0, 1, 1, atr_buffer) > 0)
atr = atr_buffer[0];
IndicatorRelease(atr_handle);
}
How to Use in Your EA
Replace the ATR section in your PlacePendingOrders() function:
mql5
if(UseATRStopLoss)
{
double atr = 0.0;
int atr_handle = iATR(_Symbol, PERIOD_D1, ATRPeriod);
if(atr_handle != INVALID_HANDLE)
{
double atr_buffer[];
if(CopyBuffer(atr_handle, 0, 1, 1, atr_buffer) > 0)
atr = atr_buffer[0];
IndicatorRelease(atr_handle);
}
slPoints = atr * ATRMultiplier / _Point;
}
Summary
iATR gives a handle, not a value.
- Use
CopyBuffer to get the ATR value.
- Always release the handle with
IndicatorRelease.
Your EA should now compile and work!
Let me know if you need more help or want the full updated code.