/*[[ Name := RSI MA Author := Copyright © 2003, Fostar Link := fostar_fx@yahoo.com Separate Window := Yes First Color := Lime First Draw Type := Line First Symbol := 217 Use Second Data := Yes Second Color := Red Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs: RsiPeriod(14), Price_C_O_H_L_M_T_W(0), //0..6 /* PRICE_CLOSE - 0 PRICE_OPEN - 1 PRICE_HIGH - 2 PRICE_LOW - 3 PRICE_MEDIAN - 4 PRICE_TYPICAL - 5 PRICE_WEIGHTED - 6 */ MAPeriod(8), MAType_Simp_E_Smo_W(0), //0..3 /* MODE_SMA - 0 MODE_EMA - 2 MODE_SMMA - 2 MODE_WMA - 3 */ MAShift(0), BarsCount(500); Variable : shift(0), value(0), sum(0), n(0), MA(0), bars_(0), smconst(0), prev(0); Variable: weight(0), linear(0); SetLoopCount(0); if BarsCount > 0 then { if BarsCount > Bars then {bars_ = Bars;} else {bars_ = BarsCount;} } else {bars_ = Bars;}; smconst = 2 / (1 + MAPeriod); For shift = bars_-1 Downto 0 Begin value = iRSIEx(RsiPeriod, 1, Price_C_O_H_L_M_T_W, MODE_FIRST, shift); SetIndexValue(shift, value); if (shift < bars_ - (RsiPeriod + MAPeriod + MAShift)) and (MAPeriod > 1) then begin Switch MAType_Simp_E_Smo_W Begin case 0://Simple sum = 0; for n = 0 to MAPeriod -1 begin sum = sum + GetIndexValue(shift + n + MAShift); end; MA = sum/MAPeriod; SetIndexValue2(shift, MA); case 1://Exponential prev = GetIndexValue2(shift + 1 - MAShift); MA = smconst * (value - prev) + prev; SetIndexValue2(shift - MAShift, MA); case 2://Smoothed If shift = bars_ - MAPeriod Then Begin sum = 0; For n = 0 To MAPeriod-1 Begin sum = sum + GetIndexValue(shift+n + MAShift); End; End Else Begin prev = GetIndexValue2(shift + 1); sum = prev*MAPeriod - prev + GetIndexValue(shift + MAShift); End; MA = sum/MAPeriod; SetIndexValue2(shift, MA); case 3: //Linear weighted sum = 0; weight = 0; linear = MAPeriod; For n = 0 To MAPeriod-1 Begin sum = sum + GetIndexValue(shift + n + MAShift) * linear; weight = weight + linear; linear = linear - 1; End; MA = sum/weight; SetIndexValue2(shift, MA); default://Simple sum = 0; for n = 0 to MAPeriod -1 begin sum = sum + GetIndexValue(shift + n + MAShift); end; MA = sum/MAPeriod; SetIndexValue2(shift, MA); end; end; If GetIndexValue2(shift)>65 then { SetArrow(Time[shift],High[shift],159,RED); //MoveObject("vLine"+shift,OBJ_VLINE,Time[shift],50,Time[shift],50,Indigo,1,STYLE_SOLID); } If GetIndexValue2(shift)<35 then { SetArrow(Time[shift],Low[shift],159,LIME); //MoveObject("vLine"+shift,OBJ_VLINE,Time[shift],50,Time[shift],50,Indigo,1,STYLE_SOLID); } End;