~~Title: PnL Check (Query)~~
{{tag>guides}}
==== How-to: Regular account PnL check to limit loss/risk ====
It is always recommended to use testnet/sandbox first!
ex=bybitv5demo acc=*
# query PnL of all closed trades from the last 24h (1d) and save the summarized data to local variables
query=pnl from=-1d sym=* save
echo=~~codedoc:clean:"We made {lastpnlsum.2}% in the last 24h!"~~
if=(lastpnlsum < 0) goto=loss
exit
:loss
echo=~~codedoc:clean:"WE HAD LOSSES, STOP THE MACHINES!":fatal~~
disable=PV
# alternatively: disable entry alert and enable again if lastpnlsum >= 0 (disable=alertname)
# alternatively: place a custom lock with an expiration time to prohibit entry temporarily
# alternatively: set a global variable that you check in the entry alert
**Note:** Currently only works on Bybit, but the query command will soon be implemented for other exchanges as well!
\\
To run the above check **automatically** in regular intervals you can simply configure the **PV** alert accordingly:
{{:syntax:pnl-check-schedule.png?nolink|}}
{{:syntax:pnl-check-schedule-edit.png?nolink&900|}}
**Note:** You might have to click the little syphon icon on the right above all the alerts to toggle the visibility of the advanced filtering options!
=== Attention ===
Always double check that you are using the right syntax/alert!