Goodmnorning to everyone,
I need a help about an indicator I’m trying to build.I’d like to code two EMAs that are the closest possibile to the lows and the highs of X candles before (that don’t overlap the price), and a middle line between this two. How can I do?
thank’s in advance
Alessio
JSParticipant
Senior
Hi,
Something like this…
x=20 // Period = x-Candles
EMAHigh=ExponentialAverage[x](High)
EMALow=ExponentialAverage[x](Low)
EMAMiddle=(EMAHigh + EMALow)/2
Return EMAHigh as "EMAHigh" coloured("Green"), EMALow as "EMALow" coloured("Red"), EMAMiddle as "EMAMiddle" coloured("Blue")
A little tip… try using open and close instead of high and low. 😉
Hi JS, thank you for your answer. I’m looking for a different approach. I’d like to consider the argument of the EMA as something to calculate, for example, every 5 or 10 bars, not an input at the beginning. The goal is to stay closer possible to the lows (or highs, it depends on the case) of X bars, without crossing the price ( keeping the lowest distance between EMA and Price, the leastest possible). my idea is , on a high number of bars it’ll stay close to the swing lows (for example 500 bars), on short number of candles it’ll stay close to the lows. Hope to be clear
Alessio
JSParticipant
Senior
Hi,
You could try something with the EMA plus the standard deviation…
SCH=ExponentialAverage[10](High)+Std[10](High)
SCL=ExponentialAverage[10](Low)+Std[10](Low)
Return SCH as "Stay Close High" coloured("Green")Style(DottedLine,3), SCL as "Stay Close Low" coloured("Red")Style(DottedLine,3)
JSParticipant
Senior
I meant, of course:
SCL=ExponentialAverage[10](Low) – Std[10](Low)
(not +)
JSParticipant
Senior
You can turn this into a “CounterTrend” trading system…
DefParam CumulateOrders=False
SCH=ExponentialAverage[PeriodHigh](High)+Std[PeriodHigh](High)
SCL=ExponentialAverage[PeriodLow](Low)-Std[PeriodLow](Low)
If High > SCH then
SellShort 1 contract at Market
EndIf
If Low < SCL then
Buy 1 contract at Market
EndIf