1

I have a comment in my strategy (need that for my custom alert). But it displays the comment on the graph. Any way for me to hide comment, price, and those arrows. I don't think I'm calling plot or label anywhere...

enter image description here

The reason I want to do this is because I want to create nice custom labels. For instance:

// Check if the strategy opened a long position
longNow = (strategy.position_size[1] <= 0) and (strategy.position_size > 0)
// Look if the strategy went long from a short position
longFromShort = (strategy.position_size[1] < 0) and (strategy.position_size > 0)
// See if the strategy went long from being flat
// at the end of the previous bar
longFromFlat = (strategy.position_size[1] == 0) and (strategy.position_size > 0)
 // See if strategy is short now, from long or flat earlier
shortNow = (strategy.position_size[1] >= 0) and (strategy.position_size < 0)
// See if strategy went short from no market position earlier
shortFromFlat = (strategy.position_size[1] == 0) and (strategy.position_size < 0)
// See if strategy is flat now (from a market position earlier)
flatNow = (strategy.position_size[1] != 0) and (strategy.position_size == 0)
// Check if strategy went flat from previous long position
flatFromLong = (strategy.position_size[1] > 0) and (strategy.position_size == 0)
// See if strategy went from flat to short position
flatFromShort = (strategy.position_size[1] < 0) and (strategy.position_size == 0)

// green arrow
if longNow
    myLabel2 = label.new(x=bar_index, y=low - 0.5 * tr, text=tostring(strategy.position_avg_price), color=color.green, textcolor=color.black, style=label.style_labelup)

But now my nice green labels are overlayed with the comment: enter image description here

--update based on Andrey D's answer:

Using alert_message I can keep the comments empty. Still the position size shows on the graph per default.

enter image description here

dorien
  • 5,265
  • 10
  • 57
  • 116

2 Answers2

2

You can use the alert_message parameter and {{alert_message}} placeholder in your alerts.

Andrey D
  • 1,534
  • 1
  • 5
  • 7
  • That helps me keep the comments empty, but it still displays the position size on the graph by default. I added a screenshot in the question. – dorien Jul 08 '21 at 05:07
  • 1
    Check the `Style` page in the Settings of your strategy: https://i.imgur.com/mMGLaJY.png – Andrey D Jul 08 '21 at 15:56
  • OMG thank you! So easy, how could I have overlooked this! – dorien Jul 09 '21 at 02:00
0

Is this really the only somewhat ok solution for hiding the quantity without needing to uncheck it in the styles?: Hide trades on chart, quantity and signal labels in code tradingview

I'll just add that for pinescript v5, this is the correct code: var bool UnHideCode = input(false, title="Un Hide Code")

Then the rest of the code is the same for all pine versions so far: if(LongSignal and UnHideCode) strategy.entry("Buy - Long Term", long=true)

Jaro
  • 51
  • 5
  • This would not work as it would prohibit any strategy entries from occurring, thus disabling the backtesting. – dorien Apr 29 '23 at 07:17
  • Yes, but the idea was that you can easily turn it on/off, while keeping other parts of the strategy script intact - like showing the moving average lines, etc. vs if you just completely hid the whole script. – Jaro Apr 30 '23 at 08:45