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

Newbie question - Reverse Positions

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

    Newbie question - Reverse Positions

    I used the strategy wizard to create a template strategy and now trying to customize the strategy.

    In essence, this is what I am trying to do.

    If (Condition 1 that should trigger a long)
    EnterLong
    ExitShort

    if (Condition 2 that should trigger a short)
    EnterShort
    ExitLong

    The problem is I dont know how to check whether I have an active position to Exit (long or short). If I run it as above, an extra order is created.

    Also, would appreciate if there is any "initialize" actions that I should do when the strategy starts.

    #2
    Hello,

    Thank you for the question.

    You can add additional checks to your current conditions to check your position.

    You can do this by doing the following in the condition builder:

    On the left side
    Strategy -> Current Market Position
    In the center choose the according operator or == for example.
    On the right side
    Strategy -> Flat

    This would be saying if the current position is flat, allow the condition to happen.

    I look forward to being of further assistance .
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the information.

      From what I understand, this checks whether there is any open position. What I was looking for is a nested condition as shown in the bold below.

      If (Condition 1 that should trigger a long)
      EnterLong
      if there is an open short position,
      ExitShort


      if (Condition 2 that should trigger a short)
      EnterShort
      if there is an open long position,
      ExitLong

      Comment


        #4
        Hello,

        Thank you for the reply.

        In the wizard there is no way to create nested conditions, this would be something you need to unlock and manually code.

        You can create additional condition sets using the position check for this or you can use user variables like bool values to add additional depth to your conditions.

        For example you could set user variable 0 to a value of 1 when you enter long, and then in another set check if user variable 0 == 1 and also check if you are long and if so then exit. this would ensure you are in a position and the order had been filled. you would also need to set the variable back to 0 after the exit to ensure this loop could happen again.

        This would really be the only way to add additional depth using the wizard.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse.

          A nested condition was not really needed I think using the && option would have worked. Just added more conditions.

          Appreciate the pointer.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jpeep, 08-16-2020, 08:31 AM
          13 responses
          485 views
          0 likes
          Last Post notenufftime  
          Started by realblubb, 04-28-2024, 09:28 AM
          2 responses
          32 views
          0 likes
          Last Post realblubb  
          Started by bmarovets, Today, 06:33 PM
          0 responses
          9 views
          0 likes
          Last Post bmarovets  
          Started by ETFVoyageur, Yesterday, 07:05 PM
          4 responses
          36 views
          0 likes
          Last Post ETFVoyageur  
          Started by JGriff5646, Yesterday, 10:02 PM
          2 responses
          24 views
          0 likes
          Last Post JGriff5646  
          Working...
          X