Metatrader 5 coding questions / issues - page 7

 
dr.house7:
Another bug?

I don't know yet

From what I see the whole code should be written much simpler and only then it will be clear what exactly is happening

 
mladen:
I don't know yet From what I see the whole code should be written much simpler and only then it will be clear what exactly is happening

Oh god, why always me?

 

I wrote to Nikolay Kositsin (godzilla), the one who edited the code before me, to partecipate to the discussion.

 

Is there anyone with mt5 equivalence of fisher_m11.mq4? I find this indicator promising since it does not repaint. I believe I can deduce some strategy based on this indicator which can later be developed into an expert advisor. Please find below, my effort of converting fisher_m11.mq4 to mq5. Thanks.//+------------------------------------------------------------------+

//| fisher_m11_test.mq5 |

//| Copyright 2013, MetaQuotes Software Corp. |

//| MQL5: automated forex trading, strategy tester and custom indicators with MetaTrader |

//+------------------------------------------------------------------+

#property copyright "Copyright 2013, MetaQuotes Software Corp."

#property link "https://www.mql5.com"

#property version "1.00"

//#property indicator_chart_window

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots 1

#property indicator_color1 Lime, Red

#property indicator_type1 DRAW_COLOR_HISTOGRAM

#property indicator_style1 STYLE_SOLID

#property indicator_width1 2

int LeftNum1=56;

int LeftNum2=56;

//---- indicator parameters

input int RangePeriods=30;

//input double PriceSmoothing=0.3; // =0.67 bei Fisher_m10

//input double IndexSmoothing=0.3; // =0.50 bei Fisher_m10

double PriceSmoothing=0.3; // =0.67 bei Fisher_m10

double IndexSmoothing=0.3; // =0.50 bei Fisher_m10

//---- indicator buffers

double ExtBuffer0[]; //This buffer is for drawing

double ExtBuffer1[]; //This buffer is for color

string ThisName="Fisher_m11";

int DrawStart;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

//--- indicator buffers mapping

IndicatorSetString(INDICATOR_SHORTNAME, "Fisher");

IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1);

//---- indicator buffers mapping

SetIndexBuffer(0, ExtBuffer0, INDICATOR_DATA);

SetIndexBuffer(1, ExtBuffer1, INDICATOR_COLOR_INDEX);

/*string Text=ThisName;

Text=Text+" (rPeriods "+RangePeriods;

Text=Text+", pSmooth "+DoubleToStr(PriceSmoothing,2);

Text=Text+", iSmooth "+DoubleToStr(IndexSmoothing,2);

Text=Text+") ";

IndicatorSetString(INDICATOR_SHORTNAME,Text);

*/

PlotIndexSetString(1,PLOT_LABEL,NULL);

PlotIndexSetString(2,PLOT_LABEL,NULL);

DrawStart=2*RangePeriods+4; // DrawStart= BarNumber calculated from left to right

PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,DrawStart);

PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,DrawStart);

if (PriceSmoothing>=1.0)

{

PriceSmoothing=0.9999;

Alert("Fish61: PriceSmothing factor has to be smaller 1!");

}

if (PriceSmoothing<0)

{

PriceSmoothing=0;

Alert("Fish61: PriceSmothing factor mustn''t be negative!");

}

if (IndexSmoothing>=1.0)

{

IndexSmoothing=0.9999;

Alert("Fish61: PriceSmothing factor has to be smaller 1!");

}

if (IndexSmoothing<0)

{

IndexSmoothing=0;

Alert("Fish61: PriceSmothing factor mustn''t be negative!");

}

//---

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

/*int OnDeinit()

{

//----

//----

return(0);

}

*/

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

const int prev_calculated,

const datetime &time[],

const double &open[],

const double &high[],

const double &low[],

const double &close[],

const long &tick_volume[],

const long &volume[],

const int &spread[])

{

//---

//--- return value of prev_calculated for next call

return(rates_total);

}

//custom iteration

int OnStart()

{

int Bars=Bars(_Symbol,_Period);

if (Bars<DrawStart)

{

Alert("Fish84: Not enough Bars loaded to calculate FisherIndicator with RangePeriods=",RangePeriods);

return(-1);

}

//----

int counted_bars=IndicatorCountedMQL4();

if (counted_bars<0) return(-1);

if (counted_bars>0) counted_bars--;

//----

int Position=Bars-counted_bars; // Position = BarPosition calculated from right to left

LeftNum1=Bars-Position; // when more bars are loaded the Position of a bar changes but not its LeftNum

if (LeftNum1<RangePeriods+1)Position=Bars-RangePeriods-1;

while(Position>=0)

{

CalculateCurrentBar(Position);

Position--;

}

return(0);

}

//+------------------------------------------------------------------+

//| Single Bar Calculation function |

//+------------------------------------------------------------------+

int CalculateCurrentBar(int pos)

{

double LowestLow, HighestHigh, GreatestRange, MidPrice;

double PriceLocation, SmoothedLocation, FishIndex, SmoothedFish;

//----

LowestLow = Low[Lowest(NULL,0,MODE_LOW,RangePeriods,pos)];

HighestHigh = High;

if (HighestHigh-LowestLow<0.1*Point)HighestHigh=LowestLow+0.1*Point;

GreatestRange=HighestHigh-LowestLow;

MidPrice = (High[pos]+Low[pos])/2;

// PriceLocation in current Range

if (GreatestRange!=0)

{

PriceLocation=(MidPrice-LowestLow)/GreatestRange;

PriceLocation= 2.0*PriceLocation - 1.0; // -> -1 < PriceLocation < +1

}

// Smoothing of PriceLocation

ExtMapBuffer4[pos]=PriceSmoothing*ExtMapBuffer4[pos+1]+(1.0-PriceSmoothing)*PriceLocation;

SmoothedLocation=ExtMapBuffer4[pos];

if (SmoothedLocation> 0.99) SmoothedLocation= 0.99; // verhindert, dass MathLog unendlich wird

if (SmoothedLocation<-0.99) SmoothedLocation=-0.99; // verhindert, dass MathLog minuns unendlich wird

// FisherIndex

if(1-SmoothedLocation!=0) FishIndex=MathLog((1+SmoothedLocation)/(1-SmoothedLocation));

else Alert("Fisher129: Unerlaubter Zustand bei Bar Nummer ",Bars-pos);

// Smoothing of FisherIndex

ExtMapBuffer1[pos]=IndexSmoothing*ExtMapBuffer1[pos+1]+(1.0-IndexSmoothing)*FishIndex;

if (Bars-pos<DrawStart)ExtMapBuffer1[pos]=0;

SmoothedFish=ExtMapBuffer1[pos];

if (SmoothedFish>0) // up trend

{

ExtMapBuffer2[pos]=SmoothedFish;

ExtMapBuffer3[pos]=0;

}

else // else down trend

{

ExtMapBuffer2[pos]=0;

ExtMapBuffer3[pos]=SmoothedFish;

}

return (0);

}

 
funayot:
Is there anyone with mt5 equivalence of fisher_m11.mq4? I find this indicator promising since it does not repaint. I believe I can deduce some strategy based on this indicator which can later be developed into an expert advisor. Please find below, my effort of converting fisher_m11.mq4 to mq5. Thanks.//+------------------------------------------------------------------+

//| fisher_m11_test.mq5 |

//| Copyright 2013, MetaQuotes Software Corp. |

//| MQL5: automated forex trading, strategy tester and custom indicators with MetaTrader |

//+------------------------------------------------------------------+

#property copyright "Copyright 2013, MetaQuotes Software Corp."

#property link "https://www.mql5.com"

#property version "1.00"

//#property indicator_chart_window

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots 1

#property indicator_color1 Lime, Red

#property indicator_type1 DRAW_COLOR_HISTOGRAM

#property indicator_style1 STYLE_SOLID

#property indicator_width1 2

int LeftNum1=56;

int LeftNum2=56;

//---- indicator parameters

input int RangePeriods=30;

//input double PriceSmoothing=0.3; // =0.67 bei Fisher_m10

//input double IndexSmoothing=0.3; // =0.50 bei Fisher_m10

double PriceSmoothing=0.3; // =0.67 bei Fisher_m10

double IndexSmoothing=0.3; // =0.50 bei Fisher_m10

//---- indicator buffers

double ExtBuffer0[]; //This buffer is for drawing

double ExtBuffer1[]; //This buffer is for color

string ThisName="Fisher_m11";

int DrawStart;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

//--- indicator buffers mapping

IndicatorSetString(INDICATOR_SHORTNAME, "Fisher");

IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1);

//---- indicator buffers mapping

SetIndexBuffer(0, ExtBuffer0, INDICATOR_DATA);

SetIndexBuffer(1, ExtBuffer1, INDICATOR_COLOR_INDEX);

/*string Text=ThisName;

Text=Text+" (rPeriods "+RangePeriods;

Text=Text+", pSmooth "+DoubleToStr(PriceSmoothing,2);

Text=Text+", iSmooth "+DoubleToStr(IndexSmoothing,2);

Text=Text+") ";

IndicatorSetString(INDICATOR_SHORTNAME,Text);

*/

PlotIndexSetString(1,PLOT_LABEL,NULL);

PlotIndexSetString(2,PLOT_LABEL,NULL);

DrawStart=2*RangePeriods+4; // DrawStart= BarNumber calculated from left to right

PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,DrawStart);

PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,DrawStart);

if (PriceSmoothing>=1.0)

{

PriceSmoothing=0.9999;

Alert("Fish61: PriceSmothing factor has to be smaller 1!");

}

if (PriceSmoothing<0)

{

PriceSmoothing=0;

Alert("Fish61: PriceSmothing factor mustn''t be negative!");

}

if (IndexSmoothing>=1.0)

{

IndexSmoothing=0.9999;

Alert("Fish61: PriceSmothing factor has to be smaller 1!");

}

if (IndexSmoothing<0)

{

IndexSmoothing=0;

Alert("Fish61: PriceSmothing factor mustn''t be negative!");

}

//---

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

/*int OnDeinit()

{

//----

//----

return(0);

}

*/

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

const int prev_calculated,

const datetime &time[],

const double &open[],

const double &high[],

const double &low[],

const double &close[],

const long &tick_volume[],

const long &volume[],

const int &spread[])

{

//---

//--- return value of prev_calculated for next call

return(rates_total);

}

//custom iteration

int OnStart()

{

int Bars=Bars(_Symbol,_Period);

if (Bars<DrawStart)

{

Alert("Fish84: Not enough Bars loaded to calculate FisherIndicator with RangePeriods=",RangePeriods);

return(-1);

}

//----

int counted_bars=IndicatorCountedMQL4();

if (counted_bars<0) return(-1);

if (counted_bars>0) counted_bars--;

//----

int Position=Bars-counted_bars; // Position = BarPosition calculated from right to left

LeftNum1=Bars-Position; // when more bars are loaded the Position of a bar changes but not its LeftNum

if (LeftNum1<RangePeriods+1)Position=Bars-RangePeriods-1;

while(Position>=0)

{

CalculateCurrentBar(Position);

Position--;

}

return(0);

}

//+------------------------------------------------------------------+

//| Single Bar Calculation function |

//+------------------------------------------------------------------+

int CalculateCurrentBar(int pos)

{

double LowestLow, HighestHigh, GreatestRange, MidPrice;

double PriceLocation, SmoothedLocation, FishIndex, SmoothedFish;

//----

LowestLow = Low[Lowest(NULL,0,MODE_LOW,RangePeriods,pos)];

HighestHigh = High;

if (HighestHigh-LowestLow<0.1*Point)HighestHigh=LowestLow+0.1*Point;

GreatestRange=HighestHigh-LowestLow;

MidPrice = (High[pos]+Low[pos])/2;

// PriceLocation in current Range

if (GreatestRange!=0)

{

PriceLocation=(MidPrice-LowestLow)/GreatestRange;

PriceLocation= 2.0*PriceLocation - 1.0; // -> -1 < PriceLocation < +1

}

// Smoothing of PriceLocation

ExtMapBuffer4[pos]=PriceSmoothing*ExtMapBuffer4[pos+1]+(1.0-PriceSmoothing)*PriceLocation;

SmoothedLocation=ExtMapBuffer4[pos];

if (SmoothedLocation> 0.99) SmoothedLocation= 0.99; // verhindert, dass MathLog unendlich wird

if (SmoothedLocation<-0.99) SmoothedLocation=-0.99; // verhindert, dass MathLog minuns unendlich wird

// FisherIndex

if(1-SmoothedLocation!=0) FishIndex=MathLog((1+SmoothedLocation)/(1-SmoothedLocation));

else Alert("Fisher129: Unerlaubter Zustand bei Bar Nummer ",Bars-pos);

// Smoothing of FisherIndex

ExtMapBuffer1[pos]=IndexSmoothing*ExtMapBuffer1[pos+1]+(1.0-IndexSmoothing)*FishIndex;

if (Bars-pos<DrawStart)ExtMapBuffer1[pos]=0;

SmoothedFish=ExtMapBuffer1[pos];

if (SmoothedFish>0) // up trend

{

ExtMapBuffer2[pos]=SmoothedFish;

ExtMapBuffer3[pos]=0;

}

else // else down trend

{

ExtMapBuffer2[pos]=0;

ExtMapBuffer3[pos]=SmoothedFish;

}

return (0);

}

Modified the Ehlers Fisher Transform to make a version of fisher_m11.

 
mrtools:
Modified the Ehlers Fisher Transform to make a version of fisher_m11.

It's very close, thank you, I really appreciate your effort. Do you have any suggestion as to building an EA based on this indicator?

 
funayot:
It's very close, thank you, I really appreciate your effort. Do you have any suggestion as to building an EA based on this indicator?

Good question, would have to think about something that would go with it, and get back to you.

 

I tried using the custom indicator Ehlers fisher transform _m_11.mq5 in eatree.com ea builder, but I received an error. This error does not show in the mq4 version - fisher_m11.mq4. "Error at line 37 while loading button iCustom_5(in7), unknown data type [input enPrices EftPrice = pr_close;" I will play around the code and see what I get.

mrtools:
Good question, would have to think about something that would go with it, and get back to you.
 

Mladen, can you make the indicators fisher_m11.mq4 and its mq5 Multi-Time-Frame? Thanks in advance.

 
funayot:
Mladen, can you make the indicators fisher_m11.mq4 and its mq5 Multi-Time-Frame? Thanks in advance.

funayot,

This is a correct Ehlers fisher transform for metatrader 5 : https://www.mql5.com/en/forum/181297/page13

Reason: