I am using a study that runs continously as a bar is built (I am not using setComputeOnClose(true)). There are some lines of code that I only want to execute on the first tick of a new bar.
This is what I tried:
if (getBarState() == BARSTATE_NEWBAR)
{
if (OrderPlacedBarCount == 2)
{
OrderPlacedBarCount = 3;
}
}
if ((getBarState() == BARSTATE_NEWBAR))
{
if (OrderPlacedBarCount == 1)
{
OrderPlacedBarCount = 2;
}
}
When I run this and OrderPlacedBarCount was set to 1 on the previous bar, OrderPlacedBarCount returns 3 instead of 2. Since the formula is run each time a new tick comes in, I put the code that sets the OrderPlacedBarCount value to 3 first, assuming that it could only be run after the first tick of a new bar and would therefore not execute in the current bar. It appears that BARSTATE_NEWBAR does not limit execution only to the first tick of a new bar. Does anyone know of a function that will work for this?
I am running version 7.91.
Thanks
This is what I tried:
if (getBarState() == BARSTATE_NEWBAR)
{
if (OrderPlacedBarCount == 2)
{
OrderPlacedBarCount = 3;
}
}
if ((getBarState() == BARSTATE_NEWBAR))
{
if (OrderPlacedBarCount == 1)
{
OrderPlacedBarCount = 2;
}
}
When I run this and OrderPlacedBarCount was set to 1 on the previous bar, OrderPlacedBarCount returns 3 instead of 2. Since the formula is run each time a new tick comes in, I put the code that sets the OrderPlacedBarCount value to 3 first, assuming that it could only be run after the first tick of a new bar and would therefore not execute in the current bar. It appears that BARSTATE_NEWBAR does not limit execution only to the first tick of a new bar. Does anyone know of a function that will work for this?
I am running version 7.91.
Thanks
Comment