REM GAP GAIN TEST
//created by @overratedtrader for the Tradingview platform
//translated for platform Prorealtime by bolsatrilera
// Look at the 20 MA to gauge likelihood of stock following its up or down gap.
// - if above the 20 MA, follow the gap direction
// - if below the 20 MA, take counter trend trade
// If stock gaps up AND closes higher than it opens, that gain % (close/open) is colored green and if stock gaps down and closes lower than it opens, that gain % (close/open) is colored green
// Conversely if the stock gaps up BUT closes lower than it opens, red and if a stop gaps down but closes higher than it opens, red.
if open>close[1] then
gapUP= close/open
else
gapUP=1
endif
if open<close[1] then
gapDOWN= close/open
else
gapDOWN=1
endif
gapUPgain = (gapUP -1) * 100 //percent gain for the day
gapDOWNgain = (gapDOWN -1) * 100 //percent lost for the day
totalgain = gapUPgain - gapDOWNgain
if totalgain >0 then
r=0
g=128
b=0
elsif totalgain= 0 then
r=0
g=0
b=0
else
r=255
g=0
b=0
endif
//Arnaud Legoux moving average
// Window = 20
// Sigma = 85
// Offset = 0.6
Price = totalgain
m = (Offset * (Window - 1))
s = Window/Sigma
WtdSum = 0
CumWt = 0
for k = 0 to Window - 1 do
Wtd = Exp(-((k-m)*(k-m))/(2*s*s))
WtdSum = WtdSum + Wtd * Price[Window - 1 - k]
CumWt = CumWt + Wtd
next
alma = WtdSum / CumWt
return totalgain coloured(r,g,b)style(histogram)as "%Gain",alma style(line,2)as "alma"