/*[[ Name := New_NRTR WATR Separate Window := No First Color := Red First Draw Type := Symbol First Symbol := 159 Use Second Data := Yes Second Color := Blue Second Draw Type := Symbol Second Symbol := 159 ]]*/ Input : AveragePeriod(10),Reg(1),AllBars(500); Variable : bar(0),StartBar(0),NumBars(0); Variable : value(0),RetValue(0); Variable : price(0); Variable : trend(0),dK(0), AvgRange(0),i(0),WATR(0); SetLoopCount(0); AvgRange=0; for i=AveragePeriod DownTo 1 { dK = 1+(AveragePeriod-i)/AveragePeriod; AvgRange=AvgRange+ dK*Abs(High[i]-Low[i]); }; WATR = AvgRange/AveragePeriod; If Bars AveragePeriod Then StartBar=Bars-AveragePeriod Else StartBar=AllBars; if Close[StartBar-1] > Open[StartBar-1] then { value = Close[StartBar - 1] * (1 - WATR); trend = 1; SetIndexValue2(StartBar - 1, value); }; if Close[StartBar-1] < Open[StartBar-1] then { value = Close[StartBar - 1] * (1 + WATR); trend = -1; SetIndexValue(StartBar - 1, value); }; for bar = StartBar - 2 downto 0 { if Reg = 2 then { AvgRange=0; for i=1 To AveragePeriod { dK = 1+(AveragePeriod-i)/AveragePeriod; AvgRange=AvgRange+ dK*Abs(High[bar + i]-Low[bar + i]); }; WATR = AvgRange/AveragePeriod; }; if trend >= 0 then { if Close[bar] > price then price = Close[bar]; value = price * (1 - WATR); if Close[bar] < value then { price = Close[bar]; value = price * (1 + WATR); trend = -1; }; } else if trend <= 0 then { if Close[bar] < price then price = Close[bar]; value = price * (1 + WATR); if Close[bar] > value then { price = Close[bar]; value = price * (1 - WATR); trend = 1; }; }; if trend = -1 then SetIndexValue(bar, value); if trend = 1 then SetIndexValue2(bar, value); };