Advanced Position Size Source Code (Forex)
Advanced Position Size Source Code (Forex)
0 at
https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading / www.PineScriptMastery.com
// @version=5
strategy(title="Breakout Strategy", overlay=true, currency="USD")
// Import ZenLibrary
import ZenAndTheArtOfTrading/ZenLibrary/3 as zen
// Get ATR
atr = ta.atr(14)
// If bullish breakout detected today, disable any future signals for today
if bullishBO
bullishBreakoutToday := true
t_stop := longStop
t_target := longTarget
positionSize = zen.av_getPositionSize(strategy.equity, riskPerTrade,
zen.toWhole(longStopDist) * 10, conversionCurrencyRate)
stopLabelText = str.tostring(longStopDist / syminfo.mintick / 10, "#.#")
strategy.entry(id="Long", direction=strategy.long, qty=positionSize,
comment="Long (SL=" + stopLabelText + " pips)")
// If bearish breakout detected today, disable any future signals for today
if bearishBO
bearishBreakoutToday := true
t_stop := shortStop
t_target := shortTarget
positionSize = zen.av_getPositionSize(strategy.equity, riskPerTrade,
zen.toWhole(shortStopDist) * 10, conversionCurrencyRate)
stopLabelText = str.tostring(shortStopDist / syminfo.mintick / 10, "#.#")
strategy.entry(id="Short", direction=strategy.short, qty=positionSize,
comment="Short (SL=" + stopLabelText + " pips)")
// Draw signals
plotshape(bearishBO, title="Bearish Breakout", style=shape.triangledown,
location=location.abovebar, color=color.red)
plotshape(bullishBO, title="Bullish Breakout", style=shape.triangleup,
location=location.belowbar, color=color.green)