Strategy · Pine Script v5 · On the chart

12/26-IT Strategy

by PlusGenie

12/26-IT Strategy is a trend-following trading strategy that calculates 12 and 26 exponential moving averages alongside resistance levels and RSI bounds.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code201
Settings20inputs
LicenceMPL-2.0
Last update2 years ago24 Dec 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

201 lines of Pine Script v5 from src/strategies/strategy_entry_and_close_all/12_26-IT_strategy.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

12_26-IT_strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// 
// Credits: © AbdulRahimShama
//  https://www.tradingview.com/script/00meSQ1R-12-26-IT-strategy/
//@version=5

strategy('12/26-IT strategy',
     overlay=true,
     initial_capital=10000,
     currency=currency.USD,
     default_qty_type = strategy.percent_of_equity,
     default_qty_value=100,
     use_bar_magnifier = true,
     commission_type=strategy.commission.cash_per_contract,
     commission_value=0.005, //Interactive Brokers rate
     process_orders_on_close = true)

// TBOT on TradingBoat
import AlphaCentauri66367/PineTradingbotWebhook/7 as tv


Show_Only_12_26_Crossover_Entry             = input.bool(true, group = "Entry_Exit Criteria")
Show_12_26_Crossover_and_resistance_Entry   = input.bool(true, group = "Entry_Exit Criteria")

Show_MA_StopLoss                            = input.bool(false, group = "Entry_Exit Criteria", tooltip = "update values as per your requirement in MA section")
Show_TSL_StopLoss                           = input.bool(true, group = "Entry_Exit Criteria")
Show_Crossdown_StopLoss                     = input.bool(false, group = "Entry_Exit Criteria")



////////////////////////////////////////////////
////////////////TARGETS INPUT
////////////////////////////////////////////////

////////Target1

TargetPerc1         = input.float(title="Target (%)", minval=0,defval=5, group="Target-1") / 100
TargetPrice1        = strategy.position_avg_price * (1 + TargetPerc1)
Target1_exit_qty    = input.int(50, group="Target-1",tooltip = "% qty to sell when Target1 is reached")



////////Target2

TargetPerc2         = input.float(title="Target (%)", minval=0,defval=10, group="Target-2") / 100
TargetPrice2        = strategy.position_avg_price * (1 + TargetPerc2)
Target2_exit_qty    = input.int(100, group="Target-2",tooltip = "% qty to sell when Target2 is reached")



////////////////////////////////////////////////
////////////////TRAILING STOP LOSS
////////////////////////////////////////////////


TSLsource           = input(low, title="TSL Source", group="Trailing StopLoss")

longTrailPerc       = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=1, group="Trailing StopLoss") * 0.01

TrailStopPrice = 0.0

TrailStopPrice := if strategy.position_size > 0
    sPIVOT_highValue = TSLsource * (1 - longTrailPerc)
    math.max(sPIVOT_highValue, TrailStopPrice[1])
else
    0

TSL                 = close < TrailStopPrice
plot(series=strategy.position_size > 0 and Show_TSL_StopLoss ? TrailStopPrice : na, color=color.new(color.fuchsia, 0), style=plot.style_linebr, linewidth=2, title='Trailing StopLoss')




////////////////////////////////////////////////
////////////////Moving Averages
////////////////////////////////////////////////

SLmaLength          = input.int(21, group="StopLoss MA")
SLmaSource          = close
ma(SLmaSource, length, type) =>
    switch type
        "SMA" => ta.sma(SLmaSource, SLmaLength)
        "EMA" => ta.ema(SLmaSource, SLmaLength)

SLmaType            = input.string("EMA", title="StopLoss MA", options=["SMA", "EMA"], group="StopLoss MA")

SL_MA =             ma(SLmaSource, SLmaLength, SLmaType)
plot(Show_MA_StopLoss ? SL_MA : na, "StopLoss for MA", color=color.rgb(255, 0, 0))


EMA_12              =ta.ema(close, 12)
EMA_26              =ta.ema(close, 26)
EMA_21              =ta.ema(close,21)

plot(EMA_12, title="EMA_12", color=color.rgb(0, 255, 0), offset=0, linewidth=1)
plot(EMA_26, title="EMA_26", color=color.rgb(0, 0, 255), offset=0, linewidth=2)
plot(Show_MA_StopLoss ? SL_MA : na, "StopLoss for MA", color=color.rgb(255, 0, 0))



////////////////////////////////////////////////
////////////////RESISTANCE INPUT and PLOTTING
////////////////////////////////////////////////

CrossOverLookbackCandles    = input.int(10, group= "RESISTANCE")

resistanceSRC               = input(high, group= "RESISTANCE")
resistanceLEFT              = input(10, group= "RESISTANCE")
resistanceRIGHT             = input(10, group= "RESISTANCE")

hih = ta.pivothigh(resistanceSRC, resistanceLEFT, resistanceRIGHT)
top = ta.valuewhen(hih, resistanceSRC[resistanceRIGHT], 0)

res = plot(top, color=top != top[1] ? na : color.new(#00ff00, 50), offset=-resistanceLEFT, linewidth=2, title="Resistance Line")

EMA_12_Low = ta.lowest(EMA_12, CrossOverLookbackCandles)
EMA_26_Low = ta.lowest(EMA_26, CrossOverLookbackCandles)


////////////////////////////////////////////////
////////////////RSI INPUT and PLOTTING
////////////////////////////////////////////////
RSI                 = ta.rsi(close, 14)
RSILowerRange       = input.int(45, tooltip = "RSI value should be ABOVE this value for entry", group = "RSI")
RSIUpperRange       = input.int(70, tooltip = "RSI value should be BELOW this value for entry", group = "RSI")



////////////////////////////////////////////////
////////////////MACD
////////////////////////////////////////////////
fast_length         = 12
slow_length         = 26
MACD_src            = close
signal_length       = 9

fast_ma             = ta.ema(MACD_src, fast_length)
slow_ma             = ta.ema(MACD_src, slow_length)
macd                = fast_ma - slow_ma
signal              = ta.ema(macd, signal_length)
hist                = macd - signal



////////////////////////////////////////////////
////////////////ENTRY CRITERIA
////////////////////////////////////////////////


BUYVALUE        = input(100000, tooltip = "Buy qty displayed on chart will be based on this value")

BASEENTRY       = macd > signal and RSI > RSILowerRange and RSI < RSIUpperRange and close > EMA_21 and close > ta.sma(close, 7)


Entry           = ta.crossover(EMA_12, EMA_26) and BASEENTRY
Entry2          = ta.crossover(close, top) and EMA_12_Low < EMA_26_Low and EMA_12 > EMA_26 and RSI < 80

var float n_qty = 0.0
// TBOT: parameterfs for makeWebhookJson()
n_qty1 = 0.0
n_qty2 = 0.0
webhookKey = "WebhookReceived:8c43d5"
clientId=1
orderRef='12-26-IT'
////////////////////////////////////////////////
////////////////BUY SELL STRATEGY
////////////////////////////////////////////////

if ((Entry and Show_Only_12_26_Crossover_Entry))
    n_qty := math.floor(BUYVALUE/close )
    n_qty1 := math.floor(n_qty * Target1_exit_qty / 100)
    n_qty2 := n_qty - n_qty1
    // TBOT: Send two bracket orders to have two exit prices
    msg1 = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.entrylong', n_qty1, exitLimit=TargetPrice1, clientId=clientId)
    strategy.entry("buy", strategy.long, qty=BUYVALUE/close, alert_message=msg1)
    msg2 = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.entrylong', n_qty2, exitLimit=TargetPrice2, clientId=clientId)
    alert(msg2)

if (Entry2 and Show_12_26_Crossover_and_resistance_Entry)
    n_qty := math.floor(BUYVALUE/close )
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.entrylong', n_qty, clientId=clientId)
    strategy.entry("buy", strategy.long, qty=BUYVALUE/close, alert_message=msg)

strategy.exit("Tg1", "buy", limit=TargetPrice1, qty_percent = Target1_exit_qty)
strategy.exit("Tg2", "buy", limit=TargetPrice2, qty_percent = Target2_exit_qty)


if TSL and Show_TSL_StopLoss and close < EMA_12 
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.close_all', clientId=clientId)
    strategy.close_all ("sl", alert_message=msg)

if ta.crossunder(EMA_12, EMA_26) and Show_Crossdown_StopLoss
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.close_all', clientId=clientId)
    strategy.close_all ("sl", alert_message=msg)

if ta.crossunder(close, SL_MA) and Show_MA_StopLoss
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.close_all', clientId=clientId)
    strategy.close_all ("sl", alert_message=msg)


bgcolor(color=((Entry and Show_Only_12_26_Crossover_Entry)) ? color.new(color.blue, 0) : na)

Overview

12/26-IT Strategy triggers long entries upon EMA crossovers, optionally filtered by resistance pivots and RSI ranges. The strategy executes partial exits across two configurable percentage targets and manages risk with a percentage-based trailing stop loss or a moving average line. All lines are drawn directly on the price chart. Exit conditions trigger on bar closes, which may lead to execution slippage during fast market moves.

Details

Published by

PlusGenie on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

M15-H1, H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

ib-insyncinteractive-brokers-apitradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show_Only_12_26_Crossover_EntrybooltrueShow_Only_12_26_Crossover_Entry
Show_12_26_Crossover_and_resistance_EntrybooltrueShow_12_26_Crossover_and_resistance_Entry
Show_MA_StopLossboolfalseShow_MA_StopLoss
Show_TSL_StopLossbooltrueShow_TSL_StopLoss
Show_Crossdown_StopLossboolfalseShow_Crossdown_StopLoss
Target (%)float5TargetPerc1
Target1_exit_qtyint50Target1_exit_qty
Target (%)float10TargetPerc2
Target2_exit_qtyint100Target2_exit_qty
TSL SourcesourcelowTSLsource
Trail Long Loss (%)float1longTrailPerc
SLmaLengthint21SLmaLength
Show all 20 settings
SettingTypeDefaultVariable
StopLoss MAstringEMASLmaType
CrossOverLookbackCandlesint10CrossOverLookbackCandles
resistanceSRCsourcehighresistanceSRC
resistanceLEFTint10resistanceLEFT
resistanceRIGHTint10resistanceRIGHT
RSILowerRangeint45RSILowerRange
RSIUpperRangeint70RSIUpperRange
BUYVALUEint100000BUYVALUE
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ADA4H Optuna Strategy

by skywalker0803r
42 stars

This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy

Edge 59

by subos2008
6 stars

Edge 59 is a price-chart strategy that combines an ADX directional filter, a weighted moving average, and a trend-follower channel. The channel uses an exponential moving average of close, optionally smoothed by linear regression, and a percentage of a fixed 2

Strategy v5 TrendOscillators & momentum Repaints
Updated 2 years ago · Custom licence GitHub repository of Edge 59

AG Momentum Breakout

by eltonaguiar
4 stars

AG Momentum Breakout is a strategy that identifies continuation signals after pullbacks in trending markets. It filters for uptrends using EMAs and detects recent pullbacks via RSI conditions before entering on RSI crossovers above 50 with ADX confirmation. Th

Strategy v6 TrendOscillators & momentum
Updated 2 days ago · None stated GitHub repository of AG Momentum Breakout
4 stars

Christian Qullamaggie Strategy is a trend-following and breakout strategy overlay designed to identify high-momentum trading opportunities directly on the price chart. It evaluates market conditions using fast, mid, and slow EMAs, average true range (ATR), and

Strategy v6 BreakoutTrend
Updated 7 months ago · None stated GitHub repository of Christian Qullamaggie Strategy

RSI-7 Breakout

by aofwittawat
4 stars

This strategy identifies breakout trades using a 7-period RSI combined with price extreme lookbacks. A long entry triggers when the RSI rises above 70 and price reaches a new lookback high, provided price remains above an optional EMA trend filter and passes a

Strategy v5 Oscillators & momentumBreakout
Updated 4 years ago · None stated GitHub repository of RSI-7 Breakout

RSI EMA Breakout

by latentwill
4 stars

This strategy trades momentum breakouts by combining an Exponential Moving Average with the Relative Strength Index. It enters a long position when the closing price is above the EMA and the RSI crosses above the breakout threshold. It enters a short position

Strategy v5 TrendOscillators & momentum
Updated 8 days ago · None stated GitHub repository of RSI EMA Breakout

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers