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

Can Bill Williams Fractals be used in Strategy builder.

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

    #16
    Hello BieterDirr,

    Thanks for your reply.

    In your set two, the likely issue is that in EnterLongStopMarket(0,true,1,bwFractal1.Upper[3], "EntryFractalupper"); on each bar you are accessing bwFractal1.Upper[3] which may not have a fractal value on a given bar. You should instead be using the saved variable value of Up which should have the fractal value.

    If you want to use the IsLiveUntilCanceled then you need to add further code so that you can cancel that order if/when needed as it will in that case not be automatically canceled. Here are links to further assist you with creating orders that can be canceled:
    https://ninjatrader.com/support/help...ancelorder.htm (Please review the example in the help guide)
    https://ninjatrader.com/support/help...thod_to_ca.htm (This is an example strategy that demonstrates the cancel order process).

    Another alternative, instead of using limit orders you can create the condition of checking to see if price crosses above the fractal level and if so then use EnterLong() which is a market order. In a set, you would then check to see if you are flat and check that a price type (High, Low, Close, Open, weighted, or median, has CrossAbove, the right side would be the variable Up. The action would be EnetrLong().

    If you use variables as I have advised in post #13 you can continue working in the strategy builder which, while confining in some respects is also convenient in others. I Understand you have unlocked so you cannot use that particular file so you would have to create a new one.

    To answer your question about an array, this is more of a C# question and we generally will refer you to seek C# answers via the internet search. However, in the interest of time, you would have to create a private array like this:

    At the class level: private double [] UpFractals;

    In State.DataLoaded: UpFractals = new double[3]; // determine how many values to store and use that number, 3 is shown as an example.

    You can then use the Array as needed in OnBarUpdate().


    Paul H.NinjaTrader Customer Service

    Comment


      #17
      Hello BigDirty,

      Thanks for your post and welcome to the NinjaTrader Forums!

      First, here is an example of creating the variables on the Inputs and variables page of the Strategy Builder:
      Click image for larger version

Name:	BD1.PNG
Views:	507
Size:	27.3 KB
ID:	1170668

      Here is an example where the fractal is detected and then assigned(saved) to the variable
      Click image for larger version

Name:	BD-2.PNG
Views:	473
Size:	28.1 KB
ID:	1170669

      Here is an example of a set that checks for a flat market position, checks to see if the close price has crossed above the saved fractal and then if true will enter a long market order and will draw a dot to show on the chart when the set conditions are true.
      Click image for larger version

Name:	BD3.PNG
Views:	464
Size:	31.5 KB
ID:	1170670

      For general reference, here are the educational materials for the strategy Builder in case you have not reviewed them:
      Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
      Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
      Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
      Tutorial using the Strategy Builder (Titled "Creating the Strategy by the Wizard): https://ninjatrader.com/support/help..._cross_ove.htm
      Paul H.NinjaTrader Customer Service

      Comment


        #18
        Hello Paul,


        thank you for your time and effort.



        Code:
        In your set two, the likely issue is that in [I]EnterLongStopMarket(0,true,1,bwFractal1.Upper[3], "EntryFractalupper");[/I] on each bar you are accessing bwFractal1.Upper[3] which may not have a fractal value on a given bar. You should instead be using the saved variable value of Up which should have the fractal value.
        I changed "bwFractal1.Upper[3]" to Up...

        Still no Entries...

        So i rebuild the everything in Strategybuilder, but it does not take any Trade (Backtest and Sim).
        What i am missing?


        Here is my Ninjascriptcode, which i tried do, according to your pictures.




        //This namespace holds Strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class BWFractalAgain : Strategy
        {
        private double UpperFractal;
        private double LowerFractal;

        private bwFractal bwFractal1;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Strategy here.";
        Name = "BWFractalAgain";
        Calculate = Calculate.OnBarClose;
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = true;
        ExitOnSessionCloseSeconds = 30;
        IsFillLimitOnTouch = false;
        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution = OrderFillResolution.Standard;
        Slippage = 0;
        StartBehavior = StartBehavior.WaitUntilFlat;
        TimeInForce = TimeInForce.Gtc;
        TraceOrders = false;
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade = 20;
        // Disable this property for performance gains in Strategy Analyzer optimizations
        // See the Help Guide for additional information
        IsInstantiatedOnEachOptimizationIteration = true;
        Profit = 20;
        Stop = 20;
        UpperFractal = 0;
        LowerFractal = 0;
        }
        else if (State == State.Configure)
        {
        }
        else if (State == State.DataLoaded)
        {
        bwFractal1 = bwFractal(Close, false, true, 3, 1);
        SetProfitTarget(@"", CalculationMode.Ticks, Profit);
        SetStopLoss("", CalculationMode.Ticks, Stop, false);
        }
        }

        protected override void OnBarUpdate()
        {
        if (BarsInProgress != 0)
        return;

        if (CurrentBars[0] < 3)
        return;

        // Set 1
        if (bwFractal1.Upper[3] > 0)
        {
        UpperFractal = bwFractal1.Upper[3];
        }

        // Set 2
        if ((Position.MarketPosition == MarketPosition.Flat)
        && (CrossAbove(Close, UpperFractal, 1)))
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), "");
        Draw.Dot(this, @"BWFractalAgain Dot_1", true, 0, 0, Brushes.CornflowerBlue);
        }

        }
        Thank you for your help

        Comment


          #19
          Hello BieterDirr,

          Thanks for your reply.

          I see nothing incorrect with your strategy builder code.

          When you apply the strategy to live data, please note that you must click the "enable" check box in the strategy parameters (this step is not needed in the strategy analyzer)

          Do you see any errors listed in the "Log" tab of the Ninjatrader control center when applying the strategy in either the analyzer or on live data?

          What instrument, bar type and bar size are you testing on?

          What is the start and end date of the backtest data?

          In the Strategy analyzer, please apply the strategy SampleMACrossover using the same bar type and size and start/end dates, do you see any trade then?
          Paul H.NinjaTrader Customer Service

          Comment


            #20
            Hello Paul,

            Thank you, i will be patient to find a way.
            Because i trade these setups successfully for 4 years already (Forex and Futures).

            "I see nothing incorrect with your strategy builder code."

            Good, but why it does not work? Did it worked for you?

            I enabled the strategy on a MNQ live sim chart = no trades. Different TF: 1min-15min....1000 Tickchart
            Backtest on 60min = no trades
            No Errors in Log Tab.

            Instrument MNQ
            Time: 1.8.2021-9.9.2021

            SampleMACrossover works fine within that period=see Screenshot


            BTW:

            Here is the simple MQL-Metatrader Function which i need to transfer to Ninjascript

            // Fractal Array Function

            double findFractal(int nbr, int mode, int timeframe)
            {
            int i=3, n;
            for(n=0;n<=nbr;n++)
            {
            while(iFractals(Symbol(),0,mode,i) == 0)
            i++;
            if(n<nbr)
            i++;
            }
            return(iFractals(Symbol(),0,mode,i));
            }

            //// Access Fractal Values

            double Fr1=findFractal(0, MODE_LOWER, 0); // last fractal value

            double Fr2=findFractal(1, MODE_LOWER, 0); // next to last fractal value







            Click image for larger version

Name:	Bild_2021-09-10_193154.png
Views:	311
Size:	114.8 KB
ID:	1170728

            There has to be a solution, thank you.
            Attached Files

            Comment


              #21
              Hello BieterDirr,

              Thanks for your reply.

              Please attach your strategy file and I will test it on my end.

              The file can be found in Documents>NinjaTrader8>bin>custom>Strategies>BWFra ctalAgain.cs

              Paul H.NinjaTrader Customer Service

              Comment


                #22
                Hello Paul,

                thank you for your time. Here it is file.

                Thank you
                Attached Files

                Comment


                  #23
                  Hello BieterDirr,

                  Thanks for your reply.

                  What specific version of NinjaTrader8 are you using? (Look under Help About)

                  Paul H.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello Paul,

                    8.0.24.3 64-bit

                    Simulation License

                    Thank you

                    Comment


                      #25
                      Hello BieterDirr,

                      Thanks for your reply.

                      In looking at your strategy and comparing it to what I had been testing with I could only find one difference and the difference was that mine include a print statement to print out the fractal values. Interestingly as soon as I removed that print statement the strategy no longer traded. The same is true when the strategy is unlocked in Ninjascript form. The print statement, and the test strategy, was created some time ago so you might understand why I was surprised that your strategy was not working as it was relatively identical to mine.

                      We will be looking at this later next week to better understand why this is.

                      In the meantime, I will attach my working strategy which includes the print statement for your review and testing. As long as you add a print statement looking at the Fractal[0] or Fractal[1] the strategy will work (in the strategy builder or unlocked Ninjascript).

                      BWFractalTestSB.zip

                      Please note that this is provided as an educational example only and is not intended for use with a live account.

                      Paul H.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello BieterDirr,

                        After further review, I have updated the indicator to work as expected in a strategy.
                        You will no longer need to use a print statement.

                        A new version is being added to the NT User Apps and should be up soon.

                        The change will be noted with todays date.




                        Paul H.NinjaTrader Customer Service

                        Comment


                          #27
                          I have followed this posting from the beginning to the end. Are there any updates on the fix of the issue?

                          Comment


                            #28
                            Welcome to the forums Nyman!

                            Paul has made changes to his submission on the User App Share. Please see the link below.

                            This is a conversion of the NT7 indicator Fractals by Bill Williams. Please contact the original author for any questions or comments. 09-13-2021: &#8211; Added call to Update() in outputs to improve use in a strategy 11/02/15: &#8211; Added rays to connect last two fractal points and extend right &#8211; Added ability to set ray/text [&#8230;]


                            The link above is publicly available.

                            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                            JimNinjaTrader Customer Service

                            Comment


                              #29
                              Originally posted by NinjaTrader_PaulH View Post
                              Hello BieterDirr,

                              After further review, I have updated the indicator to work as expected in a strategy.
                              You will no longer need to use a print statement.

                              A new version is being added to the NT User Apps and should be up soon.

                              The change will be noted with todays date.



                              Hi Paul

                              I am using your 9-13-2021 version of bwfractal. I am having some weird issue with it and maybe you can tell me if anything can be done.

                              Often you get many fractals in a row e few bars apart. But when you do F5 some disappear. is that normal and will it affect the trading strategy.

                              Thank you in advance for your help

                              Richard

                              Comment


                                #30
                                Hello Richard,

                                The indicator uses Calculate.OnPriceChange as a default, and OnPriceChange is only applicable with realtime data.

                                When you reload a script, the existing data is processed following OnBarClose behavior, so there would be a difference after reloading with F5.
                                JimNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by burtoninlondon, Today, 12:38 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post burtoninlondon  
                                Started by AaronKoRn, Yesterday, 09:49 PM
                                0 responses
                                14 views
                                0 likes
                                Last Post AaronKoRn  
                                Started by carnitron, Yesterday, 08:42 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post carnitron  
                                Started by strategist007, Yesterday, 07:51 PM
                                0 responses
                                14 views
                                0 likes
                                Last Post strategist007  
                                Started by StockTrader88, 03-06-2021, 08:58 AM
                                44 responses
                                3,983 views
                                3 likes
                                Last Post jhudas88  
                                Working...
                                X