Opening a single position for critera
Opening a single position for critera
17 Oct 2018, 15:28
Hi,
I am rather new to codeing cbots with my experience limited to VBA and MathLab in the past.
During backtesting, I noticed in my trade history multiple trades opening on the same time period when critera is met, skewing my results.
I would like only 1 trade to be placed when the critera is met.
My setup is:
if (Criteria1 && Positions.Count == 0 && Criteria2)
{
PlaceLimitOrder(TradeType.Buy, Symbol, VolumeInUnits, Limit, label, SL, boll2.TP);
}
else if (Criteria1 && Positions.Count == 0 && Criteria2)
{
PlaceLimitOrder(TradeType.Sell, Symbol, VolumeInUnits, Limit, label, SL, TP);
}
Criteria1 and Criteria2 are based on movement in bollingerbands.
The if statement is run in the OnTick() instance.
besides Positions.Count I have also tried
longPosition == null
with
longPosition = Positions.Find(label, Symbol, TradeType.Buy);
Any advise would be much appreciated.
Replies
PanagiotisCharalampous
18 Oct 2018, 09:42
Hi tim_d2,
Yo get the pending limit orders. you can try the following
PendingOrders.Where(x => x.OrderType == PendingOrderType.Limit);
Best Regards,
Panagiotis
@PanagiotisCharalampous
freemangreat
17 Oct 2018, 15:59
limit order is not an open position.
Are you sure the label is defined?
@freemangreat