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

Reverse

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

    Reverse

    Hello,

    I am trying to build a code for a reverse that occurs only if the algorithm enter one bar after the trigger and, in the same bar, it hits the stop. I can set up the reverse but I and not sure how to identify which way the reverse is once the market fills the stop orders.

    if (barNumberOfLongEntries != 0)
    if ( barNumberOfLongEntries == 1 && BarsSinceExitExecution() == 0)

    WOuld you help me please?

    #2
    Hello Jorge.andres.o,

    Thanks for your post.

    When you are in a position you could set a bool variable that you create that would be the direction of the last order.

    if (Position.MarketPosition == MarketPosition.long)
    {
    myLong = true; // myLong is a bool you would create
    myShort = false; // myshort is a bool you would create
    }

    if (Position.MarketPosition == MarketPosition.Flat && (your other conditions to reverse) && myLong == true)
    {
    EnterShort(); // reverse direction from lonng.
    myLong = false;
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello Jorge.andres.o,

      Thanks for your post.

      When you are in a position you could set a bool variable that you create that would be the direction of the last order.

      if (Position.MarketPosition == MarketPosition.long)
      {
      myLong = true; // myLong is a bool you would create
      myShort = false; // myshort is a bool you would create
      }

      if (Position.MarketPosition == MarketPosition.Flat && (your other conditions to reverse) && myLong == true)
      {
      EnterShort(); // reverse direction from lonng.
      myLong = false;
      }
      Hi Paul,

      if I may add something, IMO, when reversing, there is no need to have Market = Flat before Enter. One just needs to have e.g. EnterSort conditions to be true in order to Enter Short directly from his Long Posistion (and vice versa). Unless, if he wants to avoid usage of double margin, then, yes, he may demand Market=Flat and then go Short . In the latter case, and in order to reduce some delay (if he has COBC = true), he may add in his Enter ifs the : " ... && FirstTickOfBar ". Thanks.

      Comment


        #4
        Paul,

        Thank you very much!

        I already wrote the code but it is not working because of the following error:
        Strategy 'BankingWayV3x0x2ATRTicks2xEscalonOffSetRunnersRev ersaExtrema': Error on calling 'OnBarUpdate' method on bar 154: Strategy 'BankingWayV3x0x2ATRTicks2xEscalonOffSetRunnersRev ersaExtrema/207532070': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntryExecution() method in the context of a multi-time frame and instrument strategy.
        I have not been able to find a solution to it

        Comment


          #5
          Hello Jorge.andres.o,

          Thanks for your reply.

          The error is advising to use the overload of the method that allows you to specify the BarsInProgress index.
          From the help guide it would be this overload: BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo) Please see: https://ninjatrader.com/support/help...yexecution.htm


          So instead of () you would use something like (0,"",0) where the first 0 would be the BarsInProgress index to reference the BarsInProgress where the entry was made (if it was made on BarsInprogress 0, otherwise specify the specific BarsInProgress (Time frame) that the entry was made on).
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          11 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          7 views
          0 likes
          Last Post elirion
          by elirion
           
          Working...
          X