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

Ninjascript Strategy returning wrong order?

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

    Ninjascript Strategy returning wrong order?

    When I set up a simple strategy to buy on a crossover and sell on a crossunder (and it doesn't get much simpler than that), it always fills twice the number of lots??? As an example, if the crossover triggers a buy order of one lot, it submits two orders..... (1) Buy to Cover and (2) Buy! This nets a "Position" of 2 lots??? Can anyone tell me why?????

    #2
    This is correct.

    If you are short and then you call EnterLong(), NT will send an BuyToCover for 1 lot to close the short and then send a buy order for 1 lot to open the long position.

    Your strategy position will net the correct amount, which is 1 long.
    RayNinjaTrader Customer Service

    Comment


      #3
      For further clarification.

      When you run your strategy, it will calculate its current "strategy" position. Lets say its 1 lot long. Should your actual account position be flat, you have the option (most would do this) to synchronize your account position to your strategy position. In this case, you could enter a buy order to get your account position in sync with your strategy.
      RayNinjaTrader Customer Service

      Comment


        #4
        I continue to have a problem with strategy fills?? I have created a nice system, but occasionally, here is what happens. If I have an order to go long when my conditions are met with an "enterlong", everthing is great until it reverses before kicking in and hits the "exitlong" first. Here is basically how it looks......


        protected override void OnBarUpdate()
        {
        // Condition set 1
        if condition is satisfied
        {
        EnterLong(DefaultQuantity,"");
        }


        // Condition set 2
        if ((exit Condition is met))
        && (Position.MarketPosition == MarketPosition.Long)))
        {
        ExitLong("");

        What happens is that I end up short a position if the condition 2 is met, even though I have the (Position.MarketPosition == MarketPosition.Long) in there.

        I had this happen, so "flattened" everythin via the "File" menu in the control center, closed down the chart, and reopened it with a fresh strategy and it happened again??? Any idea why?????

        Comment


          #5
          Without seeing the exact rendition of code you have I do not know what is wrong, but this is a potential cause of problems on what you have posted:

          if ((exit Condition is met)) <-- that already closed the if-statement. the whole &&... isn't part of the if-condition.
          && (Position.MarketPosition == MarketPosition.Long)))
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I figured it out Josh. I had the

            if (Historical)
            return;

            in the wrong place. I had it below the protected override void Initialize instead of below the protected override void OnBarUpdate. I think that solved it.

            As always, thanks!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottWalsh, Today, 04:29 PM
            0 responses
            3 views
            0 likes
            Last Post ScottWalsh  
            Started by rtwave, 04-12-2024, 09:30 AM
            2 responses
            21 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            5 responses
            69 views
            0 likes
            Last Post tsantospinto  
            Started by cre8able, Today, 03:20 PM
            0 responses
            7 views
            0 likes
            Last Post cre8able  
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            49 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Working...
            X