Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Tim-c, Today, 03:54 AM
      0 responses
      1 view
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by FrancisMorro, Today, 03:24 AM
      0 responses
      2 views
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,770 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      31 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      945 views
      0 likes
      Last Post spwizard  
      Working...
      X