Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong gives 2 orders!

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

    EnterLong gives 2 orders!

    Code:
    ---------
    if (CrossAbove(SMA(5), SMA(10), 1))
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    EnterLong();
    else
    ExitShort();
    }
    if (CrossBelow(SMA(5), SMA(10), 1))
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    EnterShort();
    else
    ExitLong();
    }
    ---------



    This still does not work! When I run the script, even if I have a flat market position, if it crosses, I still get a "Sell Short" order AND a "Sell" order giving me 2 orders and twice the position. (or vice versa if they cross the other way. First it does a "Close Position", then another order to "Sell".

    If you look at what "EnterLong" actually means, (StrategyBase.EnterLong) , it means: "Enter a long position via a market order and close any open short positions"

    HELP!!!!!!!!!!! All I am trying to do is create a simple strategy that trades on the crossovers and it can't be that hard!!!!!!

    #2
    Please upload your strategy file and I can take a look at it for you. If your market position is flat there should be no reason for it to ever do a Close position order.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Please take a look at the SampleMACrossOver strategy.

      Comment


        #4
        I have a question on MarketPosition.

        Is the value of MarketPosition updated immediately upon an EnterLong, EnterShort, etc. being done?

        Or is it changed only after receiving a response back from the exchange saying the order has been filled?

        If the latter, there may be problems in the logic of automated strategies.

        In either case, it would be very nice if this information were reflected in the Help documentation under EnterLong, EnterShort, etc, and under MarketPosition.

        KBJ

        Comment


          #5
          As far as I can tell it reflects you current filled position, not your target position.

          Therefore I usually have my own position variables that keep track of my intended target position between bar updates regardless of fills.

          Comment


            #6
            >> Or is it changed only after receiving a response back from the exchange saying the order has been filled?
            Correct, only as the position has been established. NT works of real positions unlike e.g. TS where positions are "virtual".

            Comment


              #7
              So, since MarketPosition is only set once an order has been filled, it would be possible for more than one bar to elapse for the example in the original post before the MarketPosition no longer had a value of "flat", so it would be possible for that example to kick off multiple trades, whether intended or not.

              Therefore, strategies must be implemented in such a way that they take steps to limit the number of trades they enter.

              One way to do this, of course, would be to set "EntriesPerDirection=1" in the Initialize() method.

              Comment


                #8
                Not sure I follow: As you pointed out the numbers of trades is determined by EntriesPerDirection=1 (default), meaning there only can be 1 signal triggered at a time. Only as the position gets flat again a new signal (and only 1!) could be triggered again.

                Comment


                  #9
                  Originally posted by NinjaTrader_Dierk View Post
                  Not sure I follow: As you pointed out the numbers of trades is determined by EntriesPerDirection=1 (default), meaning there only can be 1 signal triggered at a time. Only as the position gets flat again a new signal (and only 1!) could be triggered again.
                  I'd forgotten that it defaulted to "1". This is because I downloaded a strategy that someone else had written where they had programatically set this value to "5", and I've been working with that recently, so I've been accustomed to seeing it as "5" when invoking it in the StrategyAnalyzer.

                  So, of course, you're right: lacking the explicit code in the Initialize() method to set EntriesPerDirection to some value this should not be a consideration.

                  Comment


                    #10
                    Thanks for clarification.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    597 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    343 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    103 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    556 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    555 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X