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

    Can Bill Williams Fractals be used in Strategy builder.

    I have used when price crosses above High Pivot .BUY.

    Not getting any result when I run the strategy?

    #2
    Hello Paul Penton,

    Thanks for your post and welcome to the NinjaTrader forums!

    If you are using the indicator BWFractal from the NT User apps section of the Ninjaatrader Ecosystem then yes it can be used in the Strategy Builder.

    The indicator does not provide the "pivot" until the 3rd bar after the actual pivot. This is because the logic of the indicator requires that the point be higher than the previous 2 bars and higher than the next two bars.

    You can create a condition that checks to see if the BWFractal upper 3 bars ago is greater than 0 which will only be true when 3 bars ago a point was plotted,

    I've attached a screenshot that shows a 1-minute chart with the indicator applied. In the chart, the indicator has marked the upper with the green squares. On the right is the strategy builder condition to check if 3 bars ago the upper plot was greater than 0 and if so to then draw a red diamond 3 bars ago 3 ticks above the bar. As you can see the startegy is confirming where the pivots are which means the condition is correct.

    Click image for larger version

Name:	PaulP-1.PNG
Views:	1968
Size:	74.3 KB
ID:	1137871
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks I have tried this with the Fractals {by Bill Wiliams} but am not getting the same result as you? I have set bars ago to three and Misc-> numeric value to 0. the way my strategy comes out it looks different?
      Attached Files

      Comment


        #4
        Hello Paul Penton,

        Thanks for your reply.

        Looks like you are using a different version of the indicator so I cannot provide direction on that.

        What I would suggest is to contact the source of the indicator and ask for their assistance with how to use it in the Strategy Builder.

        Otherwise, the approach I would take is to use the Print statement in the action section a strategy builder set and print out the values of the current bar, the previous, bar, the previous to that bar value of the pivot High/Low. These prints then would give you some idea of where the High/low pivot values are. the print is found in the Misc folder in the "do the following section of a set. I would not use any conditions and print both the high and low pivot points.


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks I did a quick search for BWFractals for Ninja trader on the net but nothing came up if there 's any way of finding the source it would be appreciated, thanks?

          So just checking the inherent Ninja trader one or the wiseman fractals cannot do this?

          Comment


            #6
            Hello Paul Penton,

            Thanks for your reply.

            This indicator is publicly available on our NinjaTrader Ecosystem website:Here is a basic guideline of how to Import NinjaScripts.

            To import NinjaScripts you will need the original .zip file.

            To Import
            1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
            2. From the Control Center window select the menu Tools>Import>Ninjascript add-on..
            3. Select the downloaded .zip file
            4. NinjaTrader will then confirm if the import has been successful.

            Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

            Once installed, you may add the indicator to a chart by:
            • Right click your chart > indicators > Select the Indicator from the list on the left > New > OK

            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.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Got it-great thanks.

              Comment


                #8
                I now have this version installed and programmed in Strategy builder to buy the signal condition is met- it doesn't seem to do anything- is there another step I need to take?

                So I need to buy or sell above below the fractal.
                Attached Files

                Comment


                  #9
                  Hello Paul Penton,

                  Thanks for your reply.

                  If you are testing on a live data chart, when you apply the strategy you would need to check the "Enable" check box and click OK. If that does not resolve, please clarify how/where you are testing and provide details of the instrument, contract, bar type, bar size, and test date(s).

                  Your condition is detecting that 3 bars ago the Upper Fractal had a value so you are placing a market order to go long 3 bars after the fractal. I think what you want is to save the value of the fractal into a variable as they are found and then in another set check to see if the price does crossabove (or crossed below) the variable to then place your entry order.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello PaulH,

                    "I think what you want is to save the value of the fractal into a variable as they are found and then in another set check to see if the price does crossabove (or crossed below) the variable to then place your entry order."
                    Yes, me too, want to save the values of an Up- or Down- Fractal of the BW Indicator.

                    Can you please explain in detail with Ninjascript Code how i can save the last BW fractalvalues from the indicator into a variable/Array? And how to recall these values from ( OnBarUpdate()) for an Entry.

                    I could do that easily with MQL but unfortunately not with Ninjascript.



                    Thank you very much for your help.

                    Bieter Dirr



                    Comment


                      #11
                      Hello BieterDirr,

                      Thanks for your post and welcome to the NinjaTrader Forums!

                      If you are not familiar with Ninjascript I would suggest reviewing these resources:
                      Ninjascript 401 webinar: https://ninjatrader.com/Webinar/NinjaScript-Editor-401
                      Publically available recording of Ninjascript webinar: https://www.youtube.com/watch?v=H7aD...We0Nf&index=15
                      Tutorials: https://ninjatrader.com/support/help...strategies.htm

                      I would suggest creating the strategy using the Strategy Builder, create the conditions in the condition builder. You can then click "View code" to see the Ninjascript code that is created which is the same as you would use and you can copy/paste what you need. Alternately, once the strategy is created, you can unlock the strategy and work directly on it in the Ninjascript editor.

                      In the strategy builder, you would just create two variables of the double type to hold the latest fractal point. In a set, you would check to see if the 3rd bar ago of the indicator is greater than zero (Look at the condition in post #2). When that is true, you can have the "action" of that set to save the value of the indicator 3 bars ago into the variable you created. You would need a second "set" for the other side.

                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello PaulH,

                        Here is what i did with the Strategy Builder.

                        No sucess.

                        It does not take any trades in Backtest.
                        It would be great, if you could help.

                        I need access to the last Fractallevels. How it can be done?
                        If possible, i want to store for instance the last 3 up Fractals. (Up1,Up2....)


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

                        private bwFractal bwFractal1;

                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"Geben Sie hier die Beschreibung für die neue benutzerdefinierte Strategie.";
                        Name = "BWFractal";
                        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;
                        Up = 1;
                        Down = 1;
                        }
                        else if (State == State.Configure)
                        {
                        }
                        else if (State == State.DataLoaded)
                        {
                        bwFractal1 = bwFractal(Close, false, true, 3, 1);
                        bwFractal1.Plots[0].Brush = Brushes.Green;
                        bwFractal1.Plots[1].Brush = Brushes.Red;
                        AddChartIndicator(bwFractal1);
                        SetProfitTarget("", CalculationMode.Ticks, 200);
                        SetStopLoss("", CalculationMode.Ticks, 100, false);
                        }
                        }

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

                        if (CurrentBars[0] < 3)
                        return;

                        // set 1
                        if (bwFractal1.Upper[3] > 0)
                        {
                        Up = bwFractal1.Upper[3];
                        EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), Up, Up);
                        }

                        // set 2
                        if (bwFractal1.Lower[3] > 0)
                        {
                        Down = bwFractal1.Lower[3];
                        EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), Down, @"Down");
                        }

                        }
                        }
                        }

                        Thank you very much.

                        Comment


                          #13
                          Hello BieterDirr,

                          Thanks for your reply.

                          Now that you have created this with the Strategy Builder you can unlock the code and work directly in the Ninjascript editor if you wish to. Note that once you unlock you cannot then use the Strategy Builder on that strategy.

                          In the Strategy Builder, the EnterShort/LongStopMarket orders will be automatically canceled if not filled in the bar they are submitted in. If you remain in the Strategy builder you would need to do things a bit differently to maintain these type orders. In a nutshell, instead of placing the order in that set, you would only save the fractal value in that set. In another set, you would check that you had a flat market position and you would check that the variable Up is not equal to 1 (your default value). When those conditions are true that means that you have stored a fractal value and that you do not have an existing position. The action of the new set would be to then place the order at the Up value. This set will continue to place the order on each bar until it is filled. You would need to do the same, in another set but for the Down side.

                          To save the last 3 fractals, you would need to create 3 variables, perhaps named Up1, Up2, Up3, andDown1, Down2, Down3, where 1 is the latest, 2 the previous, and 3 the one before that. Going back to set 1, as the example, when a new fractal is found, the first action would be to assign Up2 to Up3, then Up1 to Up2, then save the latest fractal to Up1. So you are shifting back the existing fractals first then saving the latest.

                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Would you mind showing what storing the fractals looks like on the strategy builder as well as the condition to buy/sell? I have imputted all of the parameters that have been mentioned but so far there are no orders placed on the backtest.

                            Comment


                              #15
                              Hello Paul H,

                              thank you for your reply.


                              I unlocked the code and I did what you explained (flat market postition and Up !=1...)


                              Unfortunately, it is not working for me.


                              I put a Print function for debugging, and there is no fractalvalue in the Ninjacript Output window.


                              Like i said, i am able to code this in MQL=Metatrader (traded live with that).


                              All i want is a simple Buystop x-ticks above or below a valid fractal.


                              Also:

                              I need access to the last fractalvalues like in a Array.

                              Lets say:

                              ThirdFractalUp=FractalUp[3]

                              How can store the BW Fractal values in an Array? Code?


                              Thank you very much for your help.


                              Here is the code what i tried:

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

                              private bwFractal bwFractal1;

                              protected override void OnStateChange()
                              {
                              if (State == State.SetDefaults)
                              {
                              Description = @"Geben Sie hier die Beschreibung für die neue benutzerdefinierte Strategie.";
                              Name = "BWFractal";
                              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;
                              Up = 1;
                              Down = 1;
                              }
                              else if (State == State.Configure)
                              {
                              }
                              else if (State == State.DataLoaded)
                              {
                              bwFractal1 = bwFractal(Close, true, false, 3, 1);
                              bwFractal1.Plots[0].Brush = Brushes.Green;
                              bwFractal1.Plots[1].Brush = Brushes.Red;
                              AddChartIndicator(bwFractal1);
                              SetProfitTarget("", CalculationMode.Ticks, 200);
                              SetStopLoss("", CalculationMode.Ticks, 100, false);
                              }
                              }

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

                              if (CurrentBars[0] < 3)
                              return;

                              // set 1
                              if (bwFractal1.Upper[3] > 0)
                              {
                              Up = bwFractal1.Upper[3];
                              Print("Frakctal Upper:" +Up); // Show Level


                              }


                              // set 2


                              if ((Position.MarketPosition == MarketPosition.Flat )
                              && (Up != 1))
                              {

                              EnterLongStopMarket(0,true,1,bwFractal1.Upper[3], "EntryFractalupper");
                              // EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), bwFractal1.Upper[3], "");
                              }

                              }

                              }
                              }

                              Thank you.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              44 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              180 views
                              0 likes
                              Last Post jeronymite  
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Working...
                              X