i have coded the indicator but it showing array out of range can anybody help me get out of it.
//+------------------------------------------------------------------+
//| bot.mq5 |
//| Copyright 2023, harish.trader99@gmail.com |
//| harish.trader99@gmail.com |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_plots 2
#property indicator_buffers 2
//CREDITS to HPotter for the orginal code. The guy trying to sell this as his own is a scammer lol.
input double KeyVaule = 3; // This changes the sensitivity
input int ATRPeriod = 10;
double nLoss, xATRTrailingStop, pos;
double xATR = iATR(Symbol(), PERIOD_CURRENT, ATRPeriod);
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
nLoss = KeyVaule * xATR;
if (prev_calculated == 0)
{
xATRTrailingStop = 0;
pos = 0;
}
for (int i = prev_calculated; i < rates_total; ++i)
{
xATRTrailingStop = (close[i] > xATRTrailingStop && close[i - 1] > xATRTrailingStop) ? MathMax(xATRTrailingStop, close[i] - nLoss) :
(close[i] < xATRTrailingStop && close[i - 1] < xATRTrailingStop) ? MathMin(xATRTrailingStop, close[i] + nLoss) :
(close[i] > xATRTrailingStop) ? close[i] - nLoss : close[i] + nLoss;
if (close[i - 1] < xATRTrailingStop && close[i] > xATRTrailingStop)
pos = 1;
else if (close[i - 1] > xATRTrailingStop && close[i] < xATRTrailingStop)
pos = -1;
else
pos = pos;
color xcolor = pos == -1 ? clrRed : pos == 1 ? clrGreen : clrBlue;
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE, xATRTrailingStop);
PlotIndexSetInteger(0, PLOT_ARROW, i, xcolor);
bool buy = (close[i] > xATRTrailingStop) && (close[i - 1] <= xATRTrailingStop);
bool sell = (close[i] < xATRTrailingStop) && (close[i - 1] >= xATRTrailingStop);
bool barcolor = close[i] > xATRTrailingStop;
if (buy)
PlotIndexSetInteger(1, PLOT_ARROW, i, 233);
if (sell)
PlotIndexSetInteger(2, PLOT_ARROW, i, 234);
if (barcolor)
PlotIndexSetInteger(0, PLOT_LINE_COLOR, i, clrGreen);
else
PlotIndexSetInteger(0, PLOT_LINE_COLOR, i, clrRed);
if (buy)
Alert("UT BOT Buy");
if (sell)
Alert("UT BOT Sell");
}
return(rates_total);
}