My indicator is crashing Metatrader

 

I have no idea why... There is no problem with the functions isLongTermTrend() and isHigherThan(), because I use them in an EA and they work fine there.

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

//| LongTermTrend.mq4 |

//| Tosh |

//| |

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

#property copyright "Tosh"

#property link ""



#property indicator_separate_window



#property indicator_buffers 3

#property indicator_color1 ForestGreen

#property indicator_color2 FireBrick

#property indicator_color3 White

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2



extern int History = 500;



double buf_up[], buf_down[], buf_neutral[];

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, buf_up);

SetIndexBuffer(1, buf_down);

SetIndexBuffer(2, buf_neutral);

SetIndexStyle(0, DRAW_LINE, 0);

SetIndexStyle(1, DRAW_LINE, 0);

SetIndexStyle(2, DRAW_LINE, 0);

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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



datetime last = 0;

int start()

{

if (iTime(NULL, Period(), 1) != last)

last = iTime(NULL, Period(), 1);

else

return(0);

//******** TEMPLATE INDICADOR **********/

int i, counted_bars=IndicatorCounted();

i = Bars - counted_bars - 1;

if (i > History - 1)

i = History - 1;

while ( i >= 0 ) //loop do template

{

if ( isLongTermTrend(Period(), i) == 1 )

buf_up[i] = 1;

else if ( isLongTermTrend(Period(), i) == -1 )

buf_down[i] = 1;

else

buf_neutral[i] = 1;

}

return(0);

}

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



int isLongTermTrend(int timeframe, int s)

{

int tf = timeframe;

if ( isHigherThan((iClose(NULL, tf, s)/iClose(NULL, tf, s+400-1))/400, 0.0025) )

return(1);

else if ( isHigherThan((iClose(NULL, tf, s+400-1)/iClose(NULL, tf, s))/400, 0.0025) )

return(-1);

else

return(0);

}



bool isHigherThan(double value1, double value2)

{

if (NormalizeDouble(value1-value2, 5) > 0)

return(true);

else

return(false);

}
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.
    and delete your second, redundant post.
  2. if ( isHigherThan((iClose(NULL, tf, s)/iClose(NULL, tf, s+400-1))/400, 0.0025) )
    Are you sure you have History + 400 bars? The tester only guarantees 100 bars. If you don't, iClose returns zero.
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.
    and delete your second, redundant post.
  2. Are you sure you have History + 400 bars? The tester only guarantees 100 bars. If you don't, iClose returns zero.

Yes I'm sure.
 
Lol i-- was missing...
Reason: