MQL5 Custom indicator not working - need help tweaking code

 

Hi everyone...


I have coded this indicator, it's been compiled and has no errors, but when I put it on the chart, nothing shows up.


Can anyone help, please?


Here's the full code:

#include <Trade\Trade.mqh>


// Indicator parameters

input int lookback = 20;

input int atr_period = 14;

input int font_size = 12;

input color font_color = clrBlack;

input color fvg_color = clrGray;

input color fvg_fill_color = clrGray;

input int fvg_line_style = STYLE_SOLID;

input int fvg_line_width = 1;

input int fvg_fill = 0; // 0 for outline, 1 for filled

input color entry_color = clrMagenta;

input int entry_line_style = STYLE_SOLID;

input int entry_line_width = 2;

input color stop_loss_color = clrRed;

input int stop_loss_line_style = STYLE_SOLID;

input int stop_loss_line_width = 2;


// Indicator buffers

double A_level[];

double B_level[];

double C_level[];

double D_level[];

double FVG_low[];

double FVG_high[];

double entry_level[];

double stop_loss_level[];

double atr_buffer[];


// Buffers for previous values

double prev_A_level[];

double prev_B_level[];

double prev_C_level[];

double prev_D_level[];

double prev_FVG_low[];

double prev_FVG_high[];

double prev_entry_level[];

double prev_stop_loss_level[];


// Define indicator properties

#property indicator_chart_window

#property indicator_buffers 18

#property indicator_plots 1

#property indicator_color1 clrRed


//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

{

   SetIndexBuffer(0, A_level);

   SetIndexBuffer(1, B_level);

   SetIndexBuffer(2, C_level);

   SetIndexBuffer(3, D_level);

   SetIndexBuffer(4, FVG_low);

   SetIndexBuffer(5, FVG_high);

   SetIndexBuffer(6, entry_level);

   SetIndexBuffer(7, stop_loss_level);

   SetIndexBuffer(8, atr_buffer);


   SetIndexBuffer(9, prev_A_level);

   SetIndexBuffer(10, prev_B_level);

   SetIndexBuffer(11, prev_C_level);

   SetIndexBuffer(12, prev_D_level);

   SetIndexBuffer(13, prev_FVG_low);

   SetIndexBuffer(14, prev_FVG_high);

   SetIndexBuffer(15, prev_entry_level);

   SetIndexBuffer(16, prev_stop_loss_level);


   // Initialize ATR buffer

   int handle = iATR(_Symbol, PERIOD_CURRENT, atr_period);

   CopyBuffer(handle, 0, 0, Bars(_Symbol, PERIOD_CURRENT), atr_buffer);


   return INIT_SUCCEEDED;

}


//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

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[])

{

   for (int i = lookback; i < rates_total; i++) {

       // Short position logic

       if (high[i] > high[i - lookback] && high[i] > high[i + lookback]) {

           A_level[i] = high[i];

       } else if (low[i] < low[i - lookback] && low[i] < low[i + lookback]) {

           B_level[i] = low[i];

       } else if (A_level[i - lookback] != 0 && low[i] < B_level[i - lookback]) {

           C_level[i] = high[i];

       }


       if (C_level[i] != 0 && D_level[i + lookback] != 0) {

           // ... (existing code for short position FVG, entry, and stop-loss)

       }


       // Long position logic (invert conditions and calculations)

       if (low[i] < low[i - lookback] && low[i] < low[i + lookback]) {

           A_level[i] = low[i];

       } else if (high[i] > high[i - lookback] && high[i] > high[i + lookback]) {

           B_level[i] = high[i];

       } else if (A_level[i - lookback] != 0 && high[i] > B_level[i - lookback]) {

           C_level[i] = low[i];

       }


       if (C_level[i] != 0 && D_level[i + lookback] != 0) {

           // ... (logic for long position FVG, entry, and stop-loss)

       }


       // Visualizations for both short and long positions

       // ...

   }


   // Copy current data to previous buffers

   for (int i = 0; i < rates_total - 1; i++) {

       prev_A_level[i] = A_level[i + 1];

       prev_B_level[i] = B_level[i + 1];

       prev_C_level[i] = C_level[i + 1];

       prev_D_level[i] = D_level[i + 1];

       prev_FVG_low[i] = FVG_low[i + 1];

       prev_FVG_high[i] = FVG_high[i + 1];

       prev_entry_level[i] = entry_level[i + 1];

       prev_stop_loss_level[i] = stop_loss_level[i + 1];

   }


   // Visualize previous setups

   for (int i = 600; i < rates_total; i++) {

       if (prev_FVG_low[i - 600] != 0 && prev_FVG_high[i - 600] != 0) {

           // Example of creating a rectangle object for the previous FVG levels

           ObjectCreate(0, "prev_FVG_box_" + IntegerToString(i - 600), OBJ_RECTANGLE, 0, time[i - 600], prev_FVG_low[i - 600], time[i - 600], prev_FVG_high[i - 600]);

           ObjectSetInteger(0, "prev_FVG_box_" + IntegerToString(i - 600), OBJPROP_COLOR, fvg_color);

           ObjectSetInteger(0, "prev_FVG_box_" + IntegerToString(i - 600), OBJPROP_STYLE, fvg_line_style);

           ObjectSetInteger(0, "prev_FVG_box_" + IntegerToString(i - 600), OBJPROP_WIDTH, fvg_line_width);


           // ... (other visualizations for previous levels)

       }

   }


   return rates_total;

}

//+------------------------------------------------------------------+


Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Every mql5-program allows to specify additional specific parameters named #property that help client terminal in proper servicing for programs...
 
you need to define the plot type 
#property indicator_type1 ____

You have specified only 1 plot, is this correct?
 
Conor Mcnamara #:
you need to define the plot type 
#property indicator_type1 ____

You have specified only 1 plot, is this correct?

Hi Conor, 


Thank you for replying...


i'll drop you a private message