Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("PEPE REAL SIZING TEST", overlay=true, initial_capital=100)
- //// Inputs
- stopLossPercentage = input.float(0.2, title="Stop Loss Percentage") * 0.01
- takeProfitPercentage = input.float(0.2, title="Take Profit Percentage") * 0.01
- //// Position SIze
- getBetSize(stop) =>
- onePercentCapital = strategy.equity * 0.02
- betSize = onePercentCapital / math.abs(close - stop)
- //// Bands
- ema12 = ta.ema(close, 12)
- ema21 = ta.ema(close, 21)
- //// Exit lines
- var line stopLossLine = na
- var line takeProfitLine = na
- if strategy.position_size == 0
- stopLossLine := na
- takeProfitLine := na
- else
- stopLossLine.set_x2(bar_index)
- takeProfitLine.set_x2(bar_index)
- // Logic
- //// Longs
- if ta.crossover(ema12, ema21) and strategy.position_size == 0
- stopLoss = close * (1 - stopLossPercentage)
- takeProfit = close * (1 + takeProfitPercentage)
- stopLossLine := line.new(bar_index, stopLoss, bar_index, stopLoss, color=color.red)
- takeProfitLine := line.new(bar_index, takeProfit, bar_index, takeProfit, color=color.green)
- strategy.entry("Long", strategy.long, getBetSize(stopLoss))
- strategy.exit("SL / TP", "Long", stop=stopLoss, limit=takeProfit)
- //// Shorts
- if ta.crossunder(ema12, ema21) and strategy.position_size == 0
- stopLoss = close * (1 + stopLossPercentage)
- takeProfit = close * (1 - takeProfitPercentage)
- stopLossLine := line.new(bar_index, stopLoss, bar_index, stopLoss, color=color.red)
- takeProfitLine := line.new(bar_index, takeProfit, bar_index, takeProfit, color=color.green)
- strategy.entry("Short", strategy.short, getBetSize(stopLoss))
- strategy.exit("SL / TP", "Short", stop=stopLoss, limit=takeProfit)
- // Plots
- bandColor = ema12 > ema21 ? color.green : color.red
- plot(ema12, color=bandColor, linewidth=1)
- plot(ema21, color=bandColor, linewidth=3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement