Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order quantity on startup

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

    Order quantity on startup

    I have written a stratgey that increments the entry order quantity after each losing trade (up to a limit) and resets it to 1 after a winning trade. The quantity is initialised to 1 in Initialize().

    In running the strategy live, when the strategy is initially started up, instead of the order quantity being 1 it is whatever it should be had the strategy been running live for a considerable time. This surprised me. Is this expected behaviour? Can I modify this behaviour so that it always starts with an order quantity of 1 no matter when the strategy starts running?

    Thanks.

    #2
    annettes, what code are you using to set the initial quantity? You can also try setting these values when CurrentBar = 0 to be sure the value is reset.
    AustinNinjaTrader Customer Service

    Comment


      #3
      I am simply setting the variables to a startup value in Initialize() , i.e.:
      Variable0 = 0;
      Variable1 =
      1;
      Variable2 =
      0;

      I tried inserting the following into OnBarUpdate() but it didn't make any difference:
      if (CurrentBar == 0)
      {
      Variable0 =
      0;
      Variable1 =
      1;
      Variable2 =
      0;
      }

      Do you have any other suggestions? I am using NinjaTrader 6.5.
      Thanks.

      Comment


        #4
        If you start the strategy, how do you set order qty for it by? If you want to set it programmatically ensure this is set to ByStrategy and not ByDefaultQuantity.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Yes, I am definitely using By Strategy to set the order quantity. It sounds like what is happening is not expected behaviour. I will attach the code so you can have a look at it.
          Thanks,
          Annette
          Attached Files

          Comment


            #6
            Seems to work as expected here as far as the strategy driving the size dynamically, this is the size used in the last 10 days on ES March - if you feel this is not correct, you would need to debug your position sizing logic in the code :

            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 2
            PosSize 2
            PosSize 2
            PosSize 3
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            PosSize 1
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I think I have worked out what the problem is. I am checking the value of Performace.AllTrades.Count, which will include all of the historical backtest trades, not just the live trades. If I use Performace.RealtimeTrades.Count, my strategy will work when running live, but not when backtesting. Is there some way for a strategy to determine what mode it is in (i.e. backtest or live) or what account it is trading?
              Thanks.

              Comment


                #8
                annettes, for the executed to account you could look into the (unsupported) Account.Name property for checks...for the backtest vs realtime conditions you can work with Historical, it will return false if running realtime for example.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, Today, 09:30 AM
                2 responses
                11 views
                0 likes
                Last Post bltdavid  
                Started by f.saeidi, Today, 11:02 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by geotrades1, Today, 10:02 AM
                4 responses
                12 views
                0 likes
                Last Post geotrades1  
                Started by rajendrasubedi2023, Today, 09:50 AM
                3 responses
                16 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by lorem, Today, 09:18 AM
                2 responses
                11 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X