Jump to content
Medved Trader Forums
  • 0

zerolag macd & t3 stoch


rickroberts
 Share

Question

4 answers to this question

Recommended Posts

  • 0

Ok, I added ZLMA. Also added ZLMA to all the other indicators that accept multiple MA types (such as MA Ribbons or MA Envelope). Also added ZLMA as an option to MACD and MACD Histogram.

 

 

T3 stoch - would the algorithm be:

 

1. calc T3

2. find highest and lowest T3 over the T3 period  - high and low

3. show (T3-low)*100/(high-low)

 

??

Link to comment
Share on other sites

  • 0

zerolag macd:

 

#property indicator_separate_window
#property  indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Orange
//---- input parameters
extern int       FastEMA=12;
extern int       SlowEMA=24;
extern int       SignalEMA=9;
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(5);
   SetIndexBuffer(0,MACDBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,FastEMABuffer);
   SetIndexBuffer(3,SlowEMABuffer);
   SetIndexBuffer(4,SignalEMABuffer);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2);
   SetIndexDrawBegin(0,SlowEMA);
   SetIndexDrawBegin(1,SlowEMA);
   IndicatorShortName("ZeroLag MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   double EMA,ZeroLagEMAp,ZeroLagEMAq;
   for(int i=0; i<limit; i++)
      {
         FastEMABuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i);
         SlowEMABuffer=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
      }
   for(i=0; i<limit; i++)
      {
         EMA=iMAOnArray(FastEMABuffer,Bars,FastEMA,0,MODE_EMA,i);
         ZeroLagEMAp=FastEMABuffer+FastEMABuffer-EMA;
         EMA=iMAOnArray(SlowEMABuffer,Bars,SlowEMA,0,MODE_EMA,i);
         ZeroLagEMAq=SlowEMABuffer+SlowEMABuffer-EMA;
         MACDBuffer=ZeroLagEMAp - ZeroLagEMAq;
      }
   for(i=0; i<limit; i++)
         SignalEMABuffer=iMAOnArray(MACDBuffer,Bars,SignalEMA,0,MODE_EMA,i);
   for(i=0; i<limit; i++)
      {
         EMA=iMAOnArray(SignalEMABuffer,Bars,SignalEMA,0,MODE_EMA,i);
         SignalBuffer=SignalEMABuffer+SignalEMABuffer-EMA;
      }
   return(0);
  }
//+------------------------------------------------------------------+

 

 

t3rad:

 

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property  indicator_color2  Snow
#property  indicator_level1  80
#property  indicator_level2  20
#property  indicator_levelcolor Gray
#property  indicator_levelstyle 2
//----
extern int KPeriod=21;
extern int DPeriod=4;
extern int Slowing=3;
extern int Price_field = 1; //Price field parameter. Can be one of this values: 0 - Low/High or 1 - Close/Close.
extern int MA_Method  =  3; //MODE_SMA :    0 // MODE_EMA:    1 // MODE_SMMA: 2 // MODE_LWMA: 3 //
extern int T3_Period = 9;
extern double b = 0.63;
extern int Style  = 0;

//----
double e1, e2, e3, e4, e5, e6;
double e1a, e2a, e3a, e4a, e5a, e6a;
double c1, c2, c3, c4;
double c1a, c2a, c3a, c4a;
double n, w1, w2, b2, b3;
double na, w1a, w2a, b2a, b3a;
double Stochastic[];
double Stochastic_Signal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators setting
    SetIndexBuffer(0, Stochastic);
    SetIndexBuffer(1, Stochastic_Signal);

//----
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_LINE);

    
//----        
    IndicatorShortName("Rads Stochastic T3("+KPeriod+","+DPeriod+","+Slowing+", T3 "+T3_Period+ ")");
    SetIndexLabel(0, "Stochastic");     
    SetIndexLabel(1, "Signal");
   
//---- variable reset
    b2 = b*b;
    b3 = b2*b;
    c1 = -b3;
    c2 = (3*(b2 + b3));
    c3 = -3*(2*b2 + b + b3);
    c4 = (1 + 3*b + b3 + 3*b2);
    n = T3_Period;
    
    b2a = b*b;
    b3a = b2a*b;
    c1a = -b3a;
    c2a = (3*(b2a + b3a));
    c3a = -3*(2*b2a + b + b3a);
    c4a = (1 + 3*b + b3a + 3*b2a);
    na = T3_Period;
//----
    if(n < 1)
        n = 1;
    n = 1 + 0.5*(n - 1);
    w1 = 2 / (n + 1);
    w2 = 1 - w1;
    
        na = 1;
    na = 1 + 0.5*(na - 1);
    w1a = 2 / (na + 1);
    w2a = 1 - w1a;     
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0)
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0)
       counted_bars--;
   limit = Bars - counted_bars;  
//---- indicator calculation
   for(int i = Bars - 1; i >= 0; i--)
     {   
       Stochastic = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MA_Method,Price_field,MODE_MAIN,i);         
       e1 = w1*Stochastic  + w2*e1;
       e2 = w1*e1 + w2*e2;
       e3 = w1*e2 + w2*e3;
       e4 = w1*e3 + w2*e4;
       e5 = w1*e4 + w2*e5;
       e6 = w1*e5 + w2*e6;    
       Stochastic  = c1*e6 + c2*e5 + c3*e4 + c4*e3;    
     }
     for(i = Bars - 1 ; i >= 0; i--)
     {    
       Stochastic_Signal = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MA_Method,Price_field,MODE_SIGNAL,i);
       e1 = w1*Stochastic_Signal  + w2*e1;
       e2 = w1*e1 + w2*e2;
       e3 = w1*e2 + w2*e3;
       e4 = w1*e3 + w2*e4;
       e5 = w1*e4 + w2*e5;
       e6 = w1*e5 + w2*e6;    
       Stochastic_Signal = c1*e6 + c2*e5 + c3*e4 + c4*e3;  
      }   
             
//----
   return(0);
  }
//+------------------------------------------------------------------+

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...