Pinescript - Re-initialize alert variable

426 Views Asked by At

I am trying to do something very basic in Pine, but I am completely stumped on how to solve the issue. In summary I have an alert which need to update a fixed price level on a user input. The alert places an order on the chart, and I can update the price level as I see fit. When the alert is re-triggered (once per bar close) then the order is placed at the new level

However, the only behaviour I can see is that the initial variable is forever fixed until I remove the alert completely from the alert console and re-add the alert. For example, if I apply the below alert to the chart the fp=0 will not change even though I change the user input after the alert has been added.

Any help is much appreciated. Or if you need more info please let me know. Thanks in advance

var symbol = syminfo.basecurrency + "/" + syminfo.currency
var avPrefix = "e=oandapractice "  + " s=" + symbol + ""
var TpPrice = 0.000000
t_TpPrice = input(title="TP Price?", type=input.float,  defval=0.000000, step=0.000001)


if (barstate.isrealtime) 
    TpPrice := t_TpPrice
    clearOrder = avPrefix + " c=order\n "
    tpTrigger = avPrefix + " b=sell" + " q=20000" + " t=limit" + " fp=" + tostring(TpPrice)
    alert( message=clearOrder + tpTrigger ,freq=alert.freq_once_per_bar_close)   
1

There are 1 best solutions below

2
Starr Lucky On

You are using input constant variable, which is not changes after compilation. You will need to recreate alert, if you want to use it with another value from input.