Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Quad Timeline calculation issues

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

    Quad Timeline calculation issues

    Hello,
    Note I'm using NT 8.1.2.1, on Windows 11. I'm developing a strategy that uses 4 data series and a DoubleStoch indicator on each data series to calculate and decide entry points. I think I am following all of the rules for multiple timelines but the calculations do not match the visual indicators on the chart, which is what I'm trying to emulate. The four data series are a 125 Tick chart is the Entry/Base series. Then a 400 tick, 1200 tick, 3000 tick data series.

    My code to add these are as follows in the OnStateChange method:

    else if (State == State.Configure)
    {
    try
    {
    AddPerformanceMetric(new NinjaTrader.NinjaScript.PerformanceMetrics.SampleC umProfit());

    SetProfitTarget("", CalculationMode.Ticks, TargetTicks);
    SetStopLoss("", CalculationMode.Ticks, StopTicks, false);

    } catch(Exception exception) {
    MayPrint("Error occured in State Change - State.Configure. Error is: " + exception.ToString(), 0);
    }
    // Add AC1
    AddDataSeries(BarsPeriodType.Tick, 400);
    // Add AC3
    AddDataSeries(BarsPeriodType.Tick, 1200);
    // Add AC4
    AddDataSeries(BarsPeriodType.Tick, 3000);

    } else if (State == State.DataLoaded)
    {
    try
    {
    if(ChartBars == null)
    {
    MayPrint("Strategy was not loaded from a chart, exiting strategy...", 0);
    return;
    }

    // Set the Dollars Per tick
    DollarsPerTick = Instrument.MasterInstrument.PointValue * TickSize;
    MasterInstrumentName = Instrument.MasterInstrument.Name;

    mayVeryFastHMA = HMA(veryFastEMAPeriod);
    EntryEMA = EMA(EntryEMAPeriod);
    AC1EMA = EMA(AC1EMAPeriod);
    mayDSEntry = MayDSv4(BarsArray[0], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, DSPeriod, true, false, true, true, 4, 0.3, 4);
    AC1mayDS = MayDSv4(BarsArray[1], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);
    AC3mayDS = MayDSv4(BarsArray[2], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);
    AC4mayDS = MayDSv4(BarsArray[3], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);

    } catch(Exception exception) {
    MayPrint("Error occured in State Change - State DataLoaded. Error is: " + exception.ToString(), 0);
    }

    The MayDSv4 is a fast DoubleStoch. The DS in question here is the 400 Tick DS, or the Yellow one on the chart. Note the two entries on the left. They are printing the values of each DS so I can easily see what the parameters were at the time of entry. The first one down is the 125, the second is the 400, etc. Note that on the two entries on the left, the values of the 400 are 92.929 AND this matches the visual of the DS indicator down below. This is good and I'm OK with that. However, on the entry on the right, the value says 90.497, but the visual says the value is less than 5.

    This is where the issue is in the algorithm. If the calculation matched the visual then the algo would not have entered so I must be doing something wrong. Note that I am using OnBarUpdate and NOT OnTickUpdate.

    The code at the beginning of the OnBarUpdate is as follows to keep the values of the DoubleStoch for each timeline so when it enters on the main series, I can do my calculations:

    try
    {
    // Make sure we have enough bars to run this algo and that we shouldn't stop for other reasons.
    if (((CurrentBars[0] < BarsRequiredToPlot) && (CurrentBars[1] < BarsRequiredToPlot) && (CurrentBars[2] < BarsRequiredToPlot) && (CurrentBars[3] < BarsRequiredToPlot)) || (StopMaxProfit == true) || (StopMaxLoss == true))
    return;


    if (BarsInProgress == 1)
    AC1CurrVal = AC1mayDS.KMiddle[0];

    if (BarsInProgress == 2)
    AC3CurrVal = AC3mayDS.KMiddle[0];

    if (BarsInProgress == 3)
    AC4CurrVal = AC4mayDS.KMiddle[0];

    //
    // This is here so we only process the first bar for the on update. We only analyze where we are for the first bar and not the other Anchor charts
    //
    if (BarsInProgress != 0)
    return;

    So, I only do the calculations on the main series. I check all values and decide to enter long or short or nothing. I have attached an image so you can visualize what I am discussing better.

    My main question is: Can you help me figure out what I am doing incorrectly with the calculations because the 400 DoubleStoch calculation should be less than 10 and not above 90?

    Thank you for your assistance,

    Steve​
    Attached Files

    #2
    Hello,

    Thank you for your post.

    I'm a bit confused by your code. You have the following line of code, which prevents updates/calculations on any other added series :

    Code:
    if (BarsInProgress != 0)
    return;

    However you also have three checks for BIP1, BIP2, AND BIP3.
    Code:
    if (BarsInProgress == 1)
    AC1CurrVal = AC1mayDS.KMiddle[0];
    
    if (BarsInProgress == 2)
    AC3CurrVal = AC3mayDS.KMiddle[0];
    
    if (BarsInProgress == 3)
    AC4CurrVal = AC4mayDS.KMiddle[0];
    Do you want these indicators to calculate on the additional data series, or only on the primary data series? If you want the indicators to calculate when the respective series is updating, and then the rest of the code to update when BIP is 0, then it would be more intuitive to instead encapsulate that logic when BIP is 0.

    ​Additionally, where are these visuals on the chart from your screenshot coming from? Is the indicator added separately to the chart, or did you use AddChartIndicator() in the script to add the indicator to the chart visually?

    Comment


      #3
      Yes, I coded it so it would save the values of the larger data series' but it only does the calculations on the lowest timeframe. The Yellow indicator is added separately but I made sure they have the same parameters. Are you stating that I should I be doing the calculations on the highest timeframe?

      The code keeps going currently only if BIP = 0.

      Comment


        #4
        You would need to add debugging prints to the script to figure out why it is not calculating the same / why it is not taking the actions you are expecting.

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

        The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

        The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.


        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).


        Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.


        I am happy to assist you with analyzing the output from the output window.


        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.


        Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

        https://support.ninjatrader.com/s/ar...nd-TraceOrders

        Comment


          #5
          Gaby,
          Thank you for the reply. I fully understand how to debug the program and put print statements in to see where things are. In fact, based on the data and values on the screen, my entries are correct. My issue and question is with the multiple timelines and the indicators for each timeline. Currently, it appears that the second data series, which is the 400 or the AC1, is not updating properly. I only showed the code for the creation of the data series' and the saving of the data on each data series to give you enough information to tell me if I was doing something incorrectly because the AC1/400 Double Stoch does not appear to be updating correctly.

          The point of the graphic was to show that the value of the 400 DS did not match the Yellow DoubleStoch at the bottom of the screen and my question is (Note: These are both the same and have the same settings): Why is that? Am I doing something wrong with the multiple timelines and the updates to them? Why are they different? I get that the main series should have about 3 or 4 bars before the 400 gets updated, but by the visual at the bottom, the value of the 400DS should be around 10 or less, NOT above 90.

          Do you understand the question? Can you help with this? Do I need to provide more information?

          Thanks again,

          Steve

          Comment


            #6
            Why are they different? I
            There isn't enough information provided in order to know why they are different, which is why debugging is recommended.

            We would need the output from debugging to know why they are different. Without the info from debugging, we unfortunately don't have enough information.

            it appears that the second data series, which is the 400 or the AC1, is not updating properly.
            Please provide output showing this is the case. At the top of OnBarUpdate, you can print out the BarsInProgress index, along with the time of the bar to see if any updates are being skipped in the strategy's calculation.

            Code:
            Print("BIP: " + BarsInProgress + ", " + Time[0]);

            Comment


              #7
              I have put in Print statements that go to NS output. I also have a good example, with the print statements as to why I'm questioning this. Note that I took out the BIP print statements because they were too much but they were updating correctly.

              Let me explain this example. Same scenario as before: Entry chart is a 125 tick entry chart, but also has a 400 tick data series in it to use with the other DoubleStochastics. On that chart, the grey DoubleStoch is the 125 and the Yellow one is the 400. You can see on the snap that the strategy entered long at 11:21 AM CST based on the fact that the 400 DS said that it was 93.098. The math for the entry is correct. However, on the screen down below on the yellow DS, you can see it says the value is on 55. If the one in the strategy was 55, it would not have entered and thus would not have gotten a bad entry. You can also see that on a separate chart with just the 400 Tick with a DoubleStoch, the value of that one is 3. They all have the same parameters but somehow have gotten different results.

              And just in case their is question on my DoubeStoch, I added another DoubleStoch down at the bottom, which is the default NT DoubeStoch and it has basically the same value on the screen, which is 55.28.

              I also added another example where the value is much closer but still different from the ones on the screen below. It enters at 13:20 Short. It says the value of the 400DS is 6.6 whereas the ones on the screen state it is 9. That's OK and within spec at the moment, but I'm just showing the difference.
              Attached Files

              Comment


                #8
                They all have the same parameters but somehow have gotten different results.
                Where in the output provided is the different between the two tests highlighted? i.e. for which timestamps are we looking at the output for? You've provided a screenshot of a single output window, if we're trying to compare results then we would need to be comparing results from two tests.


                I think the issue is most likely where you are calculating the indicator from in the strategy. The code you've posted seems correct, but if you are getting different values there most likely is somewhere in the logic that is affecting the results.

                I am attaching a simple test script that I used to compare the value of a 400 Tick DoubleStoch on the chart with the value of a 400 Tick DoubleStoch from a strategy that adds the 400 Tick as an added series. I am seeing that the indicators match.

                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                49 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                66 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