Hi All,
I need help in writing the code to count the number of times the Mark Price has crossed the Open Price within a 1 minute bar. I want to use the result in my Buy Order condition to decide if the order should be placed or not.
Example, I have a Buy order lined up to be submitted at 9:31:00 AM. This order will have a Study Condition attached to it to submit only if the price action of the 9:30 AM bar wasn't too "choppy" i.e. wasn't alternating between red and green many times.
Below is the code I wrote to check for the choppiness of the 9:30 AM 1 minute bar. However, the "crossCounter" value isn't giving me the correct result. Can anyone let me know how to fix this?
The idea is to submit the Buy order at 9:31:00 AM only if the 9:30 AM bar (during its formation) didn't alternate between red and green more than 3 times.
Thanks!
I need help in writing the code to count the number of times the Mark Price has crossed the Open Price within a 1 minute bar. I want to use the result in my Buy Order condition to decide if the order should be placed or not.
Example, I have a Buy order lined up to be submitted at 9:31:00 AM. This order will have a Study Condition attached to it to submit only if the price action of the 9:30 AM bar wasn't too "choppy" i.e. wasn't alternating between red and green many times.
Below is the code I wrote to check for the choppiness of the 9:30 AM 1 minute bar. However, the "crossCounter" value isn't giving me the correct result. Can anyone let me know how to fix this?
Ruby:
def bidPrice = close(priceType = PriceType.BID);
def askPrice = close(priceType = PriceType.ASK);
def mark = (bidPrice + askPrice) / 2;
def crossHappened = mark crosses open;
def crossCounter = if IsNaN(crossCounter[1]) and crossHappened then 1 else if crossHappened then crossCounter[1]+1 else crossCounter[1];
def placeOrder = if crossCounter[1] < 3 then Yes else No;
plot _data_ = placeOrder;
Thanks!