Announcement

Collapse
No announcement yet.

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 bootize, Yesterday, 08:37 AM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Newtrader101, 06-17-2020, 11:01 AM
          11 responses
          52 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by TradingLoss, Today, 04:39 PM
          13 responses
          194 views
          1 like
          Last Post ibemeubu  
          Started by localappleseed, Today, 02:41 PM
          0 responses
          11 views
          1 like
          Last Post localappleseed  
          Started by kschuble, Today, 01:16 PM
          2 responses
          15 views
          0 likes
          Last Post kschuble  
          Working...
          X