Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical Values to Real Time

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

    Historical Values to Real Time

    I am using quantity calculation, based on current account size (I determine it by inputing AccountStart value by hand and then ADDING realized profits). I am also loading like 100 days of data, when enabling strategy real time, in order for daily calculations to work. My trade type is swing, meaning I could be in a position from 2 days up to 3 months (as futures roll over once every 3 months).

    So, if I start with 1 contract and get several wins, it would increase my quantity to 2, 3, 4, 5, 6, etc. throughout those 100 days of data loaded,when strategy is enabled

    My question is: when strategy is enabled, how the quantity will be calculated? 1) Historical data (including those 100 days of data) ignored and account size will be determined by AccountStart value and realized profits are 0. OR 2) Historical data is accounted for and account size will be AccountStart value and realized profits form those 100 days of data?

    If it's the latter option, I want a way to reset realized profits back to 0, when it starts running real time. I am thinking of a way to enter a code line to do so, but wonder, if I load 100 days, it would then reset on 1st bar of those historical 100 days.

    #2
    Hello UltraNIX,

    From the given details the quantity would be completely controlled by your logic. How that works would depend on what you made so that could potentially work from the start of the strategy through historical into realtime. By default the script will process historical data so if your logic is allowed to work in historical data the general answer should be that it would calculate for the whole period the script had run.

    The actual strategy position and account position quantity will be determined by the strategies orders and then live orders. If a strategy places orders historically then you should see the virtual position increase/decrease in historical data and also in realtime. If your quantity logic is tied into those executions you should see a similar result with your custom quantity.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Yes, I need further assistance.

      The one and only issue is as follows:
      How to "reset" realized profits (which be turned into variable RealizedPnL) on the 1st bar of Real time?

      Comment


        #4
        Hello UltraNIX,

        You can't reset the strategy variables, if you are tracking the values yourself by using your own variables then you would just reset the variables at the point which you need to. The first bar of realtime will have State.Realtime as its state so you could add a condition to check for realtime state and also use a bool variable if that logic should only happen one time.

        You can see the following example which shows working with PnL and resetting it for the new session, in that sample a custom variable is used to store the current pnl. https://ninjatrader.com/support/help...nce_statis.htm



        Please let me know if I may be of further assistance.

        Comment


          #5
          If there's a code to check whether previous bar (i.e. [1]) was Historical and current bar (i.e. [0]) is Real time, then there would not be a need for boolean. Can you help me construct such if statement?

          Comment


            #6
            Hello UltraNIX,

            There is not a way to check the previous state, you could detect when you move into realtime by seeing the State == State.Realtime. You could know that was the first instance by setting a custom bool variable to true and checking if that variable was false as part of the overall condition. That would let the code run on the first realtime bar and then would be ignored after that.

            Code:
            private bool doOnce;
            protected override void OnBarUpdate()
            {
                  if(State == State.Realtime && doOnce == false)
                 {
                     doOnce = true; 
                 }
            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            51 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            127 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X