PSP [Daye's Theory]

indicator("PSP [Daye's Theory]", overlay=true)
// User input to choose 3 assets
asset1 = input.string("MNQ1!", title="Select Asset 1", options=["MNQ1!", "MES1!", "MYM1!", "ES1!", "NQ1!", "YM1!"])
asset2 = input.string("MES1!", title="Select Asset 2", options=["MNQ1!", "MES1!", "MYM1!", "ES1!", "NQ1!", "YM1!"])
asset3 = input.string("MYM1!", title="Select Asset 3", options=["MNQ1!", "MES1!", "MYM1!", "ES1!", "NQ1!", "YM1!"])
// Automatically select the timeframe from the first asset
asset1_timeframe = timeframe.isintraday ? timeframe.period : "D" // Use the chart's time frame, or fallback to daily for non-intraday
// Checkbox for enabling correlation check between NQ and ES
pairs_check = input.bool(false, title="Check PSP NQ & ES only")
// Declare highlight color globally
highlight_color = input.color(color.red, title="PSP Color")
// Fetch data for all assets (do it outside the conditionals)
asset1_open = request.security(asset1, asset1_timeframe, open)
asset1_close = request.security(asset1, asset1_timeframe, close)
asset2_open = request.security(asset2, asset1_timeframe, open)
asset2_close = request.security(asset2, asset1_timeframe, close)
asset3_open = request.security(asset3, asset1_timeframe, open)
asset3_close = request.security(asset3, asset1_timeframe, close)
// Define the candle color for each asset
asset1_color = asset1_close > asset1_open ? color.green : color.red
asset2_color = asset2_close > asset2_open ? color.green : color.red
asset3_color = asset3_close > asset3_open ? color.green : color.red
// Initialize candle_diff with var to persist its state
var bool candle_diff = false
if (pairs_check)
// Only check correlation between asset1 and asset2
candle_diff := (asset1_color != asset2_color)
else
// Check correlation among all three assets
candle_diff := (asset1_color != asset2_color) or (asset2_color != asset3_color) or (asset1_color != asset3_color)
// Apply the barcolor globally if the condition is met
barcolor(candle_diff ? highlight_color : na)
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.