ATR multiplier not working

 

Hi

I am trying to have  indicator draw a box on chart with X pipsize . Where  X is dependent on ATR value for that timeframe for that symbol. I used the following lines .But they do not produce any result.

Am I using the ATR multiplier (*100)correctly ? Should there be another number as multiplier for different digit symbol. I would like the box pipsize to be the ATR value of the symbol at that timeframe.

Eg if ATR value at TF 60  is 12 pips .I would like the box to be 12 pip for that TF and if ATR @ 240 is 30 then 30 pip boxsize for 240TF.

   double MP =  iATR(NULL,0,10,0) ;
  
   BoxSize= MP * 100;
 
double MP =  iATR(NULL,0,10,0) ;

it gives some value, distance.

You want to use a box of the same size.

Why are you multiplying it? You don't need to do this.

 
Arkadii Zagorulko:

it gives some value, distance.

You want to use a box of the same size.

Why are you multiplying it? You don't need to do this.

thanks Arkadii ,

I don't see any box even without multiplying. The reson I multiplied was beacuse normally the ATR values are in decimals like 0.0023 etc so I thought in order to have a box sized 23 pips it needed to be multiplied.

Here is the complete code. What am I doing wrong?

//+------------------------------------------------------------------+
//|                                                    Renko nmc.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
//#property strict 
#property indicator_buffers 2
#property indicator_color1 clrYellow
#property indicator_color2 clrRed
#property indicator_width1 0
#property indicator_width2 0


double BoxSize ;

extern double MULT = 100;

double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

  
   double MP =  iATR(NULL,0,10,0) ; // should produce the value for any symbol , tf that the indicator is placed on
  
   BoxSize= MP * MULT;
  




 

//--- indicator buffers mapping
   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, Buffer2);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, Buffer3);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, Buffer4);
   SetIndexLabel(0, "Up");
   SetIndexLabel(1, "Dn");
   IndicatorDigits(Digits);
  
//---
   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[])
  {
  double Hi;
   double Lo;
   double result;
   double barsize;
   double digits;
   int  i;
   for(i = MathMax(rates_total-1-prev_calculated,2); i>=0; i--)
  
   Buffer1[Bars] = Close[Bars];
   Buffer2[Bars] = Close[Bars];
   Buffer3[Bars] = Close[Bars];
   Buffer4[Bars] = Close[Bars];
   if (Digits == 5 || Digits == 3) digits = NormalizeDouble(10.0 * BoxSize, Digits);
   else digits = NormalizeDouble(BoxSize, Digits);
   double box = NormalizeDouble(Point * digits, Digits);
   int bars = Bars - i;
   for (int k = bars; k >= 0; k--) {
      Hi = NormalizeDouble(High[k] - (Buffer3[k + 1]) - box, Digits);
      Lo = NormalizeDouble(Low[k] - (Buffer4[k + 1]) + box, Digits);
      if (Hi >= 0.0) {
         barsize = NormalizeDouble((High[k] - (Buffer3[k + 1])) / box, Digits);
         result = NormalizeDouble(MathFloor(barsize), Digits);
         Buffer3[k] = Buffer3[k + 1] + box * result;
         Buffer4[k] = Buffer3[k] - box * result;
         Buffer1[k] = Buffer3[k];
         Buffer2[k] = Buffer4[k];
         Buffer4[k] = Buffer3[k] - box;
      } else {
         if (Lo <= 0.0) {
            barsize = NormalizeDouble((Buffer4[k + 1] - Low[k]) / box, Digits);
            result = NormalizeDouble(MathFloor(barsize), Digits);
            Buffer4[k] = Buffer4[k + 1] - box * result;
            Buffer3[k] = Buffer4[k] + box * result;
            Buffer2[k] = Buffer3[k];
            Buffer1[k] = Buffer4[k];
            Buffer3[k] = Buffer4[k] + box;
         } else {
            Buffer3[k] = Buffer3[k + 1];
            Buffer4[k] = Buffer4[k + 1];
            if (Buffer1[k + 1] > Buffer2[k + 1]) {
               Buffer1[k] = Buffer1[k + 1];
               Buffer2[k] = Buffer1[k] - box;
            }
            if (Buffer2[k + 1] > Buffer1[k + 1]) {
               Buffer1[k] = Buffer1[k + 1];
               Buffer2[k] = Buffer1[k] + box;
            }
         }
      }
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
I am trying to have  indicator draw a box on chart with X pipsize


   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(1, DRAW_HISTOGRAM);

You can not draw a box  using indicator buffers. To do this, you need to use the object. Or maybe I just understand you wrong, and do not know what  mean  for you  the "box"

 
Arkadii Zagorulko:


You can not draw a box  using indicator buffers. To do this, you need to use the object. Or maybe I just understand you wrong, and do not know what  mean  for you  the "box"

You are right I should have said make the boxsize dependable on user input. Which was the case with the original code. I thought instead of making the box size @ user input why not make it depend on the ATR of the symbol and the timeframe , the indicator is placed on. This is what it looks like in original form.

//+------------------------------------------------------------------+
//|                                                    Renko nmc.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
//#property strict 
#property indicator_buffers 2
#property indicator_color1 clrYellow
#property indicator_color2 clrRed
#property indicator_width1 0
#property indicator_width2 0

extern double BoxSize = 7.0;
extern double BoxSizeH4 = 20.0;
extern double BoxSizeD1= 50.0;
extern double BoxSizeW1= 100.0;
extern double BoxSizeMN1= 200.0;

double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
  
  
    if ( Period()==240)
  {
  BoxSize=BoxSizeH4 ;
  }
  
  if (  Period()==1440)
  {
  BoxSize=BoxSizeD1 ;
  }
  
   if ( Period()==10080)
  {
  BoxSize=BoxSizeW1 ;
  }
  
  if (  Period()==43200)
  {
  BoxSize=BoxSizeMN1 ;
  }
//--- indicator buffers mapping
   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, Buffer2);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, Buffer3);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, Buffer4);
   SetIndexLabel(0, "Up");
   SetIndexLabel(1, "Dn");
   IndicatorDigits(Digits);
  
//---
   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[])
  {
  double Hi;
   double Lo;
   double result;
   double barsize;
   double digits;
   int  i;
   for(i = MathMax(rates_total-1-prev_calculated,2); i>=0; i--)
  
   Buffer1[Bars] = Close[Bars];
   Buffer2[Bars] = Close[Bars];
   Buffer3[Bars] = Close[Bars];
   Buffer4[Bars] = Close[Bars];
   if (Digits == 5 || Digits == 3) digits = NormalizeDouble(10.0 * BoxSize, Digits);
   else digits = NormalizeDouble(BoxSize, Digits);
   double box = NormalizeDouble(Point * digits, Digits);
   int bars = Bars - i;
   for (int k = bars; k >= 0; k--) {
      Hi = NormalizeDouble(High[k] - (Buffer3[k + 1]) - box, Digits);
      Lo = NormalizeDouble(Low[k] - (Buffer4[k + 1]) + box, Digits);
      if (Hi >= 0.0) {
         barsize = NormalizeDouble((High[k] - (Buffer3[k + 1])) / box, Digits);
         result = NormalizeDouble(MathFloor(barsize), Digits);
         Buffer3[k] = Buffer3[k + 1] + box * result;
         Buffer4[k] = Buffer3[k] - box * result;
         Buffer1[k] = Buffer3[k];
         Buffer2[k] = Buffer4[k];
         Buffer4[k] = Buffer3[k] - box;
      } else {
         if (Lo <= 0.0) {
            barsize = NormalizeDouble((Buffer4[k + 1] - Low[k]) / box, Digits);
            result = NormalizeDouble(MathFloor(barsize), Digits);
            Buffer4[k] = Buffer4[k + 1] - box * result;
            Buffer3[k] = Buffer4[k] + box * result;
            Buffer2[k] = Buffer3[k];
            Buffer1[k] = Buffer4[k];
            Buffer3[k] = Buffer4[k] + box;
         } else {
            Buffer3[k] = Buffer3[k + 1];
            Buffer4[k] = Buffer4[k + 1];
            if (Buffer1[k + 1] > Buffer2[k + 1]) {
               Buffer1[k] = Buffer1[k + 1];
               Buffer2[k] = Buffer1[k] - box;
            }
            if (Buffer2[k + 1] > Buffer1[k + 1]) {
               Buffer1[k] = Buffer1[k + 1];
               Buffer2[k] = Buffer1[k] + box;
            }
         }
      }
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+

any idea  how to make the boxsize automatically adjust to ATR value as I initially asked ?

Reason: