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 Brevo, Today, 01:45 AM
              0 responses
              3 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              3 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              239 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              384 views
              1 like
              Last Post Gavini
              by Gavini
               
              Started by oviejo, Today, 12:28 AM
              0 responses
              6 views
              0 likes
              Last Post oviejo
              by oviejo
               
              Working...
              X