dorien
dorien

Reputation: 5407

How to hide default strategy markings

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

Upvotes: 2

Views: 1404

Answers (2)

Jaro
Jaro

Reputation: 51

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)

Upvotes: 0

Andrey D
Andrey D

Reputation: 1714

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

Upvotes: 3

Related Questions