if (Positions[BarsInProgress].MarketPosition == MarketPosition.Flat)
{
if (allowedTradingHoursStart <= DateTime.Now.Hour && DateTime.Now.Hour < allowedTradingHoursEnd)
{
tpInTicks = (DateTime.Now.Hour < usSessionHour) ? 20 : 30;
if (CheckIfCanEnterLongPosition())
{
Print("Entering Short on " + BarsInProgress);
string signalName = "EnterLong_" + BarsInProgress;
SetProfitTarget(CalculationMode.Ticks, tpInTicks);
EnterLong(BarsInProgress, quantities[BarsInProgress], signalName);
}
else if (CheckIfCanEnterShortPosition())
{
Print("Entering Short on " + BarsInProgress);
string signalName = "EnterShort_" + BarsInProgress;
SetProfitTarget(CalculationMode.Ticks, tpInTicks);
EnterShort(BarsInProgress, quantities[BarsInProgress], signalName);
}
LogFunction();
}
}
else if (Positions[BarsInProgress].MarketPosition == MarketPosition.Long)
{
Print("We are currently Long on " + BarsInProgress);
if (CheckIfCanStopLongPosition(StopMethod.Method2) || DateTime.Now.Hour >= 22)
{
Print("Exiting Long on "+ BarsInProgress);
string fromEntrySignalName = "EnterLong_" + BarsInProgress;
string signalName = "ExitLong_" + BarsInProgress;
ExitLong(BarsInProgress, Positions[BarsInProgress].Quantity, signalName, fromEntrySignalName);
}
}
else if (Positions[BarsInProgress].MarketPosition == MarketPosition.Short)
{
Print("We are currently Short on "+BarsInProgress);
if (CheckIfCanStopShortPosition(StopMethod.Method2) || DateTime.Now.Hour >= 22)
{
Print("Exiting Short on " + BarsInProgress);
string fromEntrySignalName = "EnterShort_" + BarsInProgress;
string signalName = "ExitShort_" + BarsInProgress;
ExitShort(BarsInProgress, Positions[BarsInProgress].Quantity, signalName, fromEntrySignalName);
}
}
27/02/2025 12:34 Default Disabling NinjaScript strategy 'DTPStrategy/351610424' 27/02/2025 12:34 Order S1Feb2611109553, Rejected at RMS - Total sell quantity of contract would exceed its limit affected Order: Sell 4 Market 27/02/2025 12:34 Default Strategy 'DTPStrategy/351610424' submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself. 27/02/2025 12:34 Order Order='277567078/S1Feb2611109553' Name='ExitLong_0' New state='Rejected' Instrument='MES 03-25' Action='Sell' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='Rejected at RMS - Total sell quantity of contract would exceed its limit' 27/02/2025 12:34 Order Order='0de1bbd047854c48bd056916af15ddf4/S1Feb2611109553' Name='ExitLong_0' New state='Submitted' Instrument='MES 03-25' Action='Sell' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:34 NinjaScript NinjaScript strategy 'DTPStrategy/351610424' submitting order 27/02/2025 12:21 Order Order='277565883/S1Feb2611109553' Name='Profit target' New state='Working' Instrument='MES 03-25' Action='Sell' Limit price=6013 Stop price=0 Quantity=4 Type='Limit' Time in force=GTC Oco='1479836|277565881|277565881' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='277565883/S1Feb2611109553' Name='Profit target' New state='Accepted' Instrument='MES 03-25' Action='Sell' Limit price=6013 Stop price=0 Quantity=4 Type='Limit' Time in force=GTC Oco='1479836|277565881|277565881' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='277565882/S1Feb2611109553' Name='Stop loss' New state='Accepted' Instrument='MES 03-25' Action='Sell' Limit price=0 Stop price=5983 Quantity=4 Type='Stop Market' Time in force=GTC Oco='1479836|277565881|277565881' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='c0b1ddfa14774b1989225040658d25c7/S1Feb2611109553' Name='Profit target' New state='Submitted' Instrument='MES 03-25' Action='Sell' Limit price=6013 Stop price=0 Quantity=4 Type='Limit' Time in force=GTC Oco='1479836|277565881|277565881' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='82bf5cc5918a4c41b6c9a19226a19f97/S1Feb2611109553' Name='Stop loss' New state='Submitted' Instrument='MES 03-25' Action='Sell' Limit price=0 Stop price=5983 Quantity=4 Type='Stop Market' Time in force=GTC Oco='1479836|277565881|277565881' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 NinjaScript NinjaScript strategy 'DTPStrategy/351610424' submitting order 27/02/2025 12:21 NinjaScript NinjaScript strategy 'DTPStrategy/351610424' submitting order 27/02/2025 12:21 Execution Execution='1479836|277565881|277565881' Instrument='MES 03-25' Account='S1Feb2611109553' Exchange=Globex Price=6008 Quantity=4 Market position=Long Operation=Operation_Add Order='277565881' Time='2/27/2025 12:21 ' 27/02/2025 12:21 Order Order='277565881/S1Feb2611109553' Name='EnterLong_0' New state='Filled' Instrument='MES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=4 Fill price=6008 Error='No error' Native error='' 27/02/2025 12:21 Position Instrument='MES 03-25' Account='S1Feb2611109553' Average price=6008 Quantity=4 Market position=Long Operation=Operation_Add 27/02/2025 12:21 Order Order='277565881/S1Feb2611109553' Name='EnterLong_0' New state='Working' Instrument='MES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='277565881/S1Feb2611109553' Name='EnterLong_0' New state='Accepted' Instrument='MES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 Order Order='cb53fa9d4bf743008a7b4ceb45a5918c/S1Feb2611109553' Name='EnterLong_0' New state='Submitted' Instrument='MES 03-25' Action='Buy' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error='' 27/02/2025 12:21 NinjaScript NinjaScript strategy 'DTPStrategy/351610424' submitting order 27/02/2025 12:15 Default Enabling NinjaScript strategy 'DTPStrategy/351610424' : On starting a real-time strategy - StartBehavior=WaitUntilFlat 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

Comment