//+-------------------------------------------------------------------+ //| Made/Modified by Alejandro Galindo | //| | //| If this work/modification is helpful to you | //| send me a PayPal donation to ag@elcactus.com | //| any help is apreciated :) | //| Thanks. | //+-------------------------------------------------------------------+ /*[[ Name := Standard Deviation Author := Copyright © 2005 Alejandro Galindo link := http://www.elCactus.com Separate Window := Yes First Color := MediumSeaGreen First Draw Type := Line First Symbol := 217 Use Second Data := No Second Color := Red Second Draw Type := Line Second Symbol := 218 ]]*/ Input: StdDevPeriod(10); Input: BarsCount(500); Var: shift(0); Var: Avg(0), Sum(0), StdDev(0), SumSqr(0), DevSqr(0), TotalDev(0); Var: i(0), bars_(0); SetLoopCount(0); if BarsCount > 0 then { if BarsCount > Bars then {bars_ = Bars;} else {bars_ = BarsCount;} } else {bars_ = Bars;}; If StdDevPeriod<=0 then { SetIndexValue(0, 0); Exit; } // loop from first bar to current bar (with shift=0) For shift=bars_ Downto 0 Begin Avg=iMA(StdDevPeriod,MODE_SMA,shift); SumSqr = 0; i=0; For i=0 To StdDevPeriod-1 Begin SumSqr = SumSqr + (Close[shift+i] - Avg) * (Close[shift+i] - Avg); End; StdDev = Sqrt(SumSqr / StdDevPeriod); SetIndexValue(shift, StdDev); End;