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 Rapine Heihei, Today, 08:19 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 08:25 PM
                0 responses
                3 views
                0 likes
                Last Post Rapine Heihei  
                Started by f.saeidi, Today, 08:01 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 07:51 PM
                0 responses
                6 views
                0 likes
                Last Post Rapine Heihei  
                Started by frslvr, 04-11-2024, 07:26 AM
                5 responses
                96 views
                1 like
                Last Post caryc123  
                Working...
                X