简体   繁体   中英

Query the price of a candle in real time

What possibility is there to query the price of a candle in real time and compare it with a variable. I want that when the price of the candle has reached the price of my long or short trade without it being closed, it will be canceled. Is that possible? I tried that, it works, the candle price is displayed in real time, but how can I now trigger a trading view alarm to close the trade?

aktuell_price = close
xt := label.new(bar_index, y=high, text=str.tostring(aktuell_price), color=color.green, textcolor=color.black, style=label.style_label_down)
label.delete(xt[1])


You can do that in real time mode on PineScript, as the your script will be executed each time the value of the asset change.
You should also use Pinescript Version 5:

// Here 'close' is the value of the real-time bar during it's formation
if close > my_price 
    // It is just an example, you can use strategy.close(...) also
    strategy.cancel_all() 

Thank you for the feedback. Unfortunately, the strategy in Pinescript does not work with the strategy calls in Tradingview. So

if(short_condition and barstate.isconfirmed and time_is_allowed) // short_condition //and big_candle > hearts_h alertShortEntry = input.string("Entry Short {{ticker}},": "Alert Message Short Entry, ". group = "Alert Settings") strategy,entry("GS". strategy,short, alert_message = alertShortEntry)

work but all other calls to trigger an alarm are ignored by tradingview. So only if I specify strategy.long or strategy.short does Tradingview trigger an alarm. When I try strategy.close or strategy.exit nothing is thrown from tradingview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM