Download MetaTrader 5

can anyone convert this gridline indicator to array?

To add comments, please log in or register
pek4christ
79
pek4christ  
Hey Guys,
           From the teachings in this forum and personal excersice i have discovered how to build a grid indicator, But there is a little problem Im having : building the indicator as a single variable it worked correctely but when i tried to convert each grid line into individual element (array) so i can apply it to an EA, its saying array out of range.
           Here are the samples :
GridLine Indicator as Variable


    #property strict
#property indicator_chart_window
#define  RS_LINES
//--- input parameters
input double   RSG_HGmax=2.0;
input double   RSG_HGstep=50;
input double   RSG_HGmin=1.0;
input color    RSGI_HGcolor= 0;
input int      RSGI_HGstyle=2;
input int      RSGI_HGbackground=0;

double TickSize;
double pips;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
     TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;

   return(0);
  }
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int deinit()
  {
double RS_MAX  = MathRound(RSG_HGmax / Point);
double RS_STEP = MathRound(RSG_HGstep/ Point);
double RS_MIN  = MathRound(RSG_HGmin / Point);

double RS_PRICE ;
double I;
double STEP_RANGE = (RS_STEP *pips);
 for( I=RS_MIN; I<RS_MAX; I+=STEP_RANGE)
 {
 RS_PRICE  = I * Point;
 
  string     RS_HGLineName  = RS_LINES  + DoubleToStr    ( RS_PRICE , Digits        ) ;
 
 
  ObjectDelete( RS_HGLineName  = RS_LINES  + DoubleToStr    ( RS_PRICE , Digits        ));
  
     } // for                                                                                            
 
 
//---
   return(0);
  }
int start()
  {
//---
int    counted_bars=IndicatorCounted();
double RS_MAX  = MathRound(RSG_HGmax / Point) ;
double RS_STEP = MathRound(RSG_HGstep/ Point);
double  RS_MIN  = MathRound(RSG_HGmin / Point);
double RS_PRICE ;
double J;
double STEP_RANGE = (RS_STEP *pips);
 for(J=RS_MIN; J<RS_MAX; J+=STEP_RANGE)
 {
 RS_PRICE  = J * Point;
   string       RS_HGLineName  = RS_LINES  + DoubleToStr    ( RS_PRICE , Digits        ) ; //<  46>
       ObjectCreate  ( RS_HGLineName  , OBJ_HLINE     , 0 , 0          , RS_PRICE                ) ; //<  47>
       ObjectSet     ( RS_HGLineName  , OBJPROP_COLOR                  , RSGI_HGcolor                     ) ; //<  48>
       ObjectSet     ( RS_HGLineName  , OBJPROP_STYLE                  , RSGI_HGstyle                     ) ; //<  49>
       ObjectSet     ( RS_HGLineName  , OBJPROP_BACK                   ,RSGI_HGbackground               ) ; //<  50>
     
     }
   return(0);
 
  }
//+------------------------------------------------------------------+
 #property strict
#property indicator_chart_window
#define  RS_LINES
//--- input parameters
input double   RSG_HGmax=

GridLine indicator as Array

double TickSize;
double pips;
double  OPEN;
double gridLine[];
int i;
double k;
//------------------------------------------------------------------------------------------------
int const countMultiple = 100000;
int const Size  = (countMultiple * Count);
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
     TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;

   return(0);
  }
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int deinit()
  {

       double  RS_STEP = MathRound(GridStep /Point);
      double  RS_MIN  = MathRound( GridMin/Point);
      double STEP_RANGE = RS_STEP * pips;
      for( i = 0; i < Size; i++)
    {
  
     gridLine[i] =  (RS_MIN * Point) + (i * (STEP_RANGE * Point));
    
      string     RS_HGLineName  =Gridlines + DoubleToStr    ( gridLine[i] , Digits        ) ;
 
 
     ObjectDelete( RS_HGLineName  = Gridlines + DoubleToStr    ( gridLine[i] , Digits        ));
 
   }

 return(0);

 }
int start()
  {
  
      int    counted_bars=IndicatorCounted();
      double  RS_STEP = MathRound(GridStep /Point);
      double  RS_MIN  = MathRound( GridMin/Point);
      double STEP_RANGE = RS_STEP * pips;
      for( i = 0; i < Size; i++)
     {
     gridLine[i] = (RS_MIN * Point) + (i * (STEP_RANGE * Point));
    
       string       RS_HGLineName  = Gridlines + DoubleToStr    (  gridLine[i] , Digits        ) ; //<  46>
       ObjectCreate  ( RS_HGLineName  , OBJ_HLINE     , 0 , 0          , gridLine[i]               ) ; //<  47>
       ObjectSet     ( RS_HGLineName  , OBJPROP_COLOR                  , GridColor                     ) ; //<  48>
       ObjectSet     ( RS_HGLineName  , OBJPROP_STYLE                  , GridStyle                    ) ; //<  49>
       ObjectSet     ( RS_HGLineName  , OBJPROP_BACK                   , GridBackground               ) ; //<  50>
     
 
 


  }
return(0);
}
Alain Verleyen
Moderator
33481
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Blahtech Limited
5999
James Cater  
pek4christ:
Hey Guys,
           From the teachings in this forum and personal excersice i have discovered how to build a grid indicator, But there is a little problem Im having : building the indicator as a single variable it worked correctely but when i tried to convert each grid line into individual element (array) so i can apply it to an EA, its saying array out of range.
           Here are the samples :
GridLine Indicator as Variable



MQL4 arrays need to be resized before they can be populated.

https://docs.mql4.com/array/arrayresize

ArrayResize - MQL4 Documentation
  • docs.mql4.com
ArrayResize - MQL4 Documentation
Oksana Berenko
2788
Oksana Berenko  

In init() -> ArrayResize(gridLine, SIZE);

In start() and deinit() -> for(int  i = 0; i < SIZE; i++) {}

pek4christ
79
pek4christ  
Alain Verleyen:

thanks

pek4christ
79
pek4christ  
Oksana Berenko:

In init() -> ArrayResize(gridLine, SIZE);

In start() and deinit() -> for(int  i = 0; i < SIZE; i++) {}

Okasana Berenko, thanks so much,i realy appreciate your comment,now i have desing the  grid indicator in  array formatt...
pek4christ
79
pek4christ  

Thanks to all, i appreciate your comment

pek4christ
79
pek4christ  
pek4christ:
Okasana Berenko, thanks so much,i realy appreciate your comment,now i have desing the  grid indicator in  array formatt...
this is what i did on the init
int OnInit()
  {
//---
     TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;
//---
     ArrayResize(gridLine, Size);// as you said, i should apply the ArrayResize function on the init...
   return(INIT_SUCCEEDED);

  }

and on the denint and the start i also did as you said :

for( i = 0; i < Size; i++) //on init and denit

//..................... But it still saying array is out of range pls take a look at it

pek4christ
79
pek4christ  
this is what i did on the init
int OnInit()
  {
//---
     TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;
//---
     ArrayResize(gridLine, Size);// as you said, i should apply the ArrayResize function on the init...
   return(INIT_SUCCEEDED);

  }

and on the denint and the start i also did as you said :

for( i = 0; i < Size; i++) //on init and denit

//..................... But it still saying array is out of range pls take a look at it
pek4christ
79
pek4christ  
James Cater:


MQL4 arrays need to be resized before they can be populated.

https://docs.mql4.com/array/arrayresize

this is what i did on the init
int OnInit()
  {
//---
     TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;
//---
     ArrayResize(gridLine, Size);// as you said, i should apply the ArrayResize function on the init...
   return(INIT_SUCCEEDED);

  }

and on the denint and the start i also did as you said :

for( i = 0; i < Size; i++) //on init and denit

//..................... But it still saying array is out of range pls take a look at it
pek4christ
79
pek4christ  
But the Grid indicator is drawing gridlines but when you look at it on the expert conner its saying array is out of range... thats why my ea is not opening trades.thanks for making it half way done..
12
To add comments, please log in or register