OPEN-SOURCE SCRIPT
huzaifa iqbal pakistan

this is custum only for mazaq //version=6
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
float takeProfit = entryPrice * 1.10 // +//version=6
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
//version=6
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
float takeProfit = entryPrice * 1.10 // +10%
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
10%
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
float takeProfit = entryPrice * 1.10 // +//version=6
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
//version=6
strategy("UT Bot Long Only Strategy", overlay=true, pyramiding=0, initial_capital=10000, currency=currency.USD)
// Parameters for ATR-based trailing stop (UT Bot logic)
var int atrLength = 10 // ATR period length
var float atrMult = 5.0 // ATR multiplier for trailing stop
// Calculate ATR and the ATR-based stop distance (nLoss)
atrValue = ta.atr(atrLength)
nLoss = atrMult * atrValue
// ATR Trailing Stop logic (UT Bot)
// Using persistent variable 'trailingStop' to maintain state across bars
var float trailingStop = na
if na(trailingStop[1])
// Initialize trailing stop on first bar
trailingStop := close - nLoss
else if (close > trailingStop[1] and close[1] > trailingStop[1])
// Price is above trailing stop and was above it in previous bar -> uptrend continues
trailingStop := math.max(trailingStop[1], close - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
// Price is below trailing stop and was below it in previous bar -> downtrend continues
trailingStop := math.min(trailingStop[1], close + nLoss)
else if (close > trailingStop[1])
// Price crossed from below to above the trailing stop -> trend flips up (new long setup)
trailingStop := close - nLoss
else
// Price crossed from above to below the trailing stop -> trend flips down
trailingStop := close + nLoss
// Long entry signal: when price crosses above the trailing stop from below
bool longSignal = (close[1] < trailingStop[1] and close > trailingStop[1])
// Enter long position on UT Bot buy signal (price crossing above trailing stop)
if (longSignal)
strategy.entry("Long", strategy.long, comment="UT Bot Buy Signal")
// Exit conditions: take-profit at +10% and stop-loss at -0.10% from entry price
// We hold until TP or SL is hit; no early exit on UT Bot sell signals
if (strategy.position_size > 0)
// Calculate profit target and stop loss based on entry price
float entryPrice = strategy.position_avg_price
float takeProfit = entryPrice * 1.10 // +10%
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
10%
float stopLoss = entryPrice * 0.999 // -0.10%
strategy.exit("ExitLong", "Long", limit=takeProfit, stop=stopLoss)
// Plot the ATR-based trailing stop for visualization (green when trend is up, red when down)
plot(trailingStop, "Trailing Stop", color = close >= trailingStop ? color.lime : color.red, style=plot.style_line)
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.