Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Starting automated trading strategy in the middle of the day

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

    Starting automated trading strategy in the middle of the day

    Does anyone out there actually use Ninja ATI for real live trading starting in the middle of a day? or at all?
    If so, how do you configure it to start without the problems I see?

    I`d like to run ATI strategies on my real brokerage account using Ninja Trader. But the way automated trading works in sim mode, I don`t think I can. What am I missing?

    The strategy in this example backtests fine, the results backtest shows are identical to trading it manually looking at the chart. I`d like to have Ninja autotrade this strategy for me. But when I start the strategy (from control center) in live market in sim mode (I assume it would do the same with my live brokerage account) it does not do what I expect. At all.

    This strategy "entries per direction" is set to 10. When I start the strategy from control center no matter what I do, it establishes the "virtual strategy position" ( I`ve read, that`s what it supposed to do)
    Why would anyone want that to happen? It totally screws up everything that follows.
    Example:
    On the start, the strategy position becomes, lets say, 8 long (account position 0). Then later in the day (a buy) strategy condition occurs in the market so the strategy buys, of course. The condition is met 10 more times later but since strategy position was "virtual" 8 already, it only buys twice (as in up to the 10 entries per direction). Now I have strategy position of 10L, but account position only 2L. That`s all the strategy will buy. So in essence I will NEVER see 10L (in this case) in my real account position if I start the strategy in the middle of a day.
    Then the flip side of the the same strategy kicks in. It sells the Long position and starts to accumulate/enter short (up to same 10 times). Few hours into the day it really gets bizarre. Strategy position becomes 1Long, real account position became 14Short at the same time (see the screen shots attached).
    Is this what would happen to my real brokerage account????
    All that due to the fact the strategy started with "virtual position" of 8 contracts long.
    And no, I do not want to buy the 8 contracts manually for the real account just to make the strategy "happy" and match the positions on the start. The price at that time is not what I wanna buy at, and it is before the time I want it to start trading anyway (as "minimum bars required" is set to start real trading much later).

    The only case when automated trading runs fine is when I start a strategy at the beginning of a session (12:01am) using just this (one) day for the data on the chart (so the strategy has no back data to establish "virtual position" of anything other than ZERO, as it only has 1 minute worth of back data on the start) and allow the strategy to trade market hours I DO NOT want to trade. OR set "minimum bars required" to 36 for 5 min chart to make it start actual trading at 4am. which is when I want it to start trading. In either case this means I can`t go to sleep but must wait for 12:01am to start the strategy.
    If I start it later in the day, even if I set "session times" to start and end AFTER the current time of day, set the chart times the same way, and set "minimum bars required" to start later, when I press the start button there comes strategy position of 3 or 8 or whatever contracts, the "virtual position".

    I have read the help and the support forum, and to this day I have no idea how to start a strategy with starting strategy position of zero other than right after midnight.

    So, Can it be done? Is there a way to start a strategy in the middle of a day with "strategy position" at ZERO?
    How and when would you recommend I start my strategy so it would start with strategy position at zero?
    What is a reason for a strategy to establish "virtual position" on the start? What is an advantage of having that happen? there must be at least one, or it wouldn`t be logical to have the "virtual position" in the first place as it screws up everything else afterwords.
    What am I missing here?

    Suggestion for Ninja:
    The strategy should start at the time I click the start button and work from that point in time forward. Not backwards. WITH the starting "virtual strategy position" at ZERO regardless of the time of day I started it, until a buy or a sell strategy condition is met for the first time in the future upon which the strategy does what it was told to do. That would be logical.

    thanks
    Attached Files

    #2
    Hello lesbud,

    Please note that you can expect differences when backtesting a strategy compared to running it on live data in simulation. See the link below for more information.


    When you apply the strategy in the chart, it will be calculated on on all historical data available. It will calculate historical orders as well, which can have a strategy position as result. Please see the link below for more information.


    You can enable 'Wait until flat before executing live' at Tools-->Options-->Strategies-->NinjaScript-tab. The strategy will wait with submitting orders until the strategy position is flat.

    In addition, you could also include the following statement in your code to avoid the strategy to be calculated on historical data.

    // Only run on real-time data
    if (Historical)
    return;

    Add the statement at the top of OnBarUpdate()

    I will forward your suggestion to our development team and ask them if they can add this to the list of future considerations for the software.
    JasonNinjaTrader Customer Service

    Comment


      #3
      I was familiar with the info in the links you provided.

      I`m not a programmer so I tried this to insert what you provided. First renamed the strategy to find it later, then,
      1. unlock the code for the strategy I`m using
      2. find OnBarUpdate ()
      3. copy and paste your text there
      4. closed the window
      5. save the changes to strategy xxxx window pops out
      6. clicked yes

      it looks like this, but when I try to start this strategy it is not listed in the choices, even though it is listed in EditNinjaScript- Strategy.
      I can`t start it. I must have done something wrong.

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Only run on real-time data
      if (Historical)
      return;
      // Condition set 1

      Comment


        #4
        lesbud, as you were making your code changes, please ensure you compiled the changes in by hitting F5 in the NinjaScript editor, otherwise your new strategy would not be available for usage.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          F5 did the trick.
          I never made any code changes, I didn`t know how to save them. Now I do.

          I started the strategy, it had zero for "strategy position" and nothing in P&L
          I let it run for few hours in short timeframe to see how it will behave. It runs perfect, it does exactly what I had in mind.
          I`ve been at it for weeks, your code solved it in minutes.

          Thank you VERY much for your help, I couldn`t do without it.

          P.S.
          I tried "Wait until flat before executing live" in the past. While strategy position was zero, in the strategy window "Unrealized P&L" there always was some value on startup. Positive or negative, identical to what it would be if the strategy position was displayed. That told me the strategy on startup did in fact do something, it just wasn`t displayed in strategy position. I didn`t like that. Your code made it work exactly the way I want it.

          Thank you

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DayTradingDEMON, Today, 09:28 AM
          3 responses
          19 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Stanfillirenfro, Today, 07:23 AM
          9 responses
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by George21, Today, 10:07 AM
          0 responses
          8 views
          0 likes
          Last Post George21  
          Started by navyguy06, Today, 09:28 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          8 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X