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

WilliamsFractal and MACDHistogramCrossover - Exist in NT?

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

    WilliamsFractal and MACDHistogramCrossover - Exist in NT?

    Hi All,

    I'm converting a strategy from TOS and the only two open items I can't find right now are:
    1.MACDHistogramCrossover()
    2.WilliamsFractal()."DownFractal"

    Do those exists somewhere and I'm missing it?

    #2
    Hello darkgreen,

    Thanks for your post.

    You can access the histogram plot of the MCAD indicator and check to see if it has crossed above or crossed below zero.

    WilliamsFractal is available in NinjaTrader8 as WisemanFractal however it is not available through Ninjascript due to licensing (Reference: https://ninjatrader.com/support/help...WisemanFractal).

    There is a publically available indicator called BWFractal that you can download/install and can use in Ninjascript (or the strategy builder).

    This indicator is publicly available on our NinjaTrader Ecosystem website:

    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: – Added call to Update() in outputs to improve use in a strategy 11/02/15: – Added rays to connect last two fractal points and extend right – Added ability to set ray/text […]


    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


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello darkgreen,

      Thanks for your post.

      You can access the histogram plot of the MCAD indicator and check to see if it has crossed above or crossed below zero.

      WilliamsFractal is available in NinjaTrader8 as WisemanFractal however it is not available through Ninjascript due to licensing (Reference: https://ninjatrader.com/support/help...WisemanFractal).

      There is a publically available indicator called BWFractal that you can download/install and can use in Ninjascript (or the strategy builder).

      This indicator is publicly available on our NinjaTrader Ecosystem website:

      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: – Added call to Update() in outputs to improve use in a strategy 11/02/15: – Added rays to connect last two fractal points and extend right – Added ability to set ray/text […]


      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.

      Thank you.. I installed the indicators you've mentioned. I'm good with the MACD one, but with the bwFractal I'm confused as how to structure a close short position if Lower is different than n/a? it's not your typical true/false signals.

      Comment


        #4
        Hello darkgreen,

        Thanks for your reply.

        In the description of the BWfractal indicator is this, "Fractal Technical Indicator it is a series of at least five successive bars, with the highest HIGH in the middle, and two lower HIGHs on both sides. The reversing set is a series of at least five successive bars, with the lowest LOW in the middle, and two higher LOWs on both sides, which correlates to the sell fractal. The fractals have High and Low values and are indicated with the up and down arrows."; What that means is that the Fractal is not known/drawn until 2 bars after where it is marked (Middle of 5 successive bars). To find the latest Low fractal point, you would need to loop back several bars and look for a value in the Lower plot. For example:

        At the class level: private bwFractal bwFractal1;

        In State.DataLoaded: bwFractal1 = bwFractal(Close, false, false, 3, 1);

        In OnBarUpdate()

        if (CurrentBar < 10) return;

        for (int i = 0; i < 10; i++)
        {
        if (bwFractal1.Lower
        != 0)
        {
        _lowerBarsAgo = i;
        Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
        break;
        }
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello darkgreen,

          Thanks for your reply.

          In the description of the BWfractal indicator is this, "Fractal Technical Indicator it is a series of at least five successive bars, with the highest HIGH in the middle, and two lower HIGHs on both sides. The reversing set is a series of at least five successive bars, with the lowest LOW in the middle, and two higher LOWs on both sides, which correlates to the sell fractal. The fractals have High and Low values and are indicated with the up and down arrows."; What that means is that the Fractal is not known/drawn until 2 bars after where it is marked (Middle of 5 successive bars). To find the latest Low fractal point, you would need to loop back several bars and look for a value in the Lower plot. For example:

          At the class level: private bwFractal bwFractal1;

          In State.DataLoaded: bwFractal1 = bwFractal(Close, false, false, 3, 1);

          In OnBarUpdate()

          if (CurrentBar < 10) return;

          for (int i = 0; i < 10; i++)
          {
          if (bwFractal1.Lower
          != 0)
          {
          _lowerBarsAgo = i;
          Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
          break;
          }
          }
          Here's what I'm getting...

          Comment


            #6
            Hello darkgreen,

            Thanks for your reply.

            Sorry for the error, it seems when I formatted with italics it pull out [I] which in hindsight is the italics operator.

            So line 101 need to be if (bwFractal1.Upper[i] != 0)

            At the class level add this: private int _lowerBarsAgo; to clear off the last two errors.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_PaulH View Post
              Hello darkgreen,

              Thanks for your reply.

              Sorry for the error, it seems when I formatted with italics it pull out [I] which in hindsight is the italics operator.

              So line 101 need to be if (bwFractal1.Upper[i] != 0)

              At the class level add this: private int _lowerBarsAgo; to clear off the last two errors.

              Thanks again... I don't get any errors now but for some reason I still can't get the orders right. Orders seem to only close at 16:00 every day and not when bwfractal lower is plotted:
              Last edited by darkgreen; 07-22-2020, 12:48 PM. Reason: strategy

              Comment


                #8
                Here's the code btw:

                // Set 1
                if (CrossBelow(MACD1.Default, MACD1.Avg, 1))
                {
                EnterShort(Convert.ToInt32(DefaultQuantity), @"MACDCrossOver");
                }
                if (CurrentBar < 10) return;
                for (int i = 0; i < 10; i++)
                {
                if (bwFractal1.Lower[i] != 0)
                {
                _lowerBarsAgo = i;
                //Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
                ExitShort(Convert.ToInt32(DefaultQuantity), @"WFD", @"WFD");
                break;
                Attached Files

                Comment


                  #9
                  Hello darkgreen,

                  Thanks for your post,

                  In the ExitShort order, you have restricted it to only exit if the Entry signal name is WFD.

                  Change the Exits "from entry signal" to the entry signal name of MACDCrossOver.

                  Alternately, remove the entry signal names from both entry/exit methods.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_PaulH View Post
                    Hello darkgreen,

                    Thanks for your post,

                    In the ExitShort order, you have restricted it to only exit if the Entry signal name is WFD.

                    Change the Exits "from entry signal" to the entry signal name of MACDCrossOver.

                    Alternately, remove the entry signal names from both entry/exit methods.
                    Thanks, it does seem to exit the trades now, but it also exits sometimes without a valid bwFractal1.Lower plot? I suspect we can remove the false signals if we call the indicator directly, and whenever it plots the value, only then exit the code. Is there a way to do that?

                    Comment


                      #11
                      Hello darkgreen,

                      Thanks for your reply.

                      The Fractal indicator does not mark the fractal point until 2 bars after it has occurred. At the time of the entry bar (in both of the X examples), there is a fractal low point already marked within the previous 10 bars (the for loop goes back 10 bars) that would have triggered the exit. The fractal at the entry bar would not be known until 2 bars later so it is coincidental and not part of the exit.

                      The code is calling the indicator directly.

                      Perhaps you are wanting to wait for X bars after the order is filled before running the 10 bar look-back to see if a fractal has occurred.

                      One way to do that would be to use a BarsSinceEntryExecution() check. Reference: https://ninjatrader.com/support/help...yexecution.htm

                      For example

                      if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1)
                      {
                      for (int i = 0; i < 10; i++)
                      {
                      if (bwFractal1.Lower[i] != 0)
                      {
                      _lowerBarsAgo = i;
                      //Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
                      ExitShort(Convert.ToInt32(DefaultQuantity), @"MACDCrossOver", @"WFD");
                      break;
                      }

                      This example means you would wait for 10 bars before checking, you can certainly change 10 to any number you wish but keep in mind that if you want to wait for a new fractal it will be at least 2 bars before you would have it.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_PaulH View Post
                        Hello darkgreen,

                        Thanks for your reply.

                        The Fractal indicator does not mark the fractal point until 2 bars after it has occurred. At the time of the entry bar (in both of the X examples), there is a fractal low point already marked within the previous 10 bars (the for loop goes back 10 bars) that would have triggered the exit. The fractal at the entry bar would not be known until 2 bars later so it is coincidental and not part of the exit.

                        The code is calling the indicator directly.

                        Perhaps you are wanting to wait for X bars after the order is filled before running the 10 bar look-back to see if a fractal has occurred.

                        One way to do that would be to use a BarsSinceEntryExecution() check. Reference: https://ninjatrader.com/support/help...yexecution.htm

                        For example

                        if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1)
                        {
                        for (int i = 0; i < 10; i++)
                        {
                        if (bwFractal1.Lower[i] != 0)
                        {
                        _lowerBarsAgo = i;
                        //Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
                        ExitShort(Convert.ToInt32(DefaultQuantity), @"MACDCrossOver", @"WFD");
                        break;
                        }

                        This example means you would wait for 10 bars before checking, you can certainly change 10 to any number you wish but keep in mind that if you want to wait for a new fractal it will be at least 2 bars before you would have it.
                        I'm sorry, I'm probably missing something in the logic here, but I'll give it a try -
                        Yes, Williams Fractal pattern is lagging two bars that's understandable, but here's what I'm trying to achieve:

                        Sequence:
                        1. Enter Short when MACD crossover - this is working
                        2. Look for Williams Fractal Lower plot on the chart (again this will be hindsight and lagging 2 bars) but I want to find the exact point when it's plotted
                        3. As soon as the plot is made (2 bars in the past), exit the trade now (at present time)

                        The code below doesn't seem to open or close trades now.

                        // Set 1
                        if (CrossBelow(MACD1.Default, MACD1.Avg, 1))
                        {
                        EnterShort(Convert.ToInt32(DefaultQuantity));
                        }
                        //if (CurrentBar < 10) return;
                        if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1))
                        for (int i = 0; i < 10; i++)
                        {
                        if (bwFractal1.Lower[i] != 0)
                        {
                        _lowerBarsAgo = i;
                        //Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower);
                        ExitShort(Convert.ToInt32(DefaultQuantity));
                        break;
                        }
                        }
                        }
                        }
                        }


                        Thanks!













                        Comment


                          #13
                          Hello darkgreen,

                          Thanks for your reply.

                          I'm at the end of my day today but quickly I would suggest looking at the { } to make sure you have them in the right places, compared to my example.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_PaulH View Post
                            Hello darkgreen,

                            Thanks for your reply.

                            I'm at the end of my day today but quickly I would suggest looking at the { } to make sure you have them in the right places, compared to my example.
                            Thanks for the help Paul.
                            That's as close as I was able to configure this:
                            for (int i = 0; i < 3; i++)
                            {
                            if (bwFractal1.Lower[i] != 0)
                            {
                            _lowerBarsAgo = i;
                            ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
                            break;

                            For some reason the BarsSinceEntryExecution is not cooperating, but as a general guidance, some indicators are fine when you create a strategy using their plots directly from the wizard, and some don't allow you to use all plots, because the validity of the plots isn't numerical or false/true, like this one Bwfractal which is basically Lower=N/A until one is created. How would you call the plot directly? something like 'if plot exists (not a number or true/false) do the following'?

                            Comment


                              #15
                              Hello darkgreen,

                              Thanks for your reply.

                              You are calling both the indicator and the indicators plot directly with bwFractal1.Lower. The current bar [0] of the plot will always be 0 (with this indicator) because the indicator does not draw until at best 2 bars after it has determined the low point, it will then fill the barsago of the Lower plot at a bars ago of [2]. this is why you have to loop back theough the plot values to find the latest occurence in the plot of the indicator by looking for a non-zero value.

                              Regarding the BarSinceEntryExecution(), I suggest that you use a print statment to see that the method is functioning, for example:

                              if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1)
                              {
                              Print (Time[0]+" BarsSinceEntryExecution = "+BarsSinceEntryExecution().ToString());
                              }

                              The print statement send its output to the New>Ninjascript output window.

                              You should expect to see a -1 value before the first entry and then a positive value that increases between entry executions and is reset after each execution. This would prove to you that it is reacting to an entry order.
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by techgetgame, Today, 11:42 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post techgetgame  
                              Started by sephichapdson, Today, 11:36 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sephichapdson  
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,612 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              19 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Working...
                              X