I created a rather simple strategy which is aiming to submit a Long (or Short, doesn't matter) sample order on an arbitrary instrument, and follow its execution.
I tried to follow the programming guidelines (managed approach) and the samples from the forum and came up with something like:
-------------------------------
protected override void OnBarUpdate()
{
EnterLong("aTest");
Print(isOrderFilled ? "Order is filled" : "Order is NOT filled");
if (entryOrder != null){
Print("NotNull:" + entryOrder.ToString());
} else {
Print("Null:");
}
Print("");
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order.Name == "aTest")
{
Print("Order is BEING FILED ...");
Print(execution.ToString());
Print("... instrument -> " + execution.Instrument);
Print("... quantity -> " + execution.Quantity);
Print("... position -> " + execution.Position);
entryOrder = execution.Order;
isOrderFilled = true;
}
}
private Order entryOrder = null;
private bool isOrderFilled;
--------------------------------------------
In the log I see the following lines.
-------------------------------------------
Strategy 'MyCustomStrategy/197652248': An order placed at '3/31/2020 2:06:00 PM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
Order is NOT filled
Null:
Order is NOT filled
Null:
Order is NOT filled
Null:
Order is BEING FILED ...
execution='NT-00000-389' instrument='GBPJPY' account='Sim101' exchange=Default price=133.638 quantity=1 marketPosition=Long orderId='NT-00000-389' time='2020-03-31 14:12:00' sod=False statementDate='0001-01-01'
... instrument -> GBPJPY Default
... quantity -> 1
... position -> 0
Order is filled
NotNullrderId='NT-00000-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=133.638 onBehalfOf='' id=-1 time='2020-03-31 14:09:00' gtd='2099-12-01' statementDate='2020-04-06'
Order is filled
NotNullrderId='NT-00000-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=133.638 onBehalfOf='' id=-1 time='2020-03-31 14:09:00' gtd='2099-12-01' statementDate='2020-04-06'
Order is filled
NotNullrderId='NT-00000-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=133.638 onBehalfOf='' id=-1 time='2020-03-31 14:09:00' gtd='2099-12-01' statementDate='2020-04-06'
[...]
Order is filled
NotNullrderId='NT-00006-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=132.579 onBehalfOf='' id=-1 time='2020-04-05 14:04:00' gtd='2099-12-01' statementDate='2020-04-06'
Enabling NinjaScript strategy 'MyCustomStrategy/197652248' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=GBPJPY 1L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
Order is filled
NotNullrderId='NT-00006-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=132.579 onBehalfOf='' id=-1 time='2020-04-05 14:04:00' gtd='2099-12-01' statementDate='2020-04-06'
Order is filled
NotNullrderId='NT-00006-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=132.579 onBehalfOf='' id=-1 time='2020-04-05 14:04:00' gtd='2099-12-01' statementDate='2020-04-06'
Order is filled
NotNullrderId='NT-00006-389' account='Sim101' name='aTest' orderState=Filled instrument='GBPJPY' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=132.579 onBehalfOf='' id=-1 time='2020-04-05 14:04:00' gtd='2099-12-01' statementDate='2020-04-06'
-----------------------------------------
Looking at the log I would say the code works as intended, and the order is created and executed as planned. However I don't see it anywhere in the application (Orders, Executions, Positions.. anything)
Could anyone please let me know if you have any ideas what I might be doing wrong?...
Thanks in advance,
Sorin
Comment