Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug to report with Switch Statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bug to report with Switch Statement

    Code
    Code:
     protected override void OnExecutionUpdate(Cbi.Execution execution,string executionId,double price,int quantity,Cbi.MarketPosition marketPosition,string orderId, DateTime time) {
    if (PrintDetails) Print(string.Format("{0} | OEU | execution | {1} | {2}", Times[1][0], time, execution.ToString()));
    if (execution.Order.OrderState != OrderState.Filled) return;
    PrintTo = PrintTo.OutputTab2;
    
    switch (Position.MarketPosition){
    case MarketPosition.Long :
    Print("switch (Position.MarketPosition) case MarketPosition.Long: )=============================>TRUE");
    break;
    }
    
    if (Position.MarketPosition == MarketPosition.Long) {
    Print("if (Position.MarketPosition == MarketPosition.Long)=============================> TRUE");
    }
    
    ///For reference private Cbi.MarketPosition marketposition;
    if (Position.MarketPosition == MarketPosition.Short) {
    Print("if (Position.MarketPosition == MarketPosition.Short)============================= >TRUE");
    }
    
    switch (Position.MarketPosition){
    case MarketPosition.Long :
    Print("switch2 (Position.MarketPosition) case MarketPosition.Long: )=============================>TRUE");
    break;
    }
    
    
    switch (marketposition) {
    case MarketPosition.Flat : //Nothing todo
    break;
    case MarketPosition.Long :
    Print("switch (marketposition) case MarketPosition.Long: )=============================>TRUE");

    Output Tab2

    if (Position.MarketPosition == MarketPosition.Short)============================= >TRUE
    switch (marketposition) case MarketPosition.Long: )=============================>TRUE
    OnExecutionUpdate() MarketPosition.Long StopLossLong=12815.5 GetCurrentAsk(0)=12871.75 SafePriceDiff=0.75
    5/5/2022 9:05:00 PMOnExecutionUpdate() SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, StopLossLong, ocoString, stop loss GetCurrentAsk=12871.75 GetCurrentBid=12871
    CheckPNL() InTrade SHORT Position.AveragePrice=[12871]
    if (Position.MarketPosition == MarketPosition.Short)============================= >TRUE
    switch (marketposition) case MarketPosition.Long: )=============================>TRUE
    Strategy 'ABC_OEU_Trail_3/264341573' submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    Disabling NinjaScript strategy 'ABC_OEU_Trail_3/264341573'
    OnExecutionUpdate() MarketPosition.Long StopLossLong=12815.5 GetCurrentAsk(0)=12871.75 SafePriceDiff=0.75
    5/5/2022 9:00:00 PMOnExecutionUpdate() SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, StopLossLong, ocoString, stop loss GetCurrentAsk=12871.75 GetCurrentBid=12871
    if (Position.MarketPosition == MarketPosition.Short)============================= >TRUE
    switch (marketposition) case MarketPosition.Long: )=============================>TRUE
    OnExecutionUpdate() MarketPosition.Long StopLossLong=12815.5 GetCurrentAsk(0)=12871.75 SafePriceDiff=0.75
    5/5/2022 9:05:00 PMOnExecutionUpdate() SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, StopLossLong, ocoString, stop loss GetCurrentAsk=12871.75 GetCurrentBid=12871
    CheckPNL() InTrade SHORT Position.AveragePrice=[12871]
    if (Position.MarketPosition == MarketPosition.Short)============================= >TRUE
    switch (marketposition) case MarketPosition.Long: )=============================>TRUE
    Strategy 'ABC_OEU_Trail_3/264341573' submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    Disabling NinjaScript strategy 'ABC_OEU_Trail_3/264341573'
    OnExecutionUpdate() MarketPosition.Long StopLossLong=12815.5 GetCurrentAsk(0)=12871.75 SafePriceDiff=0.75
    5/5/2022 9:00:00 PMOnExecutionUpdate() SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, StopLossLong, ocoString, stop loss GetCurrentAsk=12871.75 GetCurrentBid=12871

    #2
    Hello BartMan,

    Are you saying that the C# branching command 'switch' distributed by Microsoft has a bug?

    What is the bug?


    Also, if you are intending to print the market position, be sure to do this outside of any conditions.

    Print(string.Format("{0} | Position.MarketPosition: {1}", Time[0], Position.MarketPosition));

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Not sure what was going on, I pulled the switch statement into a stand alone new strategy and it works just fine.

      SwitchVsIf.zip
      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X