Download MetaTrader 5

Need help about Indicator's codes

To add comments, please log in or register
Fa Cao
1141
Fa Cao  

I want to write an indicator to connect all the peak which meet my requirement (a little like ZigZag, but different for defining the peak); I write the codes as below, but the codes never work well, and I don;t know where something wrong exist.

the logic is very simple, but there must be some error about it, i mean when I attached it to chart, the line will show after a little time, 5 seconds or more, why not like zigzag(show immediately)?

anybody can give me some advice?

thanks.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow


extern int Seek_Period=15,Mini_Swing=8;
double High_Point[],Point_Adapted;
datetime High_Last_Time;             

int init()
{
   IndicatorBuffers(1);
   SetIndexBuffer(0,High_Point);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexEmptyValue(0,0.0);
   
   if(Digits==3||Digits==5) Point_Adapted=Point/0.1;
   else Point_Adapted=Point;
   
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{  
   if(Bars<=Seek_Period) return(0);
   int Counted_Bars=IndicatorCounted();
   if(Counted_Bars==0) Counted_Bars--;
   int Limit=Bars-Counted_Bars;
   for(int i=Limit-1;i>0;i--)
   {
     int P_CNT=Seek_Period,Show_Con=0;
     while(P_CNT>=6)
     {
       int x=iHighest(NULL,0,MODE_HIGH,P_CNT,i); if(x<5) break;
       double High_Refer_0=High[iHighest(NULL,0,MODE_HIGH,10,x-5)],Low_Refer_0=Low[iLowest(NULL,0,MODE_LOW,x,0)];
       if(High_Refer_0==High[x]&&High_Refer_0-Low_Refer_0>=Mini_Swing*Point_Adapted)                              //peak confirm
         if(High_Last_Time!=Time[x]&&Show_Con==0)                                                                 // avoid repeating assignment
           {High_Point[x]=High_Refer_0;High_Last_Time=Time[x];Show_Con=1;}
           
       P_CNT--;        
     }
   }

   return(0);
}
Simon Gniadkowski
Moderator
18023
Simon Gniadkowski  
vx0532:

I want to write an indicator to connect all the peak which meet my requirement (a little like ZigZag, but different for defining the peak); I write the codes as below, but the codes never work well, and I don;t know where something wrong exist.

the logic is very simple, but there must be some error about it, i mean when I attached it to chart, the line will show after a little time, 5 seconds or more, why not like zigzag(show immediately)?

anybody can give me some advice?

thanks.

Comparing doubles like this is prone to problems . . .

       if(High_Refer_0 == High[x] && High_Refer_0-Low_Refer_0 >= Mini_Swing*Point_Adapted)                              //peak confirm
         if(High_Last_Time != Time[x]&& Show_Con == 0)  

. . . read this thread and adjust your code: Can price != price ?

Fa Cao
1141
Fa Cao  
RaptorUK:

Comparing doubles like this is prone to problems . . .

. . . read this thread and adjust your code: Can price != price ?


I know your meaning thanks

Fa Cao
1141
Fa Cao  

the line which is draw by this code will show after a few seconds after it is attached to chart; maybe because there are too many bars, and the computing is so much, so it needs some time?

thanks

To add comments, please log in or register