How to trigger alerts in real time (calc_on_every_tick on)
Posted: Wed Mar 01, 2023 9:08 pm
Hi guys, hope you are doing well.
I'm an intermediate level coder, but still I had been struggling for some weeks with a simple code and I cannot make it work. Please I need your help.
The intention is to trigger an entry at the exact time upper/lower Bollinger band line is crossed, and close it when BB MA is crossed (both are checked on real time, before bar closes). I need to link this with an external bot provider so I need to trigger alerts. Strategy and entry alerts are working well, but exit is not working.
This is the exit condition. When this happens, both strategy.exit and alert() code lines are triggered. I have tried adding and removing strategy (and leaving only alert code), but nothing helped.
realtimeCloseCond = barstate.isrealtime and (strategy.position_size > 0 and close < SL_long) or (strategy.position_size < 0 and close > SL_short)
My best hypothesis is that calc_on_every_tick on is messing things around someway and strategy.position_size never actually changed (stayed at zero)
I was wondering if you had any similar issue working with calc_on_every_tick on that could help me understand this error. I feel there is something about the way code works with calc_on_every_tick on that I don't know and may be explaining this issue.
Thanks in advance and regards
I'm an intermediate level coder, but still I had been struggling for some weeks with a simple code and I cannot make it work. Please I need your help.
The intention is to trigger an entry at the exact time upper/lower Bollinger band line is crossed, and close it when BB MA is crossed (both are checked on real time, before bar closes). I need to link this with an external bot provider so I need to trigger alerts. Strategy and entry alerts are working well, but exit is not working.
This is the exit condition. When this happens, both strategy.exit and alert() code lines are triggered. I have tried adding and removing strategy (and leaving only alert code), but nothing helped.
realtimeCloseCond = barstate.isrealtime and (strategy.position_size > 0 and close < SL_long) or (strategy.position_size < 0 and close > SL_short)
My best hypothesis is that calc_on_every_tick on is messing things around someway and strategy.position_size never actually changed (stayed at zero)
I was wondering if you had any similar issue working with calc_on_every_tick on that could help me understand this error. I feel there is something about the way code works with calc_on_every_tick on that I don't know and may be explaining this issue.
Thanks in advance and regards