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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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; 
                 }
            }
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mkouitra, 10-23-2021, 04:40 PM
            17 responses
            1,959 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
            4 responses
            26 views
            0 likes
            Last Post Vietanhnguyen2hotmailcom  
            Started by PhillT, 04-19-2024, 02:16 PM
            4 responses
            36 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Started by ageeholdings, 05-01-2024, 05:22 AM
            5 responses
            38 views
            0 likes
            Last Post ageeholdings  
            Started by reynoldsn, Yesterday, 02:34 PM
            0 responses
            15 views
            0 likes
            Last Post reynoldsn  
            Working...
            X