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

mixing two strategies X EntriesPerDirection

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

    mixing two strategies X EntriesPerDirection

    I ve mixed two strategies in one script. However, when testing it, I see that there is a unwanted interaction taking place. As I see it, there must be something related to EntriesPerDirection.
    How can I let two different logics (algos inside my strat) trigger order. e.g. The strategy is long 2 contracts and due to the other strat buys 1 more..
    In case I allow EntriesPerDirection = 2, one strategy can generate 2 buy orders, and that is not what I want. I want to let each strat generates 1 entry.
    How can I manage EntriesPerDirection that way?

    #2
    Hello dafonseca, and thank you for your question.

    In order to do what you are describing, you will need to set EntriesPerDirection to the total number of entries your strategy will manage - in your case too - and then use flags that are stored outside your OnBarUpdate method. Here is some sample code which can get you started.

    Code:
    [FONT=Courier New]IOrder trade1, trade2;
    protected override void OnBarUpdate()
    {
        bool trade1Condition = false;
    
        if (trade1Condition && trade1 == null)
        {
            trade1 = EnterLong();
        }
    }[/FONT]
    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      I am following you.
      One question:

      let me remake my question..
      i just want to differentiate trade 1 from trade2 on execution().
      Can you inform me if when a Stop order were triggered on trade1 how can I choose between trade1 and trade 2 OnExecution()?

      if (execution.Order != null && (execution.Name == "Stop loss") && ......................)
      {
      carrytrade1long == false;
      }
      the problem is: both stop loss has the same name "Stop loss". if i could get the entry name from the execution() would be fine, but I cant.
      As I ve tested I cannot access IOrder object properties inside OnExecution(), can I?
      Last edited by dafonseca; 10-04-2016, 05:29 PM.

      Comment


        #4
        Provided you defined your IOrder objects outside of any method - as you can see in the example, the ones I posted are defined outside of OnBarUpdate - then you'll be able to access objects like trade1 and trade2 in any method including OnExecution. You will therefore be able to e.g.

        Code:
        [FONT=Courier New]if (execution.Order == trade1 && execution.Order != null)
        [/FONT]
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        8 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        385 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X