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

"blending" trades

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

    "blending" trades

    Hello,
    I have certain trades in which I would like to change the exit conditions during the trade according to market conditions. So I have two trading ideas x & y. I enter a trade with idea x and price continues to move in my direction until the entry condition for idea y is triggered. Instead of a new entry I'd like to "blend" idea x into idea y and use idea y's exit conditions. Any suggestions on how that would be accomplished? Thanks.

    #2
    CaptainAmericaXX,

    Thank you for your post.

    If I am following you correctly, you should be able to accomplish this by using a different stop strategy with each condition.

    Here is some pseudo code to help you get started...

    if (MyXCondition)
    //doMyXExit

    if (MyYCondition)
    //doMyYExit

    As long as your Y condition is true, it will use the Y exit.
    MatthewNinjaTrader Product Management

    Comment


      #3
      So if I understand you correctly your saying that if I'm in x trade and the conditions for y become true, the y trade will not fire and the x trade exit conditions will be automatically disregarded in favor of the y exit?
      In my experience both trades will fire independently with the separate exit working as well. If there are unique names for the conditions one exit will not recognize the other.

      Comment


        #4
        CaptainAmericaXX,

        When you have both statements both are used. The logic would not be a "one or the other" type of logic. If you want one or the other you would need to use an if-else statement, not two if-statements like in Matthew's code.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          So I would need to say something like:
          if(x trade == true)
          Exit conditions
          else(x trade == true
          && y conditions == true)
          Exit(with y condition)
          is this correct?

          Comment


            #6
            Assuming you are going long...

            Code:
            // In variables section above Initialize()
            private bool useYExits = false;
            
            // In OnBarUpdate()
            if (x trade entry conditions == true)
                 EnterLong();
            
            if (Position.MarketPosition == MarketPosition.Long)
            {
                 if (y entry conditions == true)
                      useYExits = true;
            
                 if (useYExits == false && x exit conditions == true)
                      ExitLong();
                 else if (useYExits == true && y exit conditions == true)
                      ExitLong();
            }
            
            if (Position.MarketPosition == MarketPosition.Flat && useYExits == true)
                 useYExits = false;
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Sweet!
              Thanks Josh and thank you to everyone at NT. A year ago I had absolutely no clue how to program.(I"m still very green) The staff at NT has been a huge help to me. Thanks for everything! I don't know how else to send a "Thank you" card. I know I'll still need a lot of help before my ideas materialize, but I wanted to take a moment and thank you all.

              Comment


                #8
                You're welcome. Glad to be able to help.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by helpwanted, Today, 03:06 AM
                1 response
                11 views
                0 likes
                Last Post sarafuenonly123  
                Started by Brevo, Today, 01:45 AM
                0 responses
                9 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
                387 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Working...
                X