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

closing and opening in the same bar...

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

    closing and opening in the same bar...

    Hi,

    I am having trouble when I try to flat a trade and open another right after.
    I´m using my inside strategy:
    CalculateOnBarClose = true;

    protected override void OnBarUpdate()
    {
    ...

    if( ............)
    {
    ExitLong(Position.Quantity);
    EnterShort(QT);
    }

    The trade is never seems to open the correct QT .

    I think with the problem is that I am closing the trade and opening the other in the same bar, do you think that is whats causing the error? If it is, how I do to close and open correctly ?

    Kind regards

    #2
    Originally posted by ocorrea View Post
    Hi,

    I am having trouble when I try to flat a trade and open another right after.
    I´m using my inside strategy:
    CalculateOnBarClose = true;

    protected override void OnBarUpdate()
    {
    ...

    if( ............)
    {
    ExitLong(Position.Quantity);
    EnterShort(QT);
    }

    The trade is never seems to open the correct QT .

    I think with the problem is that I am closing the trade and opening the other in the same bar, do you think that is whats causing the error? If it is, how I do to close and open correctly ?

    Kind regards
    Are you talking about this in Strategy Analyzer ?

    Comment


      #3
      Hello ocorrea,

      Thank you for your post.

      As koganam asked, are you using this in real-time data or through backtesting in the Strategy Analyzer?

      What quantity are you seeing? What quantity is expected?

      If you use only the EnterShort() and not the ExitLong() does the correct quantity get entered short?

      Comment


        #4
        Sorry for the delay in response.

        I'm using this in real-time data.

        The quantity of ExitLong depends on what has already been done. It can be 8, for example. But in EnterShort() quantity (QT) should be 10, but the entrance is always greater.

        Comment


          #5
          Hello ocorrea,

          Thank you for your response.

          You can just use EnterShort(QT);, this will close the current position and then open you for the value of QT short.

          Comment


            #6
            Thanks for replay, but it is that I´m doing.

            I did not mention early, but I am using:

            Period.Type.Tick, 30;
            ExitOnClose = true;
            EntriesPerDirection = 1;

            See a snippet of my routine:

            //
            // -----------------------------------------------------------------------
            // Rotina 3 - Reverte Trade
            // - se comprado, sai da compra entra na venda,
            // - se vendido, sai da venda entra na compra
            //
            private int ReverteTrade(int Side)
            {
            if(LxP < 0.0 && Trig1 == 0) // esta com Prejuizo e ñ atingiu Stop
            {
            if(Side == 1)
            {
            if(CkInVD() > 0)
            {
            ExitLong(Position.Quantity);
            ZeraTrade(); // sets condition for entry
            EnterShort(QT);
            return(Side);
            }
            }
            else
            {
            if(CkInCP()>0)
            {
            ExitShort(Position.Quantity);
            ZeraTrade(); // sets condition for entry
            EnterLong(QT);
            return(Side);
            }
            }
            }
            return(Side);
            }

            The whole Strategy is in the attached file.
            Attached Files

            Comment


              #7
              Hello ocorrea,

              Thank you for your response.

              Remove the Exit() methods from your method. Test again without the Exit() methods.

              Enter() methods will reverse your position without the need for the Exit() method.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kujista, Today, 12:39 AM
              0 responses
              2 views
              0 likes
              Last Post kujista
              by kujista
               
              Started by tonynt, 05-21-2019, 06:27 AM
              11 responses
              534 views
              1 like
              Last Post NinjaTrader_Jason  
              Started by fitspressotablettry, Today, 12:36 AM
              0 responses
              1 view
              0 likes
              Last Post fitspressotablettry  
              Started by Lancer, 01-29-2020, 10:15 PM
              7 responses
              468 views
              1 like
              Last Post NinjaTrader_Jason  
              Started by gravdigaz6, Today, 12:05 AM
              0 responses
              1 view
              0 likes
              Last Post gravdigaz6  
              Working...
              X