0

I have an indicator which sends alerts when buy and sell signals appear. The indicator itself is not repainting when the bar has closed, but it repaint on the current bar. My problem is that I need my indicator to send alerts every time the signal changes. If the bar opens with buy, and later changes to sell I get alerts. but I dont get alerts when it goes from buy to sell and then to buy again on the same bar. Should I change it to strategy or study? Or use alert() instead of 'alertcondition()'

I dont want to trade on bar close

I really appreciate any inputs.

This is a part of my code:

alertcondition(goLong, title = "Long", message = "Buy")
alertcondition(goShort, title = "Short", message = "Sell")

I reaally appreciate if you could help me!

I have tried ChatGPT and different variations of this code:

var bool hasLongAlert = false
var bool hasShortAlert = false

if goLong
    if not hasLongAlert
        alert("Long", alert.freq_all)
        hasLongAlert := true

if goShort
    if not hasShortAlert
        alert("Short", alert.freq_all)
        hasShortAlert := true

if not goLong
    hasLongAlert := false

if not goShort
    hasShortAlert := false
N00b
  • 1
  • 3

1 Answers1

0

You'll likely have much better luck converting the indicator into a strategy and having the alerts execute as strategy alert messages.

Then remember to create alerts with '{{strategy.order.alert_message}}' in the alert message box.

Something like this should be a good start after you've converted the indicator into a strategy (sorry if it's not formatted quite correct!):

if goLong

strategy.entry('Long', strategy.long, alert_message = 'Buy')

if goShort

strategy.entry('Short', strategy.short, alert_message = 'Sell')
Oxelo
  • 7
  • 2