Help with Tradestation to MQL4 Equivalent code.

 

Hi,

I have a simple piece of code I'm trying to convert to MQL4, However I have no experience with TradeStation's EasyLanguage.

The whole code:

Inputs:
        Cutoff(60);

Vars:
        alpha1(0),
        HP(0),
        Decycle(0);

//Highpass filter cyclic components whose periods are shorter than “cutoff” bars
alpha1 = (Cosine(360 / Cutoff) + Sine (360 / Cutoff) - 1) /
Cosine(360 / Cutoff);
Decycle = (alpha1 / 2)*(Close + Close[1]) + (1- alpha1)*Decycle[1];

Plot1(Decycle);


The part I can't quite translate is this line:

Decycle = (alpha1 / 2)*(Close + Close[1]) + (1- alpha1)*Decycle[1];

What is the MQL4 equivalent of  Decycle[1]?

any help is greatly appreciated, Thank you.

 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. double       Ln(double v){    return MathLog(v);                  }
    double     Sine(double a){    return MathSin(a * M_PI/180.0);     }
    double   Cosine(double a){    return MathCos(a * M_PI/180.0);     }
    double   Arctangent(double v){ return MathArctan(v) * 180.0/M_PI; }
    :
    Decycle[iBar] = (alpha1 / 2)*(Close[iBar] + Close[iBar+1]) + (1- alpha1)*Decycle[iBar+1];

 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.


Thank you very much for the help. Sorry If I asked this question in the wrong place.

It might be lack of sleep getting to me, but now my output seems to be astronomically to high.

Current code: 

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_label1  "Decycler"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrWhite
#property indicator_style1  STYLE_SOLID
extern int Cutoff=60;
double       Ln(double v){    return MathLog(v);                  }
double     Sine(double a){    return MathSin(a * M_PI/180.0);     }
double   Cosine(double a){    return MathCos(a * M_PI/180.0);     }
double   Arctangent(double v){ return MathArctan(v)*180.0/M_PI; }
double Decycle[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

//---- indicators
   SetIndexBuffer(0,Decycle,INDICATOR_DATA);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {

   int limit;

   int counted_bars=IndicatorCounted();

//---- 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;

//---- main loop

   for(int i=0; i<limit; i++)

     {

      double   alpha1=(Cosine(360/Cutoff)+Sine(360/Cutoff)-1)/Cosine(360/Cutoff);
      Decycle[i] = (alpha1 / 2)*(Close[i] + Close[i+1]) + (1- alpha1)*Decycle[i+1];  
     }

//----
   return(0);
  }
//+------------------------------------------------------------------+

The Output should be somewhere near price, However mine is outputting huge off the chart numbers.

Thanks again for the help.

Reason: