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

How to avoid crossed orders

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

    How to avoid crossed orders

    Today I started live trading and obviously orders got crossed.

    I tried to sell 1 fdax in order to close a position and exactly at the same second my strategy wanted to go short with a sell short order and due to overmargining an error was triggered and my strategy stopped :-((

    Can this situation be avoided by using the command:

    if (position.MarketPosition == MarketPosition.Flat)
    {
    <new entry>
    }
    ...

    thanks
    brima

    #2
    Yes, that would work.
    RayNinjaTrader Customer Service

    Comment


      #3
      And when exactly is the condition
      (position.MarketPosition == MarketPosition.Flat) true?

      as soon as the flattening order is
      a) PendingSubmitt
      b) Accepted
      c) Working
      d) Filled

      Comment


        #4
        As soon as the position is flat determined by incoming executions.
        RayNinjaTrader Customer Service

        Comment


          #5
          Does that mean as soon as an flattening order has category "Execution" in the log file?

          Comment


            #6
            brima,

            check my reply to a similar instance at

            mrlogik
            NinjaTrader Ecosystem Vendor - Purelogik Trading

            Comment


              #7
              Originally posted by brima View Post
              Does that mean as soon as an flattening order has category "Execution" in the log file?
              An order can be made up of multiple executions, but in concept your understanding is correct.
              RayNinjaTrader Customer Service

              Comment


                #8
                @mrlogik

                unfortunately I'm not working with the advanced order handling yet, my code is as follows:

                protected override void Initialize()
                {
                SetStopLoss(CalculationMode.Ticks, stoplossticks);
                CalculateOnBarClose = false;
                }

                protected override void OnBarUpdate()
                {
                #region ENTRY
                if ( (<EntryCondition == true>) & (Position.MarketPosition == MarketPosition.Flat))

                {
                EnterShort(1)
                or
                EnterLong(1)
                }
                #endregion

                #region EXIT
                if ( (<ExitCondition == true>) & (Position.MarketPosition != MarketPosition.Flat))
                {
                ExitShort(1)
                or
                ExitLong(1)
                }
                #endregion
                }

                Hopefully that makes sense and works fine now.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by helpwanted, Today, 03:06 AM
                1 response
                7 views
                0 likes
                Last Post sarafuenonly123  
                Started by Brevo, Today, 01:45 AM
                0 responses
                7 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                5 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                242 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
                 
                Working...
                X