/*[[ Name := SilverTrend Author := Copyright © 2003, VIAC.RU AlexSilver,OlegVS,GOODMAN Link := http://viac.ru/ Separate Window := No First Color := Red First Draw Type := Symbol First Symbol := 242 Use Second Data := Yes Second Color := Blue Second Draw Type := Symbol Second Symbol := 241 ]]*/ // Trend Start Indicator. RISK-price not less than (33-RISK)% from Silver-channel border with period SSP //CountBars - number of bars Inputs : RISK(1),CountBars(240),SSP(9); Variables : firstTime(True),shift(0), loopbegin(0),Range(0),AvgRange(0),Sell(false),Buy(false); Variables : smin(0), smax(0), SsMax(0), SsMin(0) ,K(0),val1(0),val2(0),i1(0),MyBars(0); SetLoopCount(0); K=50-RISK; If firstTime then// initial settings { loopbegin = CountBars; If loopbegin>(Bars-2*SSP+1) Then loopbegin=Bars-2*SSP+1; firstTime=False; }; For shift = loopbegin DownTo 0 Begin Range=0; AvgRange=0; For i1=shift To shift+9 {AvgRange=AvgRange+Abs(High[i1]-Low[i1]); }; Range=AvgRange/10;//ATR(10) - для уровня стопа SsMax = High[Highest(MODE_HIGH,shift+SSP-1,SSP)]; // Maximum for period SsMin = Low[Lowest(MODE_LOW,shift+SSP-1,SSP)]; // Minimum for period smin = SsMin+(SsMax-SsMin)*K/100; // Upper border channel for current bar smax = SsMax-(SsMax-SsMin)*K/100; // //and h[shift-1]+200*Point>ssmaxand l[shift-1]-200*Pointsmax And (Not buy Or MyBars=Bars) Then {// if 1st bar with BUY signal - make an up arrow val2=Low[shift]-Range*0.5; buy=true; sell=false; MyBars=Bars-shift; }; If val1=0 And val2=0 And MyBars=Bars Then {// in case the signal disappears sell=!sell; buy=!buy; MyBars=MyBars-1; }; SetIndexValue(shift,val1); SetIndexValue2(shift,val2); If shift>0 then loopbegin=loopbegin-1;// counter - ignore recalculation of the whole volume at every tick End;