0% found this document useful (0 votes)
440 views5 pages

Pinnacle Momentum Algo

The document outlines a trading strategy script called 'Pinnacle Momentum Algo' designed for educational purposes, incorporating various indicators like Adaptive Moving Average, Stiffness Indicator, and Chaikin Money Flow. It includes features for trade mode selection, entry and exit conditions, and a performance summary dashboard. The script emphasizes the importance of consulting a financial advisor and includes disclaimers about trading risks.

Uploaded by

movie.expo-0s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
440 views5 pages

Pinnacle Momentum Algo

The document outlines a trading strategy script called 'Pinnacle Momentum Algo' designed for educational purposes, incorporating various indicators like Adaptive Moving Average, Stiffness Indicator, and Chaikin Money Flow. It includes features for trade mode selection, entry and exit conditions, and a performance summary dashboard. The script emphasizes the importance of consulting a financial advisor and includes disclaimers about trading risks.

Uploaded by

movie.expo-0s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

//@version=5

strategy("Pinnacle Momentum Algo", overlay=true, initial_capital=1000,


default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.05, slippage=1)

// === DISCLAIMER ===


// This script is for educational purposes only and does not constitute financial
advice.
// Trading involves significant risk, and you should consult with a qualified
financial advisor before making any trading decisions.
// The author assumes no responsibility for any financial losses or damages
resulting from the use of this script.
// Past performance does not guarantee future results.

// === Date Filter === //


start_date = input.time(title="Start Date", defval=timestamp("2023-01-01
00:00:00"))
end_date = input.time(title="End Date", defval=timestamp("2029-12-31 23:59:59"))
in_date_range = (time >= start_date and time <= end_date)

// === Trade Mode Selection === //


tradeMode = input.string("Both", title="Trade Mode", options=["Both", "Long Only",
"Short Only"])

// === AMA (Adaptive Moving Average) Settings === //


amaFastLength = input.int(40, title="AMA Fast EMA Length")
amaSlowLength = input.int(55, title="AMA Slow EMA Length")
n = input.int(60, title="ER Period")

change = math.abs(close - close[n])


volatility = math.sum(math.abs(close - close[1]), n)
ER = change / volatility
fastest = 2 / (amaFastLength + 1)
slowest = 2 / (amaSlowLength + 1)
sc = math.pow(ER * (fastest - slowest) + slowest, 2)
var ama = 0.0
ama := na(ama[1]) ? close : ama[1] + sc * (close - ama[1])

// === Stiffness Indicator Settings === //


maLength = input.int(30, title="Stiffness MA Length")
stiffLength = input.int(90, title="Stiffness Period")
stiffSmooth = input.int(9, title="Stiffness Smoothing")
threshold = input.float(55, title="Stiffness Threshold")

bound = ta.sma(close, maLength) - 0.2 * ta.stdev(close, maLength)


sumAbove = math.sum(close > bound ? 1 : 0, stiffLength)
stiffness = ta.ema(sumAbove * 100 / stiffLength, stiffSmooth)

// === CMF (Chaikin Money Flow) Settings === //


lengthCMF = input.int(90, title="CMF Length")
ad = close == high and close == low or high == low ? 0 : ((2 * close - low -
high) / (high - low)) * volume
mf = math.sum(ad, lengthCMF) / math.sum(volume, lengthCMF)

// === Take Profit Inputs === //


long_tp1 = input.float(2.0, title="Long TP1 (%)", minval=0.1) * 0.01
long_tp2 = input.float(4.0, title="Long TP2 (%)", minval=0.1) * 0.01
short_tp1 = input.float(2.0, title="Short TP1 (%)", minval=0.1) * 0.01
short_tp2 = input.float(4.0, title="Short TP2 (%)", minval=0.1) * 0.01

// === Entry Conditions with Stiffness Filter === //


upward = close > ama
downward = close < ama
cmfPositive = mf > 0
cmfNegative = mf < 0
stiffnessFilter = stiffness > threshold

longEntry = upward and cmfPositive and stiffnessFilter and in_date_range


shortEntry = downward and cmfNegative and stiffnessFilter and in_date_range

// === Apply Trade Mode Filters === //


longAllowed = tradeMode == "Both" or tradeMode == "Long Only"
shortAllowed = tradeMode == "Both" or tradeMode == "Short Only"

longEntry := longEntry and longAllowed


shortEntry := shortEntry and shortAllowed

// === Exit on Trend Weakness Conditions === //


exitLongCondition = close < ama or stiffness < threshold or mf < 0
exitShortCondition = close > ama or stiffness < threshold or mf > 0

// === Track Open Trades === //


var bool tradeClosed = true
var float tp1 = na
var float tp2 = na

if strategy.position_size == 0
tradeClosed := true

// === Execute Long Trades with Take Profits === //


if (longEntry and tradeClosed)
strategy.close("Short", comment="EXIT-SHORT") // Ensure short position is
closed
tradeClosed := false
strategy.entry("Long", strategy.long, comment="ENTER-LONG")

tp1 := close * (1 + long_tp1)


tp2 := close * (1 + long_tp2)

strategy.exit("Long TP1", from_entry="Long", limit=tp1, qty_percent=50)


strategy.exit("Long TP2", from_entry="Long", limit=tp2, qty_percent=100,
comment="EXIT-LONG")

// === Execute Short Trades with Take Profits === //


if (shortEntry and tradeClosed)
strategy.close("Long", comment="EXIT-LONG") // Ensure long position is closed
tradeClosed := false
strategy.entry("Short", strategy.short, comment="ENTER-SHORT")

tp1 := close * (1 - short_tp1)


tp2 := close * (1 - short_tp2)

strategy.exit("Short TP1", from_entry="Short", limit=tp1, qty_percent=50)


strategy.exit("Short TP2", from_entry="Short", limit=tp2, qty_percent=100,
comment="EXIT-SHORT")

// === Ensure Full Close at TP2 === //


if (strategy.position_size > 0 and not na(tp2) and close >= tp2)
strategy.close("Long", comment="FORCED-EXIT-LONG")
tradeClosed := true

if (strategy.position_size < 0 and not na(tp2) and close <= tp2)


strategy.close("Short", comment="FORCED-EXIT-SHORT")
tradeClosed := true

// === Exit Trades on Trend Weakness === //


if strategy.position_size > 0 and exitLongCondition
strategy.close("Long", comment="Exit Long on Trend Weakness")
tradeClosed := true

if strategy.position_size < 0 and exitShortCondition


strategy.close("Short", comment="Exit Short on Trend Weakness")
tradeClosed := true

// === Trend-Based Bar Coloring === //


var color barColor = na
barColor := longEntry ? color.green : barColor
barColor := shortEntry ? color.red : barColor
barColor := na(barColor) ? color.gray : barColor
barcolor(barColor)

//
***********************************************************************************
***********************************************************************************
***********************************************************************************
****************
// MONTHLY TABLE PERFORMANCE - Developed by @QuantNomad
//
***********************************************************************************
***********************************************************************************
***********************************************************************************
****************
// DASHBOARD PERFORMANCE TABLE//
i_tableTextSize = input.string(title = 'Dashboard Size', defval = 'Small', options
= ['Auto', 'Huge', 'Large', 'Normal', 'Small', 'Tiny'], group = 'Dashboards')
table_text_size(s) =>
switch s
'Auto' => size.auto
'Huge' => size.huge
'Large' => size.large
'Normal' => size.normal
'Small' => size.small
=> size.tiny
tableTextSize = table_text_size(i_tableTextSize)

/// Performance Summary Dashboard


//
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// Inspired by https://www.tradingview.com/script/uWqKX6A2/ - Thanks VertMT

i_showDashboard = input.bool(title = 'Performance Summary', defval = true, group =


'Dashboards', inline = 'Show Dashboards')

f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>


_cellText = _title + '\n' + _value
table.cell(_table, _column, _row, _cellText, bgcolor = _bgcolor, text_color =
_txtcolor, text_size = tableTextSize)

// Draw dashboard table


if i_showDashboard
var bgcolor = color.new(color.black, 0)

// Keep track of Wins/Losses streaks


newWin = strategy.wintrades > strategy.wintrades[1] and strategy.losstrades ==
strategy.losstrades[1] and strategy.eventrades == strategy.eventrades[1]
newLoss = strategy.wintrades == strategy.wintrades[1] and strategy.losstrades >
strategy.losstrades[1] and strategy.eventrades == strategy.eventrades[1]

varip int winRow = 0


varip int lossRow = 0
varip int maxWinRow = 0
varip int maxLossRow = 0

if newWin
lossRow := 0
winRow := winRow + 1
winRow
if winRow > maxWinRow
maxWinRow := winRow
maxWinRow

if newLoss
winRow := 0
lossRow := lossRow + 1
lossRow
if lossRow > maxLossRow
maxLossRow := lossRow
maxLossRow

// Prepare stats table


var table dashTable = table.new(position.top_right, 1, 15, border_width = 1)

if barstate.islastconfirmedhistory
// Update table
dollarReturn = strategy.netprofit
f_fillCell(dashTable, 0, 0, 'Start:', str.format('{0,date,long}',
strategy.closedtrades.entry_time(0)), bgcolor, color.white) // + str.format("
{0,time,HH:mm}", strategy.closedtrades.entry_time(0))
f_fillCell(dashTable, 0, 1, 'End:', str.format('{0,date,long}',
strategy.opentrades.entry_time(0)), bgcolor, color.white) // + str.format("
{0,time,HH:mm}", strategy.opentrades.entry_time(0))
_profit = strategy.netprofit / strategy.initial_capital * 100
f_fillCell(dashTable, 0, 2, 'Net Profit:', str.tostring(_profit, '##.##') +
'%', _profit > 0 ? color.teal : color.maroon, color.white)
_numOfDaysInStrategy = (strategy.opentrades.entry_time(0) -
strategy.closedtrades.entry_time(0)) / (1000 * 3600 * 24)
f_fillCell(dashTable, 0, 3, 'Percent Per Day', str.tostring(_profit /
_numOfDaysInStrategy, '#########################.#####') + '%', _profit > 0 ?
color.teal : color.maroon, color.white)
_winRate = strategy.wintrades / strategy.closedtrades * 100
f_fillCell(dashTable, 0, 4, 'Percent Profitable:', str.tostring(_winRate,
'##.##') + '%', _winRate < 50 ? color.maroon : _winRate < 75 ? #999900 :
color.teal, color.white)
f_fillCell(dashTable, 0, 5, 'Profit Factor:',
str.tostring(strategy.grossprofit / strategy.grossloss, '##.###'),
strategy.grossprofit > strategy.grossloss ? color.teal : color.maroon, color.white)
f_fillCell(dashTable, 0, 6, 'Total Trades:',
str.tostring(strategy.closedtrades), bgcolor, color.white)
f_fillCell(dashTable, 0, 8, 'Max Wins In A Row:', str.tostring(maxWinRow,
'######'), bgcolor, color.white)
f_fillCell(dashTable, 0, 9, 'Max Losses In A Row:',
str.tostring(maxLossRow, '######'), bgcolor, color.white)

You might also like