Killzone Strategy - PINE
Killzone Strategy - PINE
// Color Inputs
group_title_color_inputs = "Color Settings"
longEntryColor = input.color(color.green, title='Long Entry Signal',
group=group_title_color_inputs)
shortEntryColor = input.color(color.red, title='Short Entry Signal',
group=group_title_color_inputs)
slLabelColor = input.color(color.red, title='Stop Loss Label',
group=group_title_color_inputs)
tpLabelColor = input.color(color.green, title='Take Profit Label',
group=group_title_color_inputs)
buyEntryLineColor = input.color(color.blue, title='Buy Entry Line',
group=group_title_color_inputs)
sellEntryLineColor = input.color(color.red, title='Sell Entry Line',
group=group_title_color_inputs)
// ATR Input
lengthATR = input.int(14, title="ATR Period", group="ATR Settings")
atrSLFactor = input.float(1.5, title="ATR SL Factor", group="ATR Settings",
step=0.1)
// Calculate ATR
atrValue = ta.atr(lengthATR)
if not shortTradeEntered and time >= startTime and time < endTime
if low < nyOpenLow
nyOpenLow := low
shortEntryTriggered := true
stopLossPriceShort := stopLossReferenceInput == 'Last Swing' ? high :
close[1]
entryPriceShort := nyOpenLow - atrStopLoss // Adjusted for ATR-based SL
// Entry conditions
longCondition = longEntryTriggered and not longTradeEntered
shortCondition = shortEntryTriggered and not shortTradeEntered
if shortCondition
shortTradeEntered := true
entryPriceShort := nyOpenLow
label.new(x=bar_index + 10, y=entryPriceShort, text='Sell',
color=shortEntryColor, style=label.style_label_right, size=size.tiny,
textcolor=color.white)
// Draw the entry line
line.new(x1=bar_index, y1=entryPriceShort, x2=bar_index + 10,
y2=entryPriceShort, color=sellEntryLineColor, width=2)
if shortCondition
stopLossLevelShort := stopLossPriceShort
takeProfitLevelShort := entryPriceShort - (stopLossPriceShort -
entryPriceShort) * riskRewardRatio
label.new(x=bar_index, y=stopLossLevelShort, text='SL', color=slLabelColor,
style=label.style_label_down, size=size.tiny, textcolor=color.white)
label.new(x=bar_index, y=takeProfitLevelShort, text='TP', color=tpLabelColor,
style=label.style_label_up, size=size.tiny, textcolor=color.white)
// Alerts
alertcondition(longCondition, title='Long Entry Alert', message='Long Entry Signal
Triggered')
alertcondition(shortCondition, title='Short Entry Alert', message='Short Entry
Signal Triggered')
alertcondition(close >= takeProfitLevelLong and not na(takeProfitLevelLong),
title='Long Take Profit Hit', message='Long Take Profit Level Hit')
alertcondition(close <= takeProfitLevelShort and not na(takeProfitLevelShort),
title='Short Take Profit Hit', message='Short Take Profit Level Hit')
alertcondition(close <= stopLossLevelLong and not na(stopLossLevelLong),
title='Long Stop Loss Hit', message='Long Stop Loss Level Hit')
alertcondition(close >= stopLossLevelShort and not na(stopLossLevelShort),
title='Short Stop Loss Hit', message='Short Stop Loss Level Hit')