Trend Signal Indicator Question

 
I'm using this Trend Signal indicator and it fails to keep the trend up and treand down arrows on the chart current. When indicator is reset by either reloading, opeing propeties and clicking OK or changing chart timeframe and back again, it redraws the latest arrow with new data. But it doesn't do this automatically.

Can someone please review code below and advise if this indicator code can be altered to keep chart arrows current.

Thanks in advance,

Wackena

//+------------------------------------------------------------------+
//|                                           SHI_SilverTrendSig.mq4 |
//|          Copyright © 2003, VIAC.RU, OlegVS, GOODMAN, 2005 Shurka |
//|                                                 shforex@narod.ru |
//|                                                                  |
//|                                                                  |
//| Ïèøó ïðîãðàììû íà çàêàç                                          |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Shurka"
#property link      "http://shforex.narod.ru"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue


//---- Âõîäíûå ïàðàìåòðû
extern int     AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int     Otstup=30;//Îòñòóï.
extern double  Per=9;//Ïåðèîä.
int            SH,NB,i,UD;
double         R,SHMax,SHMin;
double         BufD[];
double         BufU[];
#define  SH_BUY   1
#define  SH_SELL  -1
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè                                            |
//+------------------------------------------------------------------+
int init()
{
   // NB çàïèñûâàåì êîëè÷åñòâî áàðîâ äëÿ êîòîðûõ ñ÷èòàåì èíäèêàòîð
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   IndicatorBuffers(2);
   IndicatorShortName("SHI_SilverTrendSig");
   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);
   SetIndexBuffer(0,BufU);
   SetIndexBuffer(1,BufD);
   SetIndexDrawBegin(0,Bars-NB);//&#200;&#237;&#228;&#232;&#234;&#224;&#242;&#238;&#240; &#225;&#243;&#228;&#229;&#242;&#238;&#242;&#238;&#225;&#240;&#224;&#230;&#224;&#242;&#252;&#241;&#255; &#242;&#238;&#235;&#252;&#234;&#238; &#228;&#235;&#255; NB &#225;&#224;&#240;&#238;&#226;
   SetIndexDrawBegin(1,Bars-NB);
   ArrayInitialize(BufD,0.0);//&#199;&#224;&#225;&#252;&#184;&#236; &#238;&#225;&#224; &#225;&#243;&#244;&#229;&#240;&#224; &#237;&#238;&#235;&#232;&#234;&#224;&#236;&#232;. &#200;&#237;&#224;&#247;&#229; &#225;&#243;&#228;&#229;&#242; &#236;&#243;&#241;&#238;&#240; &#239;&#240;&#232; &#241;&#236;&#229;&#237;&#229; &#242;&#224;&#233;&#236;&#244;&#240;&#229;&#233;&#236;&#224;.
   ArrayInitialize(BufU,0.0);
   return(0);
}
//+------------------------------------------------------------------+
//| &#212;&#243;&#237;&#234;&#246;&#232;&#255; &#228;&#229;&#232;&#237;&#232;&#246;&#232;&#224;&#235;&#232;&#231;&#224;&#246;&#232;&#232;                                          |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
//+------------------------------------------------------------------+
//| &#209;&#238;&#225;&#241;&#237;&#224; &#232;&#237;&#228;&#232;&#234;&#224;&#242;&#238;&#240;                                                 |
//+------------------------------------------------------------------+
int start()
{
   int CB=IndicatorCounted();
   /* &#210;&#243;&#242; &#226;&#238;&#242; &#242;&#224; &#241;&#224;&#236;&#224;&#255; &#238;&#239;&#242;&#232;&#236;&#232;&#231;&#224;&#246;&#232;&#238;&#237;&#237;&#224;&#255; &#244;&#232;&#248;&#234;&#224;. &#194; &#255;&#231;&#251;&#234; &#226;&#226;&#229;&#228;&#229;&#237;&#224; &#244;&#243;&#237;&#234;&#246;&#232;&#255;, &#234;&#238;&#242;&#238;&#240;&#224;&#255; &#226;&#238;&#231;&#226;&#240;&#224;&#249;&#224;&#229;&#242; &#234;&#238;&#235;&#232;&#247;&#229;&#241;&#242;&#226;&#238;
   &#239;&#238;&#241;&#247;&#232;&#242;&#224;&#237;&#237;&#251;&#245; &#225;&#224;&#240;&#238;&#226;, &#239;&#240;&#232;&#247;&#184;&#236; &#238;&#247;&#229;&#237;&#252; &#245;&#232;&#242;&#240;&#238;. &#207;&#240;&#232; &#239;&#229;&#240;&#226;&#238;&#236; &#226;&#251;&#231;&#238;&#226;&#229; &#232;&#237;&#228;&#232;&#234;&#224;&#242;&#238;&#240;&#224; &#253;&#242;&#238; 0, &#226;&#241;&#184; &#239;&#238;&#237;&#255;&#242;&#237;&#238;, &#229;&#249;&#184; &#237;&#232;&#247;&#229;&#227;&#238;
   &#237;&#229; &#241;&#247;&#232;&#242;&#224;&#235;&#238;&#241;&#252;, &#224; &#231;&#224;&#242;&#229;&#236; &#226;&#251;&#228;&#224;&#184;&#242; &#234;&#238;&#235;&#232;&#247;&#229;&#241;&#242;&#226;&#238; &#238;&#225;&#241;&#247;&#232;&#242;&#224;&#237;&#237;&#251;&#245; &#225;&#224;&#240;&#238;&#226; &#236;&#232;&#237;&#243;&#241; &#238;&#228;&#232;&#237;. &#210;.&#229;. &#229;&#241;&#235;&#232; &#226;&#241;&#229;&#227;&#238; &#225;&#224;&#240;&#238;&#226; 100,
   &#242;&#238; &#244;&#243;&#237;&#234;&#246;&#232;&#255; &#226;&#229;&#240;&#237;&#184;&#242; 99. &#223; &#226;&#226;&#184;&#235; &#242;&#224;&#234;&#238;&#233; &#234;&#238;&#228;, &#226;&#251;&#248;&#229; &#243; &#236;&#229;&#237;&#255; &#238;&#239;&#240;&#229;&#228;&#229;&#235;&#255;&#235;&#224;&#241;&#252; NB - &#234;&#238;&#235;-&#226;&#238; &#225;&#224;&#240;&#238;&#226; &#239;&#238;&#228;&#235;&#229;&#230;&#224;&#249;&#232;&#245;
   &#238;&#225;&#241;&#247;&#184;&#242;&#243;. &#194; &#239;&#240;&#232;&#237;&#246;&#232;&#239;&#229; &#253;&#242;&#238;&#242; &#239;&#224;&#240;&#224;&#236;&#229;&#242;&#240; &#236;&#238;&#230;&#237;&#238; &#232; &#226;&#251;&#234;&#232;&#237;&#243;&#242;&#252;, &#238;&#228;&#237;&#224;&#234;&#238; &#228;&#235;&#255; &#242;&#229;&#245; &#234;&#242;&#238; &#226; &#242;&#224;&#237;&#234;&#229; (I80286) &#236;&#238;&#230;&#237;&#238;
   &#232; &#238;&#241;&#242;&#224;&#226;&#232;&#242;&#252;. &#210;&#224;&#234; &#226;&#238;&#242;, &#231;&#228;&#229;&#241;&#252;, &#239;&#240;&#232; &#239;&#229;&#240;&#226;&#238;&#236; &#226;&#251;&#231;&#238;&#226;&#229; NB &#238;&#241;&#242;&#224;&#184;&#242;&#241;&#255; &#239;&#240;&#229;&#230;&#237;&#229;&#233;, &#224; &#239;&#240;&#232; &#239;&#238;&#241;&#235;&#229;&#228;&#243;&#254;&#249;&#232;&#245; &#243;&#236;&#229;&#237;&#252;&#248;&#224;&#229;&#242;&#241;&#255;
   &#228;&#238; &#239;&#238;&#241;&#235;&#229;&#228;&#237;&#229;&#227;&#238; &#225;&#224;&#240;&#224;, &#242;.&#229;. 1 &#232;&#235;&#232; 2, &#237;&#243; &#232;&#235;&#232; &#241;&#234;&#238;&#235;&#252;&#234;&#238; &#242;&#224;&#236; &#238;&#241;&#242;&#224;&#235;&#238;&#241;&#252; &#239;&#238;&#241;&#247;&#232;&#242;&#224;&#242;&#252;*/
   if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;
   for (SH=1;SH<NB;SH++)//&#207;&#240;&#238;&#247;&#184;&#241;&#251;&#226;&#224;&#229;&#236; &#227;&#240;&#224;&#244;&#232;&#234; &#238;&#242; 1 &#228;&#238; NB
   {
      for (R=0,i=SH;i<SH+10;i++) {R+=(10+SH-i)*(High[i]-Low[i]);}      R/=55;

      SHMax = High[Highest(NULL,0,MODE_HIGH,Per,SH)];
      SHMin = Low[Lowest(NULL,0,MODE_LOW,Per,SH)];
      if (Close[SH]<SHMin+(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufU[SH]=Low[SH]-R*0.5; UD=SH_BUY; }
      if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_SELL) { BufD[SH]=High[SH]+R*0.5; UD=SH_SELL; }
   }
   return(0);
}



 
Try to ask your question on https://www.mql5.com/forum/en