I need help, create an indicator, but the machine is stuck

 

#property copyright "Created by William Miranda"
#property link      "https://www.mypage.com"
#property version   "1.00"
#property description ""
#property tester_indicator "PM"

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x3300FF
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Indicator01 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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 limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
     }
   else
      limit++;
   
   int Nada = 2147483647;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation  
      
      int barshift_M30 = iBarShift(Symbol(), PERIOD_M30, Time[i]);
      if(barshift_M30 < 0) continue;
      int barshift_M15 = iBarShift(Symbol(), PERIOD_M15, Time[i]);
      if(barshift_M15 < 0) continue;
      int barshift_M5 = iBarShift(Symbol(), PERIOD_M5, Time[i]);
      if(barshift_M5 < 0) continue; 
      int barshift_M1 = iBarShift(Symbol(), PERIOD_M1, Time[i]);
      if(barshift_M1 < 0) continue;
      
      int M30UP = iCustom(NULL, PERIOD_M30, "Diamante", 30, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 3, barshift_M1);
      
              
      if (iCustom(NULL, PERIOD_M30, "Diamante", 30, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 3, barshift_M30) != Nada)
         {
            if (iCustom(NULL, PERIOD_M15, "Diamante", 15, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 3, barshift_M15) != Nada)
               {
                  if (iCustom(NULL, PERIOD_M5, "Diamante", 5, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 3, barshift_M5) != Nada)
                     {
                         if (iCustom(NULL, PERIOD_M1, "Diamante", 1, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 3, barshift_M1) != Nada)
                           {
                              Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low 
                           }
                          else
                           {
                              Buffer1[i] = EMPTY_VALUE;
                           }
                     }
               }
         }              
                 
      int M30DW = iCustom(NULL, PERIOD_M30, "Diamante", 30, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 4, barshift_M1);
      
      if (iCustom(NULL, PERIOD_M30, "Diamante", 30, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 4, barshift_M30) != Nada)
         {
            if (iCustom(NULL, PERIOD_M15, "Diamante", 15, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 4, barshift_M15) != Nada)
               {
                   if (iCustom(NULL, PERIOD_M5, "Diamante", 5, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 4, barshift_M5) != Nada)
                     {
                        if (iCustom(NULL, PERIOD_M1, "Diamante", 1, 21, PRICE_OPEN, 2.1, true, false, false, false, "Set_arrows", 119, 119, 6, 1.5, 4, barshift_M1) != Nada)
                           {
                              Buffer2[i] = High[i]; //Set indicator value at Candlestick High  
                           }   
                        else
                           {
                              Buffer2[i] = EMPTY_VALUE;
                           }
                     }
               } 
         }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

This is an English language forum.

I have edited your title but in future please remember to only post in English.


Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

Reason: