I have a strategy that is going long and short, and I’m trying to use OnOrderUpdate() and averageFillPrice to draw two lines that keep track of the long and short entries:
* One line is formed by the entry price for each long entry,
* The other line is formed by the entry price for each short entry.
For example, looking at just the long entries line, here is a hypothetical situation:
A. The strategy buys NQ at 8,700 at 10:00, at 10:09 it sells NQ at 8,750, then at 10:20 it buys NQ again at 8,720.
B. Therefore, the long entries line would be:
From 10:00 to 10:19: 8,700
From 10:20 onwards: 8,720
I suspect I need to create a variable which is equal to the averageFillPrice when it goes long and only changes when there is another long fill.
However: when I tried the following code, it did not work! I only get a line segment.
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.Name == "MyLong")
{
if (!pos1)
{
posb1 = CurrentBar; //save the start bar for the region
pos1 = true;
pos2 = false;
}
pos1price = averageFillPrice;
}
StrategyPlot5[0] = pos1price;
Could there be any example code to which you could point me so I might see an example of this?
I would really appreciate the help. Thank you in advance!
Comment