Coding help - page 248

 

Hello, friends. It is great indicator Dynamic_Momentum_Index for Thinkorswim. It is possible to rewrite it for metatrader 4?. Or maybe someone has such indicatorfor MT4?

declare lower;input price = close;input stdevLength = 5;input avgOfStdevLength = 10;input DYMILength = 30;input DYMILengthLowerLimit = 3;input DYMILengthUpperLimit = 30;assert(DYMILengthLowerLimit > 0, "'dymi length lower limit' must be positive: " + DYMILengthLowerLimit);assert(DYMILength between DYMILengthLowerLimit and DYMILengthUpperLimit, "'dymi length' must be between lower and upper limit: " + DYMILength);def std = stdev(price, stdevLength);def ratio = std / Average(std, avgOfStdevLength);def dynamicLength = Floor(DYMILength / ratio);def limitedLength = if dynamicLength between DYMILengthLowerLimit and DYMILengthUpperLimit then dynamicLength else 0;def sf = 2 / (limitedLength + 1);def bn = Max(barNumber(), 0);# 10^-5 precision for ema multiplierdef expIndex = if limitedLength == 0 then 1 else max(1, bn - ceil(-5 / lg(1 - sf)));def fromIndex = if isNan(expIndex) then 1 else expIndex;def chg = price - price[1];def absChg = AbsValue(chg);def netChgAvg = fold indexN = fromIndex to bn + 1 with accuN do sf * (if isnan(getValue(chg, bn - indexN)) then 0 else getValue(chg, bn - indexN)) + (1 - sf) * accuN;def totChgAvg = fold indexT = fromIndex to bn + 1 with accuT do sf * (if isnan(getValue(absChg, bn - indexT)) then 0 else getValue(absChg, bn - indexT)) + (1 - sf) * accuT;def RSI = if totChgAvg != 0 and limitedLength != 0 then 50 * (netChgAvg / totChgAvg + 1) else RSI[1];plot DYMI = RSI;plot OverBought = 90;plot OverSold = 10;DYMI.DefineColor("OverBought", GetColor(5));DYMI.DefineColor("Normal", GetColor(7));DYMI.DefineColor("OverSold", GetColor(1));DYMI.AssignValueColor(if RSI > overbought then DYMI.Color("OverBought") else if RSI =OverBought, "OverBought", Alert.BAR, Sound.ring);Alert (DYMI=OverBought then high*72 else double.nan;DotDn.setStyle(curve.POINTS);DotDn.setPaintingStrategy(paintingStrategy.arROW_DOWN);DotDn.setLineWeight(3);DotDn.setDefaultColor(color.wHITE);plot DotUp = if DYMI<=OverSold then low*-2 else double.nan;Dotup.setStyle(curve.POINTS);Dotup.setPaintingStrategy(paintingStrategy.arROW_UP);Dotup.setLineWeight(3);Dotup.setDefaultColor(color.wHITE);alert(Dotup, "Scalper Buy Signal", Alert.BAR, Sound.ring);alert(DotDn, "Scalper Buy Signal", Alert.BAR, Sound.ring);

Files:
image_4.jpg  392 kb
 
olvus:
Hello, friends. It is great indicator Dynamic_Momentum_Index for Thinkorswim. It is possible to rewrite it for metatrader 4?. Or maybe someone has such indicatorfor MT4?

declare lower;input price = close;input stdevLength = 5;input avgOfStdevLength = 10;input DYMILength = 30;input DYMILengthLowerLimit = 3;input DYMILengthUpperLimit = 30;assert(DYMILengthLowerLimit > 0, "'dymi length lower limit' must be positive: " + DYMILengthLowerLimit);assert(DYMILength between DYMILengthLowerLimit and DYMILengthUpperLimit, "'dymi length' must be between lower and upper limit: " + DYMILength);def std = stdev(price, stdevLength);def ratio = std / Average(std, avgOfStdevLength);def dynamicLength = Floor(DYMILength / ratio);def limitedLength = if dynamicLength between DYMILengthLowerLimit and DYMILengthUpperLimit then dynamicLength else 0;def sf = 2 / (limitedLength + 1);def bn = Max(barNumber(), 0);# 10^-5 precision for ema multiplierdef expIndex = if limitedLength == 0 then 1 else max(1, bn - ceil(-5 / lg(1 - sf)));def fromIndex = if isNan(expIndex) then 1 else expIndex;def chg = price - price[1];def absChg = AbsValue(chg);def netChgAvg = fold indexN = fromIndex to bn + 1 with accuN do sf * (if isnan(getValue(chg, bn - indexN)) then 0 else getValue(chg, bn - indexN)) + (1 - sf) * accuN;def totChgAvg = fold indexT = fromIndex to bn + 1 with accuT do sf * (if isnan(getValue(absChg, bn - indexT)) then 0 else getValue(absChg, bn - indexT)) + (1 - sf) * accuT;def RSI = if totChgAvg != 0 and limitedLength != 0 then 50 * (netChgAvg / totChgAvg + 1) else RSI[1];plot DYMI = RSI;plot OverBought = 90;plot OverSold = 10;DYMI.DefineColor("OverBought", GetColor(5));DYMI.DefineColor("Normal", GetColor(7));DYMI.DefineColor("OverSold", GetColor(1));DYMI.AssignValueColor(if RSI > overbought then DYMI.Color("OverBought") else if RSI =OverBought, "OverBought", Alert.BAR, Sound.ring);Alert (DYMI=OverBought then high*72 else double.nan;DotDn.setStyle(curve.POINTS);DotDn.setPaintingStrategy(paintingStrategy.arROW_DOWN);DotDn.setLineWeight(3);DotDn.setDefaultColor(color.wHITE);plot DotUp = if DYMI<=OverSold then low*-2 else double.nan;Dotup.setStyle(curve.POINTS);Dotup.setPaintingStrategy(paintingStrategy.arROW_UP);Dotup.setLineWeight(3);Dotup.setDefaultColor(color.wHITE);alert(Dotup, "Scalper Buy Signal", Alert.BAR, Sound.ring);alert(DotDn, "Scalper Buy Signal", Alert.BAR, Sound.ring);

olvus,

See this post : https://www.mql5.com/en/forum/172919/page4 . Maybe that helps

 

Hi mladen, I would like to ask you this favour.... have you the possibility to translate this program for MT4?

Thank you anyway..

THIS IS THE PROGRAM IN OTHER LANGUAGE:// var: domanda(0), offerta(0), var1(0), var2(0), indzona1;

// var1= ((H/C[1])-1)*V;

// var2= ((L/C[1]-1)*V*(-1);

// domanda= MOV(var1,450,S);

// offerta= MOV(var2,450,S);

// indzona1= CreateWiewport(100);

// PlotChart(domanda, indzona1, green, solid, 1);

// PlotChart(offerta, indzona1, red, solid, 1);THIS IS MY WORK FOR MT4 LANGUAGE, BUT AFTER THE LATEST UPDATE, IT DOESN'T WORK ANYMORE:

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_width1 1

#property indicator_width2 1

extern int periodo=128;

double DOMANDA[];

double OFFERTA[];

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

//| Custom indicator initialization function |

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

int init()

{

IndicatorDigits(6);

IndicatorBuffers(2);

SetIndexBuffer(0,DOMANDA);

SetIndexBuffer(1,OFFERTA);

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

int limit = Bars - counted_bars;

double var_dom[10000];

double var_off[10000];

ArraySetAsSeries(var_dom,true);

ArraySetAsSeries(var_off,true);

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

{

var_dom = ((High/Close)-1)*Volume;

var_off = ((Low/Close)-1)*Volume * (-1);

DOMANDA = iMAOnArray(var_dom,0,periodo,0,MODE_SMA,i);

OFFERTA = iMAOnArray(var_off,0,periodo,0,MODE_SMA,i);

}

return(0);

}//+------------------------------------------------------------------+

 
Stephan73:
Hi mladen, I would like to ask you this favour.... have you the possibility to translate this program for MT4?

Thank you anyway..

THIS IS THE PROGRAM IN OTHER LANGUAGE:// var: domanda(0), offerta(0), var1(0), var2(0), indzona1;

// var1= ((H/C[1])-1)*V;

// var2= ((L/C[1]-1)*V*(-1);

// domanda= MOV(var1,450,S);

// offerta= MOV(var2,450,S);

// indzona1= CreateWiewport(100);

// PlotChart(domanda, indzona1, green, solid, 1);

// PlotChart(offerta, indzona1, red, solid, 1);THIS IS MY WORK FOR MT4 LANGUAGE, BUT AFTER THE LATEST UPDATE, IT DOESN'T WORK ANYMORE:

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_width1 1

#property indicator_width2 1

extern int periodo=128;

double DOMANDA[];

double OFFERTA[];

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

//| Custom indicator initialization function |

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

int init()

{

IndicatorDigits(6);

IndicatorBuffers(2);

SetIndexBuffer(0,DOMANDA);

SetIndexBuffer(1,OFFERTA);

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

int limit = Bars - counted_bars;

double var_dom[10000];

double var_off[10000];

ArraySetAsSeries(var_dom,true);

ArraySetAsSeries(var_off,true);

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

{

var_dom = ((High/Close)-1)*Volume;

var_off = ((Low/Close)-1)*Volume * (-1);

DOMANDA = iMAOnArray(var_dom,0,periodo,0,MODE_SMA,i);

OFFERTA = iMAOnArray(var_off,0,periodo,0,MODE_SMA,i);

}

return(0);

}//+------------------------------------------------------------------+

Stephan

Here you go :

Files:
_stephan.mq4  2 kb
stephan.gif  61 kb
 
mladen:
Stephan Here you go :

Yeesss, perfect !!!!

Thank you so much!!!

 

mr. mladen, it is possible to rewrite thinkorswim indicator to metatrader 4 indicator (post 2474)?

 

Hi everyone ,

say I have a function that loops through all market order and select the last one using lastTicket(). then I use ot = orderopentime() . how do I get the value of ot such that I can use the value of ot in any other function of the program. i don't want to call checko() from inside loop through all function eg

void checko()

{

if (ot>presetdatetime)

{

closeorder();

}

}

 
hermes:
Hi everyone ,

say I have a function that loops through all market order and select the last one using lastTicket(). then I use ot = orderopentime() . how do I get the value of ot such that I can use the value of ot in any other function of the program. i don't want to call checko() from inside loop through all function eg

void checko()

{

if (ot>presetdatetime)

{

closeorder();

}

}

hermes

A question : by last order ticket do you mean the greatest (which is usually the newest order) or smallest (which is usually the oldest order)?

 
mladen:
hermes A question : by last order ticket do you mean the greatest (which is usually the newest order) or smallest (which is usually the oldest order)?

Thanks Mladen, I mean the greatest which is the newest order.

 
hermes:
Thanks Mladen, I mean the greatest which is the newest order.

then you can use a function like this one :

void deleteGreatestTicketOrder(datetime timeLimit)

{

int largestTicketNo = -1;

for (int i=OrdersTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

largestTicketNo = MathMax(largestTicketNo,OrderTicket());

}

//

//

//

//

//

if (largestTicketNo>-1 )

{

if (OrderSelect(largestTicketNo,SELECT_BY_TICKET,MODE_TRADES))

if (OrderOpenTime()>timeLimit)

OrderDelete(largestTicketNo);

}

}

PS: it does not make a difference among symbols or eventual magic numbers. If you need those to be checcked too, than some additional code needs to be added to the above function

Reason: