Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("GG", overlay=true)
- smalengt50 = 50
- emalengt12 = 12
- emalengt21 = 21
- //// Inputs
- stopLossPercentage = input.float(3, "Stop Loss Percentage") * 0.01
- takeProfitPercentage = input.float(3, "Take Profit Percentage") * 0.01
- sma50 = ta.sma(close, 50)
- ema12 = ta.ema(close, 12)
- ema21 = ta.ema(close, 21)
- // 1. Put these "na"s.
- var line stopLossLine = na
- var line takeProfitLine = na
- // 2. Adding logic to manually reset or extend the lines based on if we are in a position or not.
- if strategy.position_size == 0
- stopLossLine := na
- takeProfitLine := na
- else
- stopLossLine.set_x2(bar_index)
- takeProfitLine.set_x2(bar_index) //
- lc = ta.crossover(ema12, ema21)
- sc = ta.crossunder(ema12, ema21)
- if lc and strategy.position_size == 0
- stopLoss = close * (1 - 0.03)
- takeProfit = close* (1 + 0.03)
- // 3. Draw the start of the lines when we enter a position.
- 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, stop=stopLoss, limit=takeProfit)
- strategy.exit("SL/TP", "Long", stop=stopLoss, limit=takeProfit)
- if sc and strategy.position_size == 0
- stopLoss = close * (1 + 0.03)
- takeProfit = close * (1 - 0.03)
- // 3. Draw the start of the lines when we enter a position.
- 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, stop=stopLoss, limit=takeProfit)
- strategy.exit("SL/TP", "Short", stop=stopLoss, limit=takeProfit)
- bandColor50 = sma50 < sma50[1] ? #ffa73c : color.rgb(33, 184, 243)
- bandColor = ema12 > ema21 ? color.green : color.red
- plot(ema12, color=bandColor)
- plot(ema21, color=bandColor)
- plot(sma50, color=bandColor50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement