Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bill-Williams-Divergent-Bars

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

    Bill-Williams-Divergent-Bars

    Hi

    I would like to copy the divergence bar indicator from tradeview tot ninjatrader 8.
    this the link of the orignal indicator.
    WDlVczZNWEpFMGIwb1pEZlo3VzZ3dkh2UDJhUlF1YWtwSWZFbW hXME93YlViUHlPNU9vVVdvYmVVMW9lckhueg

    i have already this, Can someone help with it?

    Thanks.




    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class divergencebar1 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "Divergencebar2.0";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    }


    double price = (High[0] + Low[0]) / 2;
    protected override void OnBarUpdate()
    {

    int jawLength = 13;
    int teethLength = 8;
    int lipsLength = 5;
    int jawDisplace = -8;
    int teethDisplace = -5;
    int lipsDisplace = -3;

    double lips = SMA(price[-lipsDisplace],lipsLength)[0];
    double teeth = SMA(price[-teethDisplace],lipsLength)[0];
    double jaw = SMA(price[-jawDisplace],lipsLength)[0];

    bool bullDivSignal = Low < Low[1] && close > hl2 & high < lips && High < teeth && high < jaw;
    bool bearDivSignal = High > High[1] && close < hl2 && low > lips && Low > teeth && low > jaw;

    def sState = bullDivSignal ? 100 : (bearDivSignal ? -100 : sState[1]);

    AddPlot(Brushes.Green, "bull");
    AddPlot(Brushes.Red, "bear");

    //#COLORBARS
    //input showColorBars = yes;
    //AssignPriceColor(if showColorBars then
    //if sState > 0 then Color.GREEN
    // else Color.RED
    //else
    // COLOR.CURRENT
    //);

    //#LABELS
    //input showLabels = yes;
    //AddLabel(showLabels, "Buy",
    //if isNaN(sState) then COLOR.DARK_GRAY else
    // If bullDivSignal then COLOR.GREEN else COLOR.DARK_GRAY);

    //AddLabel(showLabels, "Sell",
    //if isNaN(sState) then COLOR.DARK_GRAY else
    // If bearDivSignal then COLOR.RED else COLOR.DARK_GRAY);

    }
    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private divergencebar1[] cachedivergencebar1;
    public divergencebar1 divergencebar1()
    {
    return divergencebar1(Input);
    }

    public divergencebar1 divergencebar1(ISeries<double> input)
    {
    if (cachedivergencebar1 != null)
    for (int idx = 0; idx < cachedivergencebar1.Length; idx++)
    if (cachedivergencebar1[idx] != null && cachedivergencebar1[idx].EqualsInput(input))
    return cachedivergencebar1[idx];
    return CacheIndicator<divergencebar1>(new divergencebar1(), input, ref cachedivergencebar1);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.divergencebar1 divergencebar1()
    {
    return indicator.divergencebar1(Input);
    }

    public Indicators.divergencebar1 divergencebar1(ISeries<double> input )
    {
    return indicator.divergencebar1(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.divergencebar1 divergencebar1()
    {
    return indicator.divergencebar1(Input);
    }

    public Indicators.divergencebar1 divergencebar1(ISeries<double> input )
    {
    return indicator.divergencebar1(input);
    }
    }
    }

    #endregion





    #2
    Hello Negustrader,

    Thank you for the post.

    The link you provided does not appear to be valid, if you had something specific you wanted to provide as code I would suggest to just copy that into a reply and put it in a code block.

    The indicator you attached does not appear to be valid, you have some code outside of OnBarUpdate and also code which does not belong inside OnBarUpdate. The following line belongs in OnBarUpdate:

    double price = (High[0] + Low[0]) / 2;

    The AddPlot lines would go in OnStateChange in State.Configure. You can read about these concepts in the help guide, if you use the search feature for AddPlot you can find some examples. You can also create a new indicator in the NinjaScript editor and just use the Plots page to generate plots. https://ninjatrader.com/support/help...ghtsub=addplot

    Did you otherwise have a specific question for this code?

    Please let me know if I may be of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3


      Code:
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class divergencebar1 : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "Divergencebar2.0";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      IsSuspendedWhileInactive = true;
      }
      else if (State == State.Configure)
      {
      }
      }
      
      
      double price = (High[0] + Low[0]) / 2;
      protected override void OnBarUpdate()
      {
      
      int jawLength = 13;
      int teethLength = 8;
      int lipsLength = 5;
      int jawDisplace = -8;
      int teethDisplace = -5;
      int lipsDisplace = -3;
      
      double lips = SMA(price[-lipsDisplace],lipsLength)[0];
      double teeth = SMA(price[-teethDisplace],lipsLength)[0];
      double jaw = SMA(price[-jawDisplace],lipsLength)[0];
      
      bool bullDivSignal = Low < Low[1] && close > hl2 & high < lips && High < teeth && high < jaw;
      bool bearDivSignal = High > High[1] && close < hl2 && low > lips && Low > teeth && low > jaw;
      
      def sState = bullDivSignal ? 100 : (bearDivSignal ? -100 : sState[1]);
      
      AddPlot(Brushes.Green, "bull");
      AddPlot(Brushes.Red, "bear");
      
      //#COLORBARS
      //input showColorBars = yes;
      //AssignPriceColor(if showColorBars then
      //if sState > 0 then Color.GREEN
      // else Color.RED
      //else
      // COLOR.CURRENT
      //);
      
      //#LABELS
      //input showLabels = yes;
      //AddLabel(showLabels, "Buy",
      //if isNaN(sState) then COLOR.DARK_GRAY else
      // If bullDivSignal then COLOR.GREEN else COLOR.DARK_GRAY);
      
      //AddLabel(showLabels, "Sell",
      //if isNaN(sState) then COLOR.DARK_GRAY else
      // If bearDivSignal then COLOR.RED else COLOR.DARK_GRAY);
      
      }
      }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private divergencebar1[] cachedivergencebar1;
      public divergencebar1 divergencebar1()
      {
      return divergencebar1(Input);
      }
      
      public divergencebar1 divergencebar1(ISeries<double> input)
      {
      if (cachedivergencebar1 != null)
      for (int idx = 0; idx < cachedivergencebar1.Length; idx++)
      if (cachedivergencebar1[idx] != null && cachedivergencebar1[idx].EqualsInput(input))
      return cachedivergencebar1[idx];
      return CacheIndicator<divergencebar1>(new divergencebar1(), input, ref cachedivergencebar1);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.divergencebar1 divergencebar1()
      {
      return indicator.divergencebar1(Input);
      }
      
      public Indicators.divergencebar1 divergencebar1(ISeries<double> input )
      {
      return indicator.divergencebar1(input);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.divergencebar1 divergencebar1()
      {
      return indicator.divergencebar1(Input);
      }
      
      public Indicators.divergencebar1 divergencebar1(ISeries<double> input )
      {
      return indicator.divergencebar1(input);
      }
      }
      }
      
      #endregion

      The error list

      Severity Code Description Project File Line Suppression State
      Error CS0103 The name 'low' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0236 A field initializer cannot reference the non-static field, method, or property 'NinjaScriptBase.High' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 53 Active
      Error CS0236 A field initializer cannot reference the non-static field, method, or property 'NinjaScriptBase.Low' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 53 Active
      Error CS0021 Cannot apply indexing with [] to an expression of type 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 64 Active
      Error CS0021 Cannot apply indexing with [] to an expression of type 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 65 Active
      Error CS0021 Cannot apply indexing with [] to an expression of type 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 66 Active
      Error CS0019 Operator '<' cannot be applied to operands of type 'ISeries<double>' and 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0103 The name 'close' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0103 The name 'hl2' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0103 The name 'high' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0019 Operator '<' cannot be applied to operands of type 'ISeries<double>' and 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0103 The name 'high' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 68 Active
      Error CS0019 Operator '>' cannot be applied to operands of type 'ISeries<double>' and 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0103 The name 'close' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0103 The name 'hl2' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0019 Operator '>' cannot be applied to operands of type 'ISeries<double>' and 'double' NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0103 The name 'low' does not exist in the current context NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 69 Active
      Error CS0246 The type or namespace name 'def' could not be found (are you missing a using directive or an assembly reference?) NinjaTrader.Custom C:\Users\simon_000\Documents\NinjaTrader 8\bin\Custom\Indicators\divergencebar1.cs 71 Active
      Bill William Bull/Bear divergent bars See: Book, Trading Chaos by Bill Williams Coded by polyclick A bullish (green) divergent bar, signals a trend switch from bear -> bull -> The current bar has a lower low than the previous bar, but closes in the upper half of the candle. -> This means the bulls are pushing from below and are trying to take over, potentially resulting in a trend switch to bullish. -> We also check if this bar is below the three alligator lines to avoid false …

      Comment


        #4
        Hello Negustrader,

        It looks like this file is similar to the one you provided previously, my previous comments would still apply here.

        The file you have provided contains a lot of problems, you would likely be best off to remove this file and start over from the original script that is working. Once you have the original duplicated we could walk through any changes that you may want to add.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          This is the original code, it is written in Pinscript, its from tradingview. I would like to convert it to ninjascript. I have no program skills.
          a friend has already starded (thas was the code in the first post) but he has no knowledge of trading.

          Code:
          // Bill William Bull/Bear divergent bars
          // See: Book, Trading Chaos by Bill Williams
          //
          // Coded by polyclick
          //
          // A bullish (green) divergent bar, signals a trend switch from bear -> bull
          // -> The current bar has a lower low than the previous bar, but closes in the upper half of the candle.
          // -> This means the bulls are pushing from below and are trying to take over, potentially resulting in a trend switch to bullish.
          // -> We also check if this bar is below the three alligator lines to avoid false positives.
          //
          // A bearish (red) divergent bar, signals a trend switch from bull -> bear
          // -> The current bar has a higher high than the previous bar, but closes in the lower half of the candle.
          // -> This means the bears are pushing the price down and are taking over, potentially resulting in a trend switch to bearish.
          // -> We also check if this bar is above the three alligator lines to avoid false positives.
          //
          // Best used in combination with the Bill Williams Alligator indicator.
          //
          study(title="Divergent Bars")
          
          // utility function for smoothed average
          smma(src, length) =>
          smma = na(smma[1]) ? sma(src, length) : (smma[1] * (length - 1) + src) / length
          smma
          
          // teeth (bill w red line)
          lips = smma(hl2, 5)[3]
          teeth = smma(hl2, 8)[5]
          jaw = smma(hl2, 13)[8]
          
          // signals
          bullDivSignal = low < low[1] and close > hl2 and high < lips and high < teeth and high < jaw
          bearDivSignal = high > high[1] and close < hl2 and low > lips and low > teeth and low > jaw
          
          // plot
          plot(bullDivSignal, title="Bullish divergent bars", style=histogram, linewidth=3, color=green)
          plot(bearDivSignal, title="Bearish divergent bars", style=histogram, linewidth=3, color=red)
          Last edited by Negustrader; 11-25-2020, 09:35 AM.

          Comment


            #6
            Hello Negustrader,

            Thank you for the reply.

            While I cannot make this for you we can walk through the parts you are unclear on in case you wanted to learn how to code this. If you are looking to have this developed for you please let me know and I will have someone follow up with information on that subject.

            The previous script you provided you can fix however it will take some reviewing the resources that we provide so you are putting the code in the right places. The links I had provided show an example of where you can use AddPlot and also we can go over where the other code I mentioned would need to go if you would like.


            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse

              Yes I would like this indicator developed. Can you recommend someone?

              Thanks for all the help.

              Comment


                #8
                Hello Negustrader,

                Thank you for your interest in NinjaTrader.

                You can search our list of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:
                You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

                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 companies and services 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.

                Let me know if I may be of further assistance.
                Christopher S.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by John Bogui, Today, 03:57 AM
                2 responses
                12 views
                0 likes
                Last Post John Bogui  
                Started by Dolfan, 12-30-2020, 12:04 PM
                9 responses
                52 views
                0 likes
                Last Post timko
                by timko
                 
                Started by condorhero, Yesterday, 09:28 PM
                0 responses
                13 views
                0 likes
                Last Post condorhero  
                Started by MaraAnkh, Yesterday, 08:44 PM
                0 responses
                15 views
                0 likes
                Last Post MaraAnkh  
                Started by wooofad, Yesterday, 05:38 PM
                0 responses
                10 views
                0 likes
                Last Post wooofad
                by wooofad
                 
                Working...
                X