Specification
GOOD DAY
I have created a robot using mql5 however though i have 8 errors and i tried everythin i can do but still failing.
Please advise on what to do, i am will to add more if someone can solve my issue.
PLEASE FIND THE CODE BELOW.
#include <Trade\Trade.mqh>
input int length = 22;
input float mult = 3.0;
input bool showLabels = true;
input bool useClose = true;
input bool highlightState = true;
input double lotSize = 0.1; // Lot size for trading
input double stopLoss = 50; // Stop loss distance in points
input double trailingStop = 0.3; // Trailing stop percentage
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
CTrade trade;
int totalBars = Bars;
double atr[];
double longStop[];
double shortStop[];
int dir[];
bool buySignal[];
bool sellSignal[];
ArraySetAsSeries(atr, true);
ArraySetAsSeries(longStop, true);
ArraySetAsSeries(shortStop, true);
ArraySetAsSeries(dir, true);
ArraySetAsSeries(buySignal, true);
ArraySetAsSeries(sellSignal, true);
for (int i = length; i < totalBars; i++)
{
atr[i] = mult * iATR(_Symbol, _Period, length, i);
double highRange = useClose ? iHigh(NULL, _Period, i) : iHighest(NULL, _Period, MODE_HIGH, length, i);
double lowRange = useClose ? iLow(NULL, _Period, i) : iLowest(NULL, _Period, MODE_LOW, length, i);
longStop[i] = highRange - atr[i];
longStop[i] = MathMax(longStop[i], longStop[i - 1]);
shortStop[i] = lowRange + atr[i];
shortStop[i] = MathMin(shortStop[i], shortStop[i - 1]);
dir[i] = iClose(NULL, _Period, i) > shortStop[i - 1] ? 1 : iClose(NULL, _Period, i) < longStop[i - 1] ? -1 : dir[i - 1];
buySignal[i] = dir[i] == 1 && dir[i - 1] == -1;
sellSignal[i] = dir[i] == -1 && dir[i - 1] == 1;
if (buySignal[i])
{
double entryPrice = iOpen(NULL, _Period, i + 1);
double stopLossPrice = entryPrice - stopLoss * Point;
double takeProfitPrice = entryPrice + trailingStop * entryPrice * Point;
trade.Buy(_Symbol, lotSize, entryPrice, stopLossPrice, takeProfitPrice, 0, "Buy Signal", 0, clrNONE);
}
else if (sellSignal[i])
{
double entryPrice = iOpen(NULL, _Period, i + 1);
double stopLossPrice = entryPrice + stopLoss * Point;
double takeProfitPrice = entryPrice - trailingStop * entryPrice * Point;
trade.Sell(_Symbol, lotSize, entryPrice, stopLossPrice, takeProfitPrice, 0, "Sell Signal", 0, clrNONE);
}
}
}