diff --git a/pinescripts/Three_ATR_EMA.pine b/pinescripts/Three_ATR_EMA.pine index 40cda8e..292b482 100644 --- a/pinescripts/Three_ATR_EMA.pine +++ b/pinescripts/Three_ATR_EMA.pine @@ -1,11 +1,9 @@ //@version=5 -strategy(title="3ATR EMA with Targets", shorttitle="3ATR-Target", overlay=true, currency=currency.USD, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1) +strategy(title="3ATR EMA Upper Band TP", shorttitle="3ATR-UpperBand", overlay=true, currency=currency.USD, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1) // Inputs ema_length = input.int(21, "EMA Length") atr_multiplier = input.float(3.0, "ATR Multiplier") -profit_target_1 = input.float(10, "First Profit Target (%)") -profit_target_2 = input.float(20, "Second Profit Target (%)") trail_percent = input.float(2, "Trailing Stop %") // Calculations @@ -14,39 +12,30 @@ atr = ta.atr(ema_length) upper_band = ema + (atr * atr_multiplier) lower_band = ema - (atr * atr_multiplier) -// Entry Condition (bull market requirement removed) +// Entry Condition bullish_entry = (close < ema) and (close[1] <= lower_band[1]) and (close > close[1]) -// Target Prices +// Variables for managing trade logic var float entry_price = na -var float target_1 = na -var float target_2 = na +var float trail_price = na // Declare trail_price var float trail_stop = na -var float trail_price = na var bool trail_active = false if bullish_entry entry_price := close - target_1 := entry_price * 1.10 // 10% profit - target_2 := entry_price * 1.20 // 20% profit trail_active := false + trail_price := na // Reset trail_price on a new entry // Exit Conditions trail_activation = close >= upper_band -profit_target_reached = close >= target_2 - -// Trailing stop logic (activated by upper band touch) trail_active := trail_active or trail_activation -if trail_active and na(trail_price) - trail_price := high -trail_price := math.max(high, nz(trail_price[1], high)) -trail_stop := trail_price * (1 - trail_percent/100) +trail_price := trail_active ? math.max(high, nz(trail_price[1], high)) : na +trail_stop := trail_active ? trail_price * (1 - trail_percent / 100) : na // Exit strategy -strategy.exit("First Profit", "Long", qty_percent=50, limit=target_1) -strategy.exit("Second Exit", "Long", stop=trail_active ? trail_stop : na, limit=target_2) +strategy.exit("Upper Band TP", "Long", limit=upper_band, stop=trail_stop) // Entry Execution if bullish_entry @@ -54,14 +43,9 @@ if bullish_entry // Visuals plot(ema, "EMA", color=color.new(#4A90E2, 0)) -plot(upper_band, "Upper", color=color.orange) -plot(lower_band, "Lower", color=color.green) - -// Plot targets and stops -plot(strategy.position_size > 0 ? target_1 : na, "Target 10%", color=color.gray, style=plot.style_circles) -plot(strategy.position_size > 0 ? target_2 : na, "Target 20%", color=color.gray, style=plot.style_cross) -plot(strategy.position_size > 0 and trail_active ? trail_stop : na, "Trail Stop", color=color.red, style=plot.style_linebr) +plot(upper_band, "Upper Band (TP)", color=color.orange) +plot(lower_band, "Lower Band", color=color.green) // Entry/exit markers plotshape(bullish_entry, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) -plotshape(profit_target_reached, style=shape.xcross, location=location.abovebar, color=color.gray, size=size.small) +plotshape(close >= upper_band, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Take Profit") \ No newline at end of file