Re: Does this indicator repaint?

73
zzleepy wrote: Thu May 25, 2017 11:54 pm I'm wondering about the nature of how this indicator paints. Does it repaint, and if not, when it does paint how many bars back does it paint?
Since the nature of it is in the high/low channel (that is drawn on the chart too), if the new highest high or lowest low for the chose period is formed, then the extreme can change. It will not change the direction of the last leg, but will change the position of the last extreme. It can do that for the high/low period bars back

Re: Does this indicator repaint?

74
Hi all, does this indi repaint? Seems to be simple enough not to repaint and it uses i+1. Would appreciate your help in confirming.

Many thanks in advance!

Code: Select all

//+------------------------------------------------------------------+
//|                                                TradeBreakOut.mq4 |
//|                                  Copyright © 2013, Andriy Moraru |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.earnforex.com"
/*
Red line crossing 0 from above is a support breakout signal.
Green line crossing 0 from below is a resistance breakout signal.
*/
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_color1 Green
#property indicator_color2 Red
//---
extern int L=50; // Period
extern ENUM_APPLIED_PRICE PriceTypeHigh=PRICE_HIGH;
extern ENUM_APPLIED_PRICE PriceTypeLow =PRICE_LOW; 
extern ENUM_MA_METHOD     AverageMethod=MODE_SMA;
extern int                AveragePeriod=5;
//--- Buffers
double TBR_R[],TBR_S[],priceh[],pricel[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,TBR_R);
   SetIndexBuffer(1,TBR_S);
   SetIndexBuffer(2,priceh);
   SetIndexBuffer(3,pricel);
//---
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
//---
   SetIndexDrawBegin(0,L);
   SetIndexDrawBegin(1,L);
//---
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
//---
   IndicatorDigits(Digits);
//---
   IndicatorShortName("TBR("+L+")");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| TradeBreakOut                                                    |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars <= L) return(0);
//---
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
//--- Skip calculated bars
   int end=Bars-counted_bars;
//--- Cannot calculate bars that are too close to the end. There won't be enough bars to calculate ArrayMin/Max
   if(Bars-end<=L) end=Bars -(L+1);
//---

   for(int i=0; i<end; i++)
     {
      double th = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeHigh,i);
      double tl = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeLow,i);
      priceh[i] = MathMax(th,tl);
      pricel[i] = MathMin(th,tl);
    }      
   for(i=0; i<end; i++)
     {
      
         double max = priceh[ArrayMaximum(priceh, L, i + 1)];
         double min = pricel[ArrayMinimum(pricel, L, i + 1)];
         TBR_R[i] = (max!=0) ? (priceh[i] - priceh[ArrayMaximum(priceh, L, i + 1)]) / max : 0;
         TBR_S[i] = (min!=0) ? (pricel[i] - pricel[ArrayMinimum(pricel, L, i + 1)]) / min : 0;
     }
//---
   return(0);
  }
//+------------------------------------------------------------------+

Re: Does this indicator repaint?

75
yuhu wrote: Thu Jun 15, 2017 5:49 am Hi all, does this indi repaint? Seems to be simple enough not to repaint and it uses i+1. Would appreciate your help in confirming.

Many thanks in advance!

Code: Select all

//+------------------------------------------------------------------+
//|                                                TradeBreakOut.mq4 |
//|                                  Copyright © 2013, Andriy Moraru |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.earnforex.com"
/*
Red line crossing 0 from above is a support breakout signal.
Green line crossing 0 from below is a resistance breakout signal.
*/
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_color1 Green
#property indicator_color2 Red
//---
extern int L=50; // Period
extern ENUM_APPLIED_PRICE PriceTypeHigh=PRICE_HIGH;
extern ENUM_APPLIED_PRICE PriceTypeLow =PRICE_LOW; 
extern ENUM_MA_METHOD     AverageMethod=MODE_SMA;
extern int                AveragePeriod=5;
//--- Buffers
double TBR_R[],TBR_S[],priceh[],pricel[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,TBR_R);
   SetIndexBuffer(1,TBR_S);
   SetIndexBuffer(2,priceh);
   SetIndexBuffer(3,pricel);
//---
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
//---
   SetIndexDrawBegin(0,L);
   SetIndexDrawBegin(1,L);
//---
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
//---
   IndicatorDigits(Digits);
//---
   IndicatorShortName("TBR("+L+")");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| TradeBreakOut                                                    |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars <= L) return(0);
//---
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
//--- Skip calculated bars
   int end=Bars-counted_bars;
//--- Cannot calculate bars that are too close to the end. There won't be enough bars to calculate ArrayMin/Max
   if(Bars-end<=L) end=Bars -(L+1);
//---

   for(int i=0; i<end; i++)
     {
      double th = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeHigh,i);
      double tl = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeLow,i);
      priceh[i] = MathMax(th,tl);
      pricel[i] = MathMin(th,tl);
    }      
   for(i=0; i<end; i++)
     {
      
         double max = priceh[ArrayMaximum(priceh, L, i + 1)];
         double min = pricel[ArrayMinimum(pricel, L, i + 1)];
         TBR_R[i] = (max!=0) ? (priceh[i] - priceh[ArrayMaximum(priceh, L, i + 1)]) / max : 0;
         TBR_S[i] = (min!=0) ? (pricel[i] - pricel[ArrayMinimum(pricel, L, i + 1)]) / min : 0;
     }
//---
   return(0);
  }
//+------------------------------------------------------------------+
It does not repaint
In any case you can use this instead (it is a bit faster)

Code: Select all

//+------------------------------------------------------------------+
//|                                                TradeBreakOut.mq4 |
//|                                  Copyright © 2013, Andriy Moraru |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.earnforex.com"
/*
Red line crossing 0 from above is a support breakout signal.
Green line crossing 0 from below is a resistance breakout signal.
*/
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_color1 Green
#property indicator_color2 Red
//---
extern int L=50; // Period
extern ENUM_APPLIED_PRICE PriceTypeHigh=PRICE_HIGH;
extern ENUM_APPLIED_PRICE PriceTypeLow =PRICE_LOW; 
extern ENUM_MA_METHOD     AverageMethod=MODE_SMA;
extern int                AveragePeriod=5;
//--- Buffers
double TBR_R[],TBR_S[],priceh[],pricel[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,TBR_R);
   SetIndexBuffer(1,TBR_S);
   SetIndexBuffer(2,priceh);
   SetIndexBuffer(3,pricel);
   IndicatorDigits(Digits);
   IndicatorShortName("TBR("+L+")");
   return(0);
}
int start()
{
   if(Bars <= L) return(0);
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
//--- Skip calculated bars
   int end=Bars-counted_bars;
//--- Cannot calculate bars that are too close to the end. There won't be enough bars to calculate ArrayMin/Max
   if(Bars-end<=L) end=Bars -(L+1);
//---
   Comment(end);
   for(int i=end; i>=0; i--)
   {
      double th = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeHigh,i);
      double tl = iMA(NULL,0,AveragePeriod,0,AverageMethod,PriceTypeLow,i);
      priceh[i] = MathMax(th,tl);
      pricel[i] = MathMin(th,tl);
      double max = priceh[ArrayMaximum(priceh, L, i + 1)];
      double min = pricel[ArrayMinimum(pricel, L, i + 1)];
      TBR_R[i] = (max!=0) ? (priceh[i] - priceh[ArrayMaximum(priceh, L, i + 1)]) / max : 0;
      TBR_S[i] = (min!=0) ? (pricel[i] - pricel[ArrayMinimum(pricel, L, i + 1)]) / min : 0;
   }
   return(0);
}




Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Telegram [Bot] and 86 guests