MT4 to MT5 code converter - page 18

Hamid
21
Hamid  

Mladen,

Thank you ,

Zeki Müren
33
Zeki Müren  

thank you ,

name
992
name  
mladen:
Adjustable period fractal channel (the "super signals channel") : fractals_-_adjustable_period_channel.mq5

It does what all fractal does?

earmarques
19
earmarques  

Hi Mladen,

Please can you convert to mt5 the following indicator with option to select higher timeframes? I know this can be a big work and if needed I can pay for this service. I tried to convert but I don't code in mql no way. It's necessary because here in Brazil my broker only works with MT5.

Thanks in advance.

earmarques
19
earmarques  

Hi, I tried to convert, but the indicator returns the close price of each bar.

-----------------------------CODE CHANGED---------------------------------

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

//| Trend Quality Q indicator

//| mladen

//|

//| as Published in TASC 22:04 article

//| Trend Quality indicator" by David Sepiashvili

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

#property copyright "www.forex-tsd.com"

#property link "www.forex-tsd.com"

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_plots 2

#property indicator_color1 DeepSkyBlue

#property indicator_color2 PaleVioletRed

#property indicator_color3 DimGray

#property indicator_color4 HotPink

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

#property indicator_width4 2

#property indicator_levelcolor DimGray

#property indicator_type1 DRAW_HISTOGRAM

#property indicator_type2 DRAW_HISTOGRAM

//

//

//

//

//

input int TrendPeriod = 4;

input int NoisePeriod = 250;

input double CorrectionFactor = 2;

input int FastLength = 7;

input int SlowLength = 15;

input int Price = PRICE_CLOSE;

input double LevelBoundBeneathNoise = 1;

input double LevelBoundWeakTrend = 2;

input double LevelBoundModerateTrend = 5;

//

//

//

//

//

double trendQu[];

double trendQd[];

double trendQ[];

double trendQSign[];

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

//|

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

//

//

//

//

//

int OnInit()

{

SetIndexBuffer(0,trendQu,INDICATOR_DATA);

//SetIndexBuffer(0,trendQu);

PlotIndexSetInteger(0, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexBuffer(1,trendQd,INDICATOR_DATA);

//SetIndexBuffer(1,trendQd);

PlotIndexSetInteger(1, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexBuffer(2,trendQ,INDICATOR_DATA);

// PlotIndexSetInteger(2, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

// SetIndexBuffer(2,trendQ);

SetIndexBuffer(3,trendQSign,INDICATOR_DATA);

//PlotIndexSetInteger(3, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

// SetIndexBuffer(3,trendQSign);

//

//

//

//

//

IndicatorSetDouble(INDICATOR_LEVELVALUE,0,0);

// SetLevelValue(0,0);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, LevelBoundBeneathNoise);

// SetLevelValue(1, LevelBoundBeneathNoise);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, -LevelBoundBeneathNoise);

//SetLevelValue(2,-LevelBoundBeneathNoise);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, LevelBoundWeakTrend);

//SetLevelValue(3, LevelBoundWeakTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 4, -LevelBoundWeakTrend);

//SetLevelValue(4,-LevelBoundWeakTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 5, LevelBoundModerateTrend);

//SetLevelValue(5, LevelBoundModerateTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 6, -LevelBoundModerateTrend);

//SetLevelValue(6,-LevelBoundModerateTrend);

IndicatorSetString(INDICATOR_SHORTNAME, "Trend quality Q (");//+TrendPeriod+","+NoisePeriod+","+DoubleToStr(CorrectionFactor,2)+","+FastLength+","+SlowLength+")");

return(0);

}

int deinit() { return(0); }

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

//|

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

//

//

//

//

//

double work[][7];

#define _price 0

#define _emaf 1

#define _emas 2

#define _sign 3

#define _cpc 4

#define _trend 5

#define _dt 6

//

//

//

//

//

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[])

{

int i,k,r,limit,counted_bars=prev_calculated/*=prev_calculated*/;

int BarsX=rates_total;//Bars(_Symbol,_Period);

if(prev_calculated>0) counted_bars=(prev_calculated-1);

if(prev_calculated==0) counted_bars=(0);

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

if(counted_bars>0) counted_bars--;

limit = BarsX-counted_bars;

if (ArrayRange(work,0) != BarsX) ArrayResize(work,BarsX);

double alpha1 = 2.0 / (1.0+FastLength);

double alpha2 = 2.0 / (1.0+SlowLength);

for(i=limit, r=BarsX-limit-1; i>=0; i--,r++)

{

work[r][_price] = iMA(NULL,0,1,0,MODE_SMA,Price);

work[r][_emaf] = work[r-1][_emaf]+alpha1*(work[r][_price]-work[r-1][_emaf]);

work[r][_emas] = work[r-1][_emas]+alpha2*(work[r][_price]-work[r-1][_emas]);

double macd = work[r][_emaf]-work[r][_emas];

work[r][_sign] = work[r-1][_sign];

if (macd>0) work[r][_sign] = 1;

if (macd<0) work[r][_sign] = -1;

trendQSign = work[r][_sign];

double change = work[r][_price]-work[r-1][_price];

if (work[r][_sign] != work[r-1][_sign])

{

work[r][_cpc] = 0;

work[r][_trend] = 0;

}

else

{

work[r][_cpc] = change+work[r-1][_cpc];

work[r][_trend] = work[r][_cpc]*(1.0/TrendPeriod)+work[r-1][_trend]*(1.0-(1.0/TrendPeriod));

}

work[r][_dt] = (work[r][_cpc]-work[r][_trend])*(work[r][_cpc]-work[r][_trend]);

double avgDt = 0; for (k=0; k<NoisePeriod; k++) avgDt += work[r-k][_dt]; avgDt /= NoisePeriod;

double noise = CorrectionFactor*MathSqrt(avgDt);

if (noise != 0)

trendQ = work[r][_trend]/noise;

else trendQ = 0;

trendQu = EMPTY_VALUE;

trendQd = EMPTY_VALUE;

if (trendQ>0) trendQu = trendQ;

if (trendQ<0) trendQd = trendQ;

}

return(0);

}

-----------------------------END CODE-----------------------------------------

Mladen Rakic
201568
Mladen Rakic  
earmarques:
Hi, I tried to convert, but the indicator returns the close price of each bar.

-----------------------------CODE CHANGED---------------------------------

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

//| Trend Quality Q indicator

//| mladen

//|

//| as Published in TASC 22:04 article

//| Trend Quality indicator" by David Sepiashvili

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

#property copyright "www.forex-tsd.com"

#property link "www.forex-tsd.com"

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_plots 2

#property indicator_color1 DeepSkyBlue

#property indicator_color2 PaleVioletRed

#property indicator_color3 DimGray

#property indicator_color4 HotPink

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

#property indicator_width4 2

#property indicator_levelcolor DimGray

#property indicator_type1 DRAW_HISTOGRAM

#property indicator_type2 DRAW_HISTOGRAM

//

//

//

//

//

input int TrendPeriod = 4;

input int NoisePeriod = 250;

input double CorrectionFactor = 2;

input int FastLength = 7;

input int SlowLength = 15;

input int Price = PRICE_CLOSE;

input double LevelBoundBeneathNoise = 1;

input double LevelBoundWeakTrend = 2;

input double LevelBoundModerateTrend = 5;

//

//

//

//

//

double trendQu[];

double trendQd[];

double trendQ[];

double trendQSign[];

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

//|

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

//

//

//

//

//

int OnInit()

{

SetIndexBuffer(0,trendQu,INDICATOR_DATA);

//SetIndexBuffer(0,trendQu);

PlotIndexSetInteger(0, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexBuffer(1,trendQd,INDICATOR_DATA);

//SetIndexBuffer(1,trendQd);

PlotIndexSetInteger(1, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexBuffer(2,trendQ,INDICATOR_DATA);

// PlotIndexSetInteger(2, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

// SetIndexBuffer(2,trendQ);

SetIndexBuffer(3,trendQSign,INDICATOR_DATA);

//PlotIndexSetInteger(3, PLOT_DRAW_TYPE,DRAW_HISTOGRAM);

//SetIndexStyle(1,DRAW_HISTOGRAM);

// SetIndexBuffer(3,trendQSign);

//

//

//

//

//

IndicatorSetDouble(INDICATOR_LEVELVALUE,0,0);

// SetLevelValue(0,0);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, LevelBoundBeneathNoise);

// SetLevelValue(1, LevelBoundBeneathNoise);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, -LevelBoundBeneathNoise);

//SetLevelValue(2,-LevelBoundBeneathNoise);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, LevelBoundWeakTrend);

//SetLevelValue(3, LevelBoundWeakTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 4, -LevelBoundWeakTrend);

//SetLevelValue(4,-LevelBoundWeakTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 5, LevelBoundModerateTrend);

//SetLevelValue(5, LevelBoundModerateTrend);

IndicatorSetDouble(INDICATOR_LEVELVALUE, 6, -LevelBoundModerateTrend);

//SetLevelValue(6,-LevelBoundModerateTrend);

IndicatorSetString(INDICATOR_SHORTNAME, "Trend quality Q (");//+TrendPeriod+","+NoisePeriod+","+DoubleToStr(Corre ctionFactor,2)+","+FastLength+","+SlowLength+")");

return(0);

}

int deinit() { return(0); }

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

//|

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

//

//

//

//

//

double work[][7];

#define _price 0

#define _emaf 1

#define _emas 2

#define _sign 3

#define _cpc 4

#define _trend 5

#define _dt 6

//

//

//

//

//

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[])

{

int i,k,r,limit,counted_bars=prev_calculated/*=prev_calculated*/;

int BarsX=rates_total;//Bars(_Symbol,_Period);

if(prev_calculated>0) counted_bars=(prev_calculated-1);

if(prev_calculated==0) counted_bars=(0);

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

if(counted_bars>0) counted_bars--;

limit = BarsX-counted_bars;

if (ArrayRange(work,0) != BarsX) ArrayResize(work,BarsX);

double alpha1 = 2.0 / (1.0+FastLength);

double alpha2 = 2.0 / (1.0+SlowLength);

for(i=limit, r=BarsX-limit-1; i>=0; i--,r++)

{

work[r][_price] = iMA(NULL,0,1,0,MODE_SMA,Price);

work[r][_emaf] = work[r-1][_emaf]+alpha1*(work[r][_price]-work[r-1][_emaf]);

work[r][_emas] = work[r-1][_emas]+alpha2*(work[r][_price]-work[r-1][_emas]);

double macd = work[r][_emaf]-work[r][_emas];

work[r][_sign] = work[r-1][_sign];

if (macd>0) work[r][_sign] = 1;

if (macd<0) work[r][_sign] = -1;

trendQSign = work[r][_sign];

double change = work[r][_price]-work[r-1][_price];

if (work[r][_sign] != work[r-1][_sign])

{

work[r][_cpc] = 0;

work[r][_trend] = 0;

}

else

{

work[r][_cpc] = change+work[r-1][_cpc];

work[r][_trend] = work[r][_cpc]*(1.0/TrendPeriod)+work[r-1][_trend]*(1.0-(1.0/TrendPeriod));

}

work[r][_dt] = (work[r][_cpc]-work[r][_trend])*(work[r][_cpc]-work[r][_trend]);

double avgDt = 0; for (k=0; k<NoisePeriod; k++) avgDt += work[r-k][_dt]; avgDt /= NoisePeriod;

double noise = CorrectionFactor*MathSqrt(avgDt);

if (noise != 0)

trendQ = work[r][_trend]/noise;

else trendQ = 0;

trendQu = EMPTY_VALUE;

trendQd = EMPTY_VALUE;

if (trendQ>0) trendQu = trendQ;

if (trendQ<0) trendQd = trendQ;

}

return(0);

}

-----------------------------END CODE-----------------------------------------

earmarques

Default "direction" of buffers access (unless you specify set as series to be true) in metatrader 5 is inverted compared to metatrader 4 (close[0] is the first close, not the last (current) close). When you take that into account, it will be much closer to a final solution

earmarques
19
earmarques  

Mladen,

Do you know somebody to convert this indicador? I'll pay for this service

earmarques
19
earmarques  

Mladen,

Can u help me with this indicator?

This is a version of Decision Bar, but when I try to change the parameters they don't stay fixed, don't save. And another problem is when I put the indicator the values and arrows only appears when some bars are calculated, it don't matters if the chart have more than 1000 bars or only 100. Thanks in advance.

db_strategy_v2.mq4

Files:
Mladen Rakic
201568
Mladen Rakic  
earmarques:
Mladen,

Can u help me with this indicator?

This is a version of Decision Bar, but when I try to change the parameters they don't stay fixed, don't save. And another problem is when I put the indicator the values and arrows only appears when some bars are calculated, it don't matters if the chart have more than 1000 bars or only 100. Thanks in advance.

db_strategy_v2.mq4

earmarques

As far as I see al is OK with that code, but that is metatrader 4 code

earmarques
19
earmarques  

Ok, but put hin in 01 minute chart. his lines only apears when 1 new bar is loaded.