I have now removed the SetTrailStop().
However, there are some more issues emerging in simulated trading.
Pls look at the following part of the code extracted:
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(Typical, X), EMA(Typical, Z), 1)
&& CrossAbove(CCI(Typical, C), -200, 100))
{
PN = Close[1];
AX = GetCurrentAsk();
if (Historical)
return;
if (MarketPosition.Flat == Position.MarketPosition
&& (AX-PN)/PN*100 <= SN)
{
entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLong");
}
}
protected override void OnExecution(IExecution execution)
{
if (execution.Name == "EnterLong"
&& execution.Order == entryOrder && execution.Order.OrderState == OrderState.Filled)
{
Print("OnExecution PositionQuantity: "+Position.Quantity+" Total orders needed: "+TQ);
AX = GetCurrentAsk();
if( Position.Quantity < TQ
&& (AX-PN)/PN*100 <= SN)
{
// Send as many entries to get the total quantity filled.
for(int i = TQ - Position.Quantity; i>0 ; i--)
{
entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLongAgain"+i);
}
}
}
-------------------
Now here, what if, the Order is fired but is in State Working.
In that case i want to fill the following logic:
If
execution.Order.OrderState == OrderState.Working
AX = GetCurrentAsk();
if (AX-PN)/PN*100 <= SN)
{
entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLong");
}
--
No, where do i put this for both Entry as well as Exit Conditions?
The entire code in .cs is attached for reference.

Comment