Is it possible to write an SMA that only operates un candles having a bullish body, while ignoring the other ones?
Yes you can use the “non linear data serie SMA” I introduced in this code: Moving Average of Price Median (and other examples in the New Renko System thread).
Are you reinventing the RSI? 😉
No, I was just wondering what crossings may happen creting two different MAS, one for Bullish candles and one for Bearish ones.
Well, that’s an idea! I think we could it easily with the examples I pointed. I will code it tomorrow.
Sorry Roberto, I forgot to code your project today. Please remind me later! 😉
Nicolas please look at me picture . no more back data BAR !!
Nicolas please look at me picture . no more back data BAR !!
Please stick to the topic! Thank you.
Here is the code of what you are looking for, the moving average of bullish and bearish candlesticks:
priceMAperiod=20
countup=0
countdn=0
sumup=0
sumdn=0
lastup=0
lastdn=0
for i = 0 to barindex do
if close[i]<>lastup and close[i]>open[i] then
lastup=close[i]
countup=countup+1
priceup=lastup
sumup=sumup+priceup
endif
if countup=priceMAperiod then
break
//
endif
next
for i = 0 to barindex do
if close[i]<>lastdn and close[i]<open[i] then
lastdn=close[i]
countdn=countdn+1
pricedn=lastdn
sumdn=sumdn+pricedn
endif
if countdn=priceMAperiod then
break
//
endif
next
if lastup<>lastup[1] then
avgup = sumup/priceMAperiod
endif
if lastdn<>lastdn[1] then
avgdn = sumdn/priceMAperiod
endif
return avgup coloured(0,200,0), avgdn coloured(200,0,0)
Thank you very much Nicolas!