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

EnterLong twice

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

    EnterLong twice

    I would appreciate it if you can help me out with the following because they way that I have it doesn't seem to work:
    * If Condition A then Enter Long
    * If Condition B then Enter Long
    I would still want Codition B to execute even when Condition A is currently true or when both, Condition A and Condition B become true at the same time.
    For instance:
    Case #1) If Condition A then buy 1 contract. Condition B is never true. Exit Long 1 contract.
    Case #2) If Condition A then buy 1 contract., then Condition B is true, buy 1 contract. Exit Long 2 contracts.
    Case #3) If Condition A and Condition B become true at the same time, buy 1 contract for Condition A and 1 contract for Condition B. Exit Long 2 contracts.
    Case #4) If Condition B then buy 1 contract. Condition A is never true. Exit Long 1 contract.

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
                    {                
                        if (Condition A)
                        {                        
                            EnterLong();
                        }                
                    }
                                  
        if (Condition B)
                        {                        
                            EnterLong();
                        }                
                    
    if (Position.MarketPosition == MarketPosition.Long)
                    {
                        if(Condition X)
                        {
                            ExitLong();
                        }                    
                    }

    #2
    Originally posted by 2Look4me View Post
    I would appreciate it if you can help me out with the following because they way that I have it doesn't seem to work:
    What doesn't seem to work? You don't get 2 entries? What is your EntriesPerDirection set to? 1? It should be on 2 if you want 2 long entries of 1 contract each.

    Comment


      #3
      Hello 2Look4me,

      Thank you for your note.

      To accomplish this either in the State.SetDefaults) or when applying the strategy you should set entries per direction to 1 and set EntryHandling to UniqueEntries. This will allow you to have condition A and B submit entry orders.

      See EntriesPerDirection section of our Helpguide,


      See EntryHandling,


      For example,

      Code:
      if (Condition A)
                          {                        
                              EnterLong(“LongA);
                          }        
      
      if (Condition B)
                          {                        
                              EnterLong(“LongB);
                          }        
      
      if(Condition X)
                          {
                              ExitLong();
                          }
      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Hi Alan,

        So once I have:
        Code:
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.UniqueEntries;
        Will I still need as part of the script
        Code:
        if(Position.MarketPosition == MarketPosition.Flat)
        for entries and
        Code:
        if(Position.MarketPositon == MarketPosition.Long)
        for exits?

        Comment


          #5
          Thank you for your question 2Look4me. While the call to check if you are in a flat position before entering a long position is not necessary to ensure you only enter one contract in the long direction, the check to see if you are already in a long position before exiting a long position is necessary to avoid an EnterLong and ExitLong call in the same loop. Because the second call is necessary, and because the first call will make your code more flexible in the future by decoupling your entry logic from your EntriesPerDirection setting, I would recommend keeping both calls.
          Jessica P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mongo, Today, 11:05 AM
          4 responses
          14 views
          0 likes
          Last Post Mongo
          by Mongo
           
          Started by traderqz, Today, 12:06 AM
          7 responses
          14 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Skifree, Today, 03:41 AM
          5 responses
          13 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by traderqz, Yesterday, 09:06 AM
          5 responses
          35 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by guillembm, Today, 11:25 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X