Thread: Jurik
View Single Post
  #8 (permalink)  
Old 10-30-2005, 02:12 PM
quksilver quksilver is offline
Junior Member
 
Join Date: Oct 2005
Posts: 14
quksilver is on a distinguished road
The Jurik indicators are pretty hard to understand and troubleshoot. But they certainly look worthwhile. I've been trying to use CFB to code an adaptive RSX, as described in the pdf manual. It keeps giving me odd values that I can't find anywhere in the array of CFB. Could someone look at the code and try to find an error? Here's the code... I think the problem is somewhere in the for loop.

This portion normalizes CFB to a value between 0 and 1.
Code:
      if(CFB.result > CFB.max) 
         CFB.max=CFB.result;
      else if(CFB.result < CFB.min) 
         CFB.min=CFB.result;
      
      denominator=CFB.max-CFB.min;
      if(denominator>0)
         stoch.ratio=(CFB.result-CFB.min)/denominator;
      else
         stoch.ratio=0.5;
This portion uses the normalized CFB to determine a length for JSRX between the hi and lo values input by the user:
Code:
      JRSX.length=MathCeil(Lo.RSI.Period+stoch.ratio*(Hi.RSI.Period-Lo.RSI.Period));
The problem is that the high is always 0.64626709 and the low is always 0. At least, that's how they print out. They should change as CFB finds new highs and lows. And as far as I can tell, CFB never returns those values. So I'm very confused because I've looked over the code a million times and can't figure it out. Many thanks to anyone who can help..

cheers,
-lcg


Code:
//+------------------------------------------------------------------+
//|                                                JRSX Adaptive.mq4 |
//|       JCFBaux: Copyright © 2005,            Weld, Jurik Research | 
//|                                          http://weld.torguem.net | 
//|          MQL4: Copyright © 2005,                Nikolay Kositsin | 
//|                                   Khabarovsk, violet@mail.kht.ru |   
//| JRSX Adaptive: Copyright © 2005,                    Loren Gordon |
//|                                    forex1[at]lorengordon[dot]com |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, Loren Gordon"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 1
#property  indicator_color1  Magenta
#property  indicator_level1  70
#property  indicator_level2  50
#property  indicator_level3  30

//---- indicator parameters
extern int Lo.RSI.Period=8;
extern int Hi.RSI.Period=24;
extern int CFB.Depth=24;
extern int Input.Price.Customs=2;
//(0-"Close", 1-"Open", 2-"High+Low", 3-"High", 4-"Low", 5-"Open+High+Low+Close", 6-Open+Close", ïî óìîë÷àíèþ-2.) 

//---- indicator buffers
double     ind_buffer0[];
int        draw_begin;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   draw_begin=CFB.Depth+Lo.RSI.Period+Hi.RSI.Period;
   SetIndexDrawBegin(0,draw_begin);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer0))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("JRSX Adaptive("+Lo.RSI.Period+","+Hi.RSI.Period+","+CFB.Depth+")");
   SetIndexLabel(0,"JRSX Adaptive");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| JSRX Adaptive                                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit,i;
   double denominator=0,stoch.ratio=0,CFB.result=0,CFB.max=0,CFB.min=99999,JRSX.length;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
   if(counted_bars<1)
      for(i=1;i<=draw_begin;i++) ind_buffer0[Bars-i]=0; 
//---- last counted bar will be recounted
   if(counted_bars>draw_begin) limit=Bars-counted_bars-1;
   else limit=Bars-counted_bars-draw_begin-1;

//---- JSRX adaptive counted in the 2-nd buffer
   for(i=limit; i>=0; i--)
     {
      CFB.result=iCustom(NULL,0,"JCFBaux",CFB.Depth,Input.Price.Customs,0,i);

      if(CFB.result > CFB.max) 
         CFB.max=CFB.result;
      else if(CFB.result < CFB.min) 
         CFB.min=CFB.result;
      
      denominator=CFB.max-CFB.min;
      if(denominator>0)
         stoch.ratio=(CFB.result-CFB.min)/denominator;
      else
         stoch.ratio=0.5;

      JRSX.length=MathCeil(Lo.RSI.Period+stoch.ratio*(Hi.RSI.Period-Lo.RSI.Period));
      Print("JSRX.length=",JRSX.length,
            " stoch.ratio=",stoch.ratio,
            " CFB.result=",CFB.result,
            " CFB.max=",DoubleToStr(CFB.max,8),
            " CFB.min=",DoubleToStr(CFB.min,8));
      ind_buffer0[i]=iCustom(NULL,0,"JRSX",JRSX.length,0,i);
     }
//---- done
   return(0);
  }
Reply With Quote