PURPLE WIN is a confluence-based indicator using fast & slow moving average crossover with fractal confirmation to highlight high-probability buy (call) and sell (put) signals on the chart.
Here is the Script Code :
Python:
instrument {
name = 'PURPLE WIN',
icon = "indicators:ADX",
overlay = true
}
-- Inputs de perodos
MaFast_period = input(1,"Ma Fast period",input.integer,1,1000,1)
MaSlow_period = input(34,"Ma Slow period",input.integer,1,1000,1)
Signal_period = input(5,"Signal period",input.integer,1,1000,1)
-- Cores para sinais de compra e venda
colorBuy = input { default = "white", type = input.color } -- Bola branca para compra (call)
colorSell = input { default = "red", type = input.color } -- Bola vermelha para venda (put)
-- Mdias Mveis
smaFast = sma(close, MaFast_period) -- Mdia mvel rpida baseada no fechamento
smaSlow = sma(close, MaSlow_period) -- Mdia mvel lenta baseada no fechamento
buffer1 = smaFast - smaSlow -- Diferena entre as mdias
buffer2 = wma(buffer1, Signal_period) -- Mdia ponderada da diferena
-- Funo para calcular fractal de alta e baixa (perodo 3)
local function fractalHigh(period)
return high[2] > high[1] and high[2] > high[3] and high[2] > high[period+1]
end
local function fractalLow(period)
return low[2] < low[1] and low[2] < low[3] and low[2] < low[period+1]
end
-- Verificando fractal de perodo 3
fractalHigh3 = fractalHigh(3)
fractalLow3 = fractalLow(3)
-- Condies de compra (Acima Agora) e venda (Abaixo Agora) com confluncia de fractal
buyCondition = (buffer1 > buffer2 and buffer1[1] < buffer2[1]) and fractalLow3
sellCondition = (buffer1 < buffer2 and buffer1[1] > buffer2[1]) and fractalHigh3
-- Plotagem dos sinais de confluncia
if buyCondition then
plot_shape(true, "Compra", shape_style.circle, shape_size.large, colorBuy, shape_location.belowbar, 0, "Compra", "white")
end
if sellCondition then
plot_shape(true, "Venda", shape_style.circle, shape_size.large, colorSell, shape_location.abovebar, 0, "Venda", "red")
end