• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Function for Errors Handling

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

    Stop Function for Errors Handling

    Hello, I have a stop function I am working on for error handling. It is copied below. The purpose of this code is to exist any working orders and also cancel any pending orders, then I throw a flag(haltProcessing = true which I poll in onbarupdate, and return; if true(thus stopping the code from running).

    In my main code (onbarupdate), I create my long and short orders by using this code:
    entryShortOrder1 = EnterShort(numcontracts, "target1short");
    entryLongOrder1 = EnterLong(numcontracts, "target1long");

    My question is, is my logic and syntax correct?



    private void StopStrategy()
    {
    if (entryLongOrder1 != null){
    CancelOrder(entryLongOrder1);
    }
    if (entryShortOrder1 != null){
    CancelOrder(entryShortOrder1);
    }

    // If we have a position we will need to close the position
    if (Position.MarketPosition == MarketPosition.Long)
    {
    entryLongOrder1 = ExitLong("target1long");
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    entryShortOrder1 = ExitShort("target1short");
    }

    haltProcessing = true;
    }//end stopstrategy

    #2
    Hello ktmdave,

    Your logic and syntax should be good.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by hobah99, Today, 04:12 PM
      0 responses
      3 views
      0 likes
      Last Post hobah99
      by hobah99
       
      Started by arguru, Today, 04:07 PM
      0 responses
      6 views
      0 likes
      Last Post arguru
      by arguru
       
      Started by Abdullah_KSA, Yesterday, 12:52 PM
      6 responses
      41 views
      0 likes
      Last Post NinjaTrader_ChristopherD  
      Started by ZivGillat, 06-29-2020, 11:47 AM
      4 responses
      29 views
      0 likes
      Last Post ZivGillat  
      Started by NinjaTrader_PaulH, Today, 01:48 PM
      0 responses
      9 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X