Please help me to migrate my strategy (indicator) to MT5

 

I have a request for converting an indicator from MT4 to MT5 which I would really appreciate. The problem is this: I started to learn trading and developing my strategy more than a year ago. I manually backtested and forward tested a strategy that includes an indicator called “Cyan 2 High Pass Filter” (with Dev) (I think it’s the same as Ehlers’ “Two-Pole High-Pass Filter” or “2 nd Order Gaussian High Pass Filter”). The version that I have has a deviation “envelope” overlain, which is very useful.

My backtest results were very promising (indices on D1 chart), but I decided to do a proper optimisation and walk forward analysis before going live, so I decided to switch to MT5 and learn to code at least a little to be able to write a multi-symbol EA, which I succeeded. I can code relatively simple EAs in MQL5 and they work fine, but not in MQL4 – and also I don’t know how to code indicators. So I wasn’t able to convert it myself (it doesn’t even have an OnCalculate() function, just “int start()…”).

If someone with enough knowledge could convert this indicator to MT5 it would be a great help for me, because I’m stuck. And I think it's a relatively simple indicator...

My strategy (in MT4 that I’d like to recreate in MT5) in short: when “Cyan 2 High Pass Filter with Dev” surpasses the deviation value and if also confirmed by W%R value, open position accordingly. Additionally I use a smoothed DPO with ATR channel to (try to) keep me out of overextended trends.

I’m attaching two .mq4 files:
- the first is the original file - the upper indicator in the screenshot
- the second one (“…_stripped”) is the same code with some lines removed, such as “… maxbars = 2000;” and some others that I deemed unnecessary (as long as it compiled and worked identically to the original)  - this is the bottom indicator in the screenshot – I probably shouldn’t have done that, but just so you know.

If you find my approach interesting, I’m willing to explain the details (and settings) further. So please help me make it “MT5 friendly”.

Thank you very much for any help!

//+------------------------------------------------------------------+
//|                           CyAn 2 High Pass Filter with Deviation |
//|                                           Luis Guilherme Damiani |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_label2 "Upper StdDev"
#property indicator_color3 Red
#property indicator_label3 "Lower StdDev"
#property indicator_level1 0
#property indicator_levelstyle DarkSlateGray

//---- input parameters
extern double            alpha           = 0.1;
extern int               maxbars         = 2000;
input double             deviation       = 1;
input int                period          = 5;
input int                shift           = 0;
input ENUM_MA_METHOD     method          = MODE_EMA;
input ENUM_APPLIED_PRICE price           = 0;

//---- buffers
double soHPF[];
double DevUp[];
double DevDn[];
double Res[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,soHPF); SetIndexStyle(0,DRAW_LINE); ArrayInitialize(soHPF,0);
   SetIndexBuffer(1,DevUp); SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,DevDn); SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(3,Res);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
     return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
      int    counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      int limit=Bars-counted_bars;
      if(limit>maxbars)limit=maxbars;      
      for (int i=limit; i>=0 && !_StopFlag; i--)
      {
               soHPF[i]=MathPow(1-alpha/2,2)*(Close[i] -2*Close[i+1]+Close[i+2])+2*(1-alpha)*soHPF[i+1]-MathPow(1-alpha,2)*soHPF[i+2]; 
          DevUp[i] = (deviation*iStdDev(NULL,0,period,i,method,price,shift));
          DevDn[i] = -(deviation*iStdDev(NULL,0,period,i,method,price,shift));        
          Res[i] = (soHPF[i]>DevUp[i]) ? 1 : (soHPF[i]<DevDn[i]) ? -1 : 0; 
      }

   return(0);
  }
//+------------------------------------------------------------------+
How to call indicators in MQL5
How to call indicators in MQL5
  • www.mql5.com
With new version of MQL programming language available not only the approach of dealing with indicators have changed, but there are also new ways of how to create indicators. Furthermore, you have additional flexibility working with indicator's buffers - now you can specify the desired direction of indexing and get exactly as many indicator's values as you want. This article explains the basic methods of calling indicators and retrieving data from the indicator's buffers.
 
rezalomalo:

I have a request for converting an indicator from MT4 to MT5 which I would really appreciate. 

Hello, my sugestion would be to post this job in Freelance area, there are in this community very experienced programmers.

 
You can look into various Indicators from the Examples folder, and find out everything on your own. 

Also this might be an easy task even for an intermediate Freelance programmer if they have experience with Indicators.

Why we suggest Freelance: Finding all of this out for yourself is real work.
 
Tobias Johannes Zimmer #:
Why we suggest Freelance: Finding all of this out for yourself is real work.

You are absolutely right Tobias, in my experience as a former customer of freelance service, I could learn how to do it myself in what, say 80-100 hours of my time, those hours have a precise value, while freelance service could give me the solution extremly fast for a fifth of that value. There are ppls that now khow to trade and ppls that know how to code, I say the most efficient way is to let everybody do the thing they are best at.

 
Marian Nelu Iopsu #:

You are absolutely right Tobias, in my experience as a former customer of freelance service, I could learn how to do it myself in what, say 80-100 hours of my time, those hours have a precise value, while freelance service could give me the solution extremly fast for a fifth of that value. There are ppls that now khow to trade and ppls that know how to code, I say the most efficient way is to let everybody do the thing they are best at.

Yes I understand what you mean. What would be your feeling about the cost of such a small indicator in the freelance area, if you've used it in the past? Just your rough estimate, before I start asking in that area? Around 25 EUR - more, less?

Thanks for replying.

 
rezalomalo #:

Yes I understand what you mean. What would be your feeling about the cost of such a small indicator in the freelance area, if you've used it in the past? Just your rough estimate, before I start asking in that area? Around 25 EUR - more, less?

Thanks for replying.

You can always look in Examples folder for free.
There will be not much to change in calculation it is more the preliminary stuff, buffers and initiation.
 
Tobias Johannes Zimmer #:
You can always look in Examples folder for free.
There will be not much to change in calculation it is more the preliminary stuff, buffers and initiation.
Yes, actualy I'm planning to try just that, and some tutorials on this site and YT... Hope it won't be much different from EAs.
 
If I get stuck, I can count on some help and advice on Codebase, I hope.
Reason: