Skip to content

Instantly share code, notes, and snippets.

@smyth64
Created March 6, 2022 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smyth64/13d103cf05ad612920ce9a4acdceb5ec to your computer and use it in GitHub Desktop.
Save smyth64/13d103cf05ad612920ce9a4acdceb5ec to your computer and use it in GitHub Desktop.
//
// enter_short and enter_long are the conditions that you use to enter a trade. they need to be defined by you
// They look something like this:
// enter_long = window() and entryConfirmed
// strategy.entry(id='Long', long = true, when=enter_long)
//
bgcolor = close > strategy.position_avg_price[1] ? color.new(#168978, 80) : color.new(#f05350, 80)
border_color = close > strategy.position_avg_price[1] ? color.new(color.green, 20) : color.new(color.red, 20)
barsSinceLong = barssince(enter_long and strategy.position_size <= 0)
if (strategy.position_size <= 0 and strategy.position_size[1] > 0)
box.new(left=bar_index[barsSinceLong], top=close[barsSinceLong], right=bar_index, bottom=close, border_color=border_color, bgcolor=bgcolor)
bgcolor := close < strategy.position_avg_price[1] ? color.new(#168978, 80) : color.new(#f05350, 80)
border_color := close < strategy.position_avg_price[1] ? color.new(color.green, 20) : color.new(color.red, 20)
barsSinceShort = barssince(enter_short and strategy.position_size >= 0)
if (strategy.position_size >= 0 and strategy.position_size[1] < 0)
box.new(left=bar_index[barsSinceShort], top=close[barsSinceShort], right=bar_index, bottom=close, border_color=border_color, bgcolor=bgcolor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment