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

APZ bug

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

    APZ bug

    I couldn't get APZ to work correctly on a higher time frame multi-series strategy where APZ was running on daily bars in a strat running on primary series one minute. The Upper and Lower were always the same value. It's because this condition is wrong:

    Code:
    if (CurrentBar < Period)
    {
    Lower[0] = Input[0];
    Upper[0] = Input[0];
    return;
    }
    It should be:
    Code:
    if (CurrentBar < newPeriod)
    {
    Lower[0] = Input[0];
    Upper[0] = Input[0];
    return;
    }
    newPeriod is calculated when Period is set and it's newPeriod that's used by the indicator. I changed it on my side and it's working correctly now.

    #2
    Hello Brillo,

    Could you be more specific as what was not working in your strategy? If I set up a basic strategy that uses APZ when APZ is using a daily data series, and the strategy is applied to a 1 minute chart, I do not see an issue.

    I also added a plot to the strategy so the daily APZ value can be viewed on the 1 minute data series.

    Period is used for the "emaRange" portion of code, and "newPeriod" is the square root of Period. Changing the code will change the result, so changing the indicator may affect how your strategy logic fires trades.

    Code:
    emaRange    = EMA(Range(), Period);
    Code:
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)]
    public int Period
    {
        get { return period; }
        set
        {
            period = value;
            newPeriod = Convert.ToInt32(Math.Sqrt(Convert.ToDouble(value)) );
        }
    }
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Run it with 200 for period on daily bars loaded in secondary series. Primary 1 minute. Then try to get the upper and lower out of it within the BIP 0.

      Comment


        #4
        I uploaded APZTest2.zip ( still the strategy is APZTest inside it though ).
        Changed just a little bit to make 200 and print out values.
        Output is incorrect:
        Click image for larger version

Name:	Capture.PNG
Views:	102
Size:	36.7 KB
ID:	1195802

        If you change the APZ code as I posted then the output is this (correct):

        Click image for larger version

Name:	Capture2.PNG
Views:	87
Size:	58.5 KB
ID:	1195803

        There's no reason for APZ to wait for 200 bars as configured because APZ is not using the configured value. it is using the square root of it. So configure for 200 and it's actually just needing 14 bars. that's what is in the newPeriod. I'm not sure why the script doesn't eventually get to the 200th bar and then start running as expected but you'll be able to reproduce the problem with the code in this post.

        Comment


          #5
          Here is another way to see the problem and solution.
          Just load a daily chart with the APZ set to 200 bars and a 2 percent band.
          Click image for larger version

Name:	CapturePeriod.PNG
Views:	110
Size:	502.0 KB
ID:	1195820Scroll all the way to the beginning (left) and you can see that the APZ is plotting at the Close. I included a screenshot of the original APZ code on the right and circled the Period. That property is returning 200. But 200 is not used in the calculations. It's the square root of 200.

          Now see what happens if we use the square root of 200, 14, as the APZ calculates it:

          Click image for larger version

Name:	CaptureNewPeriod.PNG
Views:	85
Size:	182.1 KB
ID:	1195821 You can see here that the APZ is correctly plotting a 2 percent band from the beginning when using newPeriod.

          Comment


            #6
            Hello Brillo,

            You may be onto something here. If I test that modification and compare with the original indicator: the wave form of the indicator starts earlier but continues creating the same plots as the original.

            We also have to consider if these changes are made, it can affect other users who have built code specific to the existing behavior.

            I can file this as an enhancement request, but it is possible it would not be considered until a "major" revision of the platform takes place (I.E. a theoretical 8.5 or 9.0) where changes that may be code-breaking would be considered. The ticket ID for considering this change is SFT-5496.

            You may reference the Release Notes page of the Help Guide for any changes made in newer versions.

            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rocketman7, Today, 09:41 AM
            2 responses
            4 views
            0 likes
            Last Post rocketman7  
            Started by traderqz, Today, 09:44 AM
            1 response
            2 views
            0 likes
            Last Post traderqz  
            Started by rocketman7, Today, 02:12 AM
            7 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by guillembm, Yesterday, 11:25 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by junkone, 04-21-2024, 07:17 AM
            10 responses
            149 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X