Hi,
I’m new to powerlanguage programming. I’m trying to make a simple test to approach to the automatic order launch.
I have this code:
private IOrderStopLimit orderbuy;
protected override void Create(){
orderbuy = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Buy));
}
protected override void CalcBar()
orderbuy(Bars.High(0) + 2 ,Bars.High(0) + 2);
}
What I pretend with this code is to send a buy stop limit order 2 points over the max of the last bar when a bar closes.
If I run this signal, when a bar finishes, the wanted buy order is sent. But if it is not filled during next bar, when it finishes the order is moved to the new high + 2, and that is not what I want.
Later, I have tried to code another example: when a bar finishes, send a buy stop order 2 points over the max, and a sell stop order 2 points under the low. I have tried this code:
private IOrderStopLimit orderbuy;
private IOrderStopLimit ordersell;
protected override void Create(){
orderbuy = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Buy));
ordersell = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default,EOrderAction.Sell));
}
protected override void CalcBar()
orderbuy(Bars.High(0) + 2 ,Bars.High(0) + 2);
ordersell(Bars.Low(0) - 2 ,Bars.Low(0) - 2);
}
}
When I run it, it launch the buy order, but not the sell order. It only launch the sell order if the buy order is filled.
The final goal I want to achieve is to launch a sort of OCO group at the end of a bar, compossed by:
An entry buy stop limit 2 points over the max of the last bar.
An exit sell limit a number of points over the buy.
An exit sell stop, a number of points below the buy.
If the bar finishes and the buy has not been filled, all orders must be cancelled.
If the buy is filled, then if one of the other orders is filled, the other has to be cancelled.
If the buy is filled and the bar in which it has been filled finished with the other two orders unfilled, move the stop sell some points up, and just wait until one of them is filled. When this occurs, the other order has to be cancelled.
And of course, whenever a position is opened, no new orders can be sent to the market.
I appreciate some help. Not need the whole code. I have enough with some clues in the right direction.