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 Haiasi, 04-25-2024, 06:53 PM
          5 responses
          76 views
          0 likes
          Last Post alancurry  
          Started by ZeroKuhl, Today, 04:31 PM
          0 responses
          16 views
          0 likes
          Last Post ZeroKuhl  
          Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
          54 responses
          5,337 views
          0 likes
          Last Post Gaterz
          by Gaterz
           
          Started by ETFVoyageur, 05-07-2024, 07:05 PM
          11 responses
          76 views
          0 likes
          Last Post -=Edge=-  
          Started by _Zero_, 04-10-2020, 03:21 PM
          145 responses
          7,902 views
          6 likes
          Last Post johng2
          by johng2
           
          Working...
          X