Examples: Effective Averaging Algorithms with Minimal Lag: Use in Indicators

 

New article Effective Averaging Algorithms with Minimal Lag: Use in Indicators has been published:

The article describes custom averaging functions of higher quality developed by the author: JJMASeries(), JurXSeries(), JLiteSeries(), ParMASeries(), LRMASeries(), T3Series(). The article also deals with application of the above functions in indicators. The author introduces a rich indicators library based on the use of these functions.

Author: Nikolay Kositsin

 

Hi Nikolay,

Thank you for a outstanding article. If you would like to use indicators with HTF at the end of the name in EA, write values to .csv and read .csv from EA.

Again, well done!!

 

Hi Nikolay,


great stuff - thanks a lot! However, when I use the functions JJMASeries () and JurXSeries () within my own indicators and then call the indicators from within an EA some strange error messages show up in the log:

2008.05.27 00:04:01    FXRangeSpotX USDCAD,Daily: JurX.Series number =0. Îøèáêà!!! Ïàðàìåòð nJurX.limit ôóíêöèè JurX.Series() áîëüøå ÷åì íåîáõîäèìî íà 1
2008.05.27 00:04:01    NNSignal USDCAD,Daily: JurXSeries number =0. Êîä îøèáêè = 4002. èíäåêñ ìàññèâà íå ñîîòâåòñòâóåò åãî ðàçìåðó
2008.05.27 00:04:01    NNSignal USDCAD,Daily: JurXSeries number =0. Ïðè èñïîëíåíèè ôóíêöèè JurXSeries() ïðîèçîøëà îøèáêà!!!
2008.05.27 00:01:47    FXRangeSpotX GBPUSD,H1: JurX.Series number =0. Îøèáêà!!! Ïàðàìåòð nJurX.limit ôóíêöèè JurX.Series() áîëüøå ÷åì íåîáõîäèìî íà 1
2008.05.27 00:01:47    NNSignal GBPUSD,H1: JurXSeries number =0. Êîä îøèáêè = 4002. èíäåêñ ìàññèâà íå ñîîòâåòñòâóåò åãî ðàçìåðó
2008.05.27 00:01:47    NNSignal GBPUSD,H1: JurXSeries number =0. Ïðè èñïîëíåíèè ôóíêöèè JurXSeries() ïðîèçîøëà îøèáêà!!!


I have followed your instructions exactly but cannot get rid of the error messages... Key question is: is there a bug in the functions or am I doing something wrong. Here is the indicator code  that causes  the problem when called from an EA:



#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Yellow

//---- input parameters

extern int IndexPeriod = 10;
extern int Length_0 = 5;   
extern int Length_1 = 10;   

extern int Input_Price_Customs = 0;

#include <SmoothAlg.mqh>

//---- buffers
double Buffer1[], Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string name = "FXRangeSpotX";
  IndicatorShortName(name);
  IndicatorBuffers(2);
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buffer1); 
   SetIndexShift(0, 0);
   SetIndexEmptyValue(0, 0.0);
       
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1,Buffer2);
   SetIndexShift(1, 0);
   SetIndexEmptyValue(1, 0.0); 
  
   SetIndexLabel(0,name);
   SetIndexDrawBegin(0,IndexPeriod);
  
   JurXSeriesResize(1);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i, limit, counted_bars;
   double bulls, bears;
   double dMA;
  
   counted_bars =IndicatorCounted();
/*
   Print("Bars: " + Bars + "; Counted: " + counted_bars);
   Print("Time of Bars[0]: " + TimeToStr(Time[0]));
   Print("Time of Bars[Bars-1]: " + TimeToStr(Time[Bars-1]));
*/
 
  //---- check for possible errors
   if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
   if(counted_bars>0)
      counted_bars--;
    
   limit=Bars-counted_bars;
    
   if (Bars <= IndexPeriod) { //set index buffer to 0
      for (i = 0; i < limit; i++) {
          Buffer1[i] = 0.0;
          Buffer2[i] = 0.0;
          }
      return (0);
   }

   for (i = 0; i < limit; i++) {
      Buffer1[i] = iSomeIndicator(NULL, 0, IndexPeriod, i) / 100.0;
      Buffer2[i] = Buffer1[i];
      }
          
     smoothJurX(Buffer1, Length_0, counted_bars);
     smoothJurX(Buffer2, Length_1, counted_bars);

   return(0);
  }

 

Hey Jurik,

its just lately that i started to get into your ideas. Very interesting & effective. Thanks a lot for sharing.