MQL4 custom indictor doesnt't load

 

Hello

I am new here. I am trying to write my first custom indicator in mql4. This is simple indicator just for purpose of learning. W would like to receive line with only 2 values possible. Idicator equals 1 when conditions are met and 0 when condition is false. Condition is to get 1 when there is low made from 3 candles. I wrote indicator which you can see below but it doesn't load at all. MT4 is still loading and nothing happens. Dou you have any idea what I made wrong?

/+------------------------------------------------------------------+
//|                                                           W1.mq4 |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrBlue

double W1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,W1);
   SetIndexDrawBegin(0,1);
   SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,clrBlue);
   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[])
  {
   int i=1;
   while(i<rates_total)
     {
      if(Low[i]>Low[i+1] && Low[i+1]<Low[i+2])
         W1[i]=1.0;
      else
         W1[i]=0.0;
     }


   return(0);
  }
//+------------------------------------------------------------------+
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2023.02.18
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 

Your while loop never finishes.

You have to increment variable i.

Or alternatively, use for loop.

 
It worked. Thx.