Detecting Pip spread
Posted: Sun Apr 02, 2023 12:33 am
I am looking to detect a Pip spread in ema2 and ema3.
//@version=5
indicator('Scalp strategy', overlay=true)
// Get indicator data
ema1 = ta.ema(close, 6)
ema2 = ta.ema(high, 32)
ema3 = ta.ema(low, 32)
// Detect Buy or Sell
buy = ema1 > ema2 and (ema2 - ema3) > 0.004
sell = ema1 < ema3 and (ema2 - ema3) > 0.004
// Eliminate repeated detects
longSignal = buy and not buy[1]
shortSignal = sell and not sell[1]
plotshape(longSignal, title= "Long signal", style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(shortSignal, title= "Short signal", style=shape.triangledown, location=location.abovebar, color=color.red)
plot(ema1, color=color.white, linewidth=2 ,title="EMA 1")
plot(ema2, color=color.green, linewidth=2, title="EMA 2")
plot(ema3, color=color.green, linewidth=2, title="EMA 3")
Basically I am trying to scalp where the ema1 crosses through ema2 and ema3 but I want to ensure there is a spread between ema2 and ema3 which will indicate that there is momentum. If the spread is low then it is likely consolidating. If the spread is good then it is a good opportunity to scalp.
So the 0.004 is the PIPs spread. So far this is not working. Also with the Yen, how do I make this work for that as well?
Any help is appreciated.
Thank you.
//@version=5
indicator('Scalp strategy', overlay=true)
// Get indicator data
ema1 = ta.ema(close, 6)
ema2 = ta.ema(high, 32)
ema3 = ta.ema(low, 32)
// Detect Buy or Sell
buy = ema1 > ema2 and (ema2 - ema3) > 0.004
sell = ema1 < ema3 and (ema2 - ema3) > 0.004
// Eliminate repeated detects
longSignal = buy and not buy[1]
shortSignal = sell and not sell[1]
plotshape(longSignal, title= "Long signal", style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(shortSignal, title= "Short signal", style=shape.triangledown, location=location.abovebar, color=color.red)
plot(ema1, color=color.white, linewidth=2 ,title="EMA 1")
plot(ema2, color=color.green, linewidth=2, title="EMA 2")
plot(ema3, color=color.green, linewidth=2, title="EMA 3")
Basically I am trying to scalp where the ema1 crosses through ema2 and ema3 but I want to ensure there is a spread between ema2 and ema3 which will indicate that there is momentum. If the spread is low then it is likely consolidating. If the spread is good then it is a good opportunity to scalp.
So the 0.004 is the PIPs spread. So far this is not working. Also with the Yen, how do I make this work for that as well?
Any help is appreciated.
Thank you.