Reputation: 7707
Sometimes, especially if pyramiding is high, TV will stop the alert if there is a burst of activity. I would like to group alerts that happen in the same minute (or session) so that only one alert will come out with the composition of orders.
For example if in the same minute I receive
buy 30 at 00:00:33
buy 30 at 00:00:46
buy 30 at 00:00:46
I would like to receive buy 90 at 00:01:00
, similarly if I receive
buy 30 at 00:00:00
sell 30 at 00:00:45
sell 30 at 00:00:59
I would like to receive sell 30 at 00:01:00
. Is there a mechanism I can leverage to do such grouping? I've seen people working with the modulo of the timestamp to achieve this but I'm not convinced, would that be idiomatic for pine script? I don't want it to break in the future.
Upvotes: 0
Views: 174
Reputation: 2161
You can use your own custom alert()
function and trigger it when you decide. That way, you can create a variable and count the quantity you wish to buy or sell, and trigger the alert when the seconds equal to 0. For example:
var qty = 0
if second(time) == 0 and qty > 0
alert("buy " + str.tostring(qty))
qty := 0
if second(time) == 0 and qty < 0
alert("sell " + str.tostring(qty))
qty := 0
longCond = // whatever you want
shortCond = // whatever you want
if longCond
qty += 30
if shortCond
qty -= 30
The main issue is that the code runs when bar closes, and if there are no trades there is no bar, and therefor sometimes there will be no bar on which second(time) == 0
will be true
.
A workaround is to count 60 bars on a 1 second timeframe chart, and trigger the alert()
function whenever you reach 60 bars:
var qty = 0
var barCounter = 0
barCounter += 1
longCond = // whatever you want
shortCond = // whatever you want
if longCond
qty += 30
if shortCond
qty -= 30
if barCounter == 60
if qty > 0
alert("buy " + str.tostring(qty))
if qty < 0
alert("sell " + str.tostring(qty))
qty := 0
barCounter := 0
While I realize that 60 1 second bars will not be equal to 60 seconds, this might currently be the closest solution to the problem that many times there are no 60 bars in 60 seconds.
Upvotes: 1