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 alexstox, 10-16-2018, 03:29 PM
                11 responses
                342 views
                0 likes
                Last Post aligator  
                Started by ageeholdings, 05-01-2024, 05:22 AM
                6 responses
                43 views
                0 likes
                Last Post ageeholdings  
                Started by tony_28217, Today, 07:04 PM
                0 responses
                11 views
                0 likes
                Last Post tony_28217  
                Started by flybuzz, Today, 10:33 AM
                1 response
                9 views
                0 likes
                Last Post flybuzz
                by flybuzz
                 
                Started by spencerp92, 10-10-2023, 09:56 AM
                4 responses
                311 views
                0 likes
                Last Post flybuzz
                by flybuzz
                 
                Working...
                X