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

Double Stochastics (bressert dstoch)

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

    Double Stochastics (bressert dstoch)

    {Stoc-1}
    _$Num1=C-Lowest(L,STLen);
    _$Denom1=Highest(H,STLen)-Lowest(L,STLen);
    _$Ratio1=IFF(_$Denom1>0,(_$Num1/_$Denom1)*100,_$Ratio1[1]);
    _$PctK1=IFF(CurrentBar=1,_$Ratio1,_$PctK1[1]+(.5*(_$Ratio1-_$PctK1[1])));

    {Stoc-2}
    _$Num2=_$PctK1-Lowest(_$PctK1,STLen);
    _$Denom2=Highest(_$PctK1,STLen)-Lowest(_$PctK1,STLen);
    _$Ratio2=IFF(_$Denom2>0,(_$Num2/_$Denom2)*100,_$Ratio2[1]);
    _$PctK2=IFF(CurrentBar=1,_$Ratio2,_$PctK2[1]+(.5*(_$Ratio2-_$PctK2[1])));

    plot1(_$PctK2,"stoc");

    Tried it with the stochastic ninjatrader code, but failed to get the right result....

    Could someone help me out converting above code to NT code?



    greetings,

    Bart

    #2
    imported post

    //stoc1

    nom.Set(Close[0] - MIN(Low, Len)[0]);
    den.Set(MAX(High, Len)[0] - MIN(Low, Len)[0]);
    ratio.Set(den[0]>0 ? (nom[0] / den[0])*100 : ratio[1]);
    pctk1.Set(CurrentBar == 0 ? ratio[0] : pctk1[1] + (0.5 * (ratio[0] - pctk1[1])));
    Plot0.Set(pctk1[0]);


    //stoc2


    nom2.Set(pctk1[0] - MIN(pctk1, Len)[0]);
    den2.Set(MAX(pctk1, Len)[0] - MIN(pctk1, Len)[0]);
    //ratio2.Set((den2[0]>0) ? ((nom2[0] / den2[0])*100) : ratio2[1]);
    //pctk12.Set(CurrentBar == 0 ? ratio2[0] : pctk12[1] + (0.5 * (ratio2[0] - pctk12[1])));

    Stoc1 works fine, but as soon I UNcomment the stoc2 lines the indicatorlines disappear in the chart!

    What am I doing wrong?


    Comment


      #3
      imported post

      Another strange thing happens:

      dstoc1 indicator works fine and plots on the chart.

      As soon as I create another indicator(2) that uses dstoc1 indicator like this: Indicator2 uses: Plot1.Set(dstoc(Low,10)[0]);

      It effects the plotted dstoc1 indicator?

      I should see 2 different indicators on the chart right?


      Comment


        #4
        imported post

        Bart,

        Could you give me a high level description of what you want to see?

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          This is my approach. It plots Stoc1&Stoc2 given in your TS sample code.

          Ray, always has cleaner code than me. If/when he responds, it will be clearer.

          /// <summary>
          /// TS double Stochastic from Forum
          /// </summary>
          [Description("TS double Stochastic from Forum")]
          [Gui.Design.DisplayName("DoubleStoc")]
          public class DoubleStoc : Indicator
          {
          #region Variables
          //Input Variable
          private int stLen = 12;

          // User defined variables (add any user defined variables below)
          private double Num1=(0); private double Num2=(0);
          private double Denom1=(0); private double Denom2=(0);

          private DataSeries ratio1;
          private DataSeries ratio2;
          private DataSeries pctK1;
          private DataSeries pctK2;
          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.Orange, PlotStyle.Line, "Plot0"));
          Add(new Plot(Color.Blue, PlotStyle.Line, "Plot1"));
          StLen = 12;
          CalculateOnBarClose = true;
          Overlay = false;
          PriceTypeSupported = false;

          // Private DataSeries used in calcs, but not made public
          pctK1 = new DataSeries(this);
          pctK2 = new DataSeries(this);
          ratio1 = new DataSeries(this);
          ratio2 = new DataSeries(this);
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if(CurrentBar>stLen)
          {
          // {Stoc-1}
          Num1=Close[0]-MIN(Low, StLen)[0];
          Denom1=MAX(High, StLen)[0]-MIN(Low, StLen)[0];
          ratio1.Set(Denom1>0 ? (Num1 / Denom1)*100 : ratio1[1]);
          pctK1.Set(CurrentBar==1? ratio1[0]: pctK1[1]+(.5*(ratio1[0]-pctK1[1])));
          Plot0.Set(pctK1[0]);

          // {Stoc-2}
          Num2=pctK1[0]-MIN(pctK1,StLen)[0];
          Denom2=MAX(pctK1,StLen)[0]-MIN(pctK1,StLen)[0];
          ratio2.Set(Denom2>0?(Num2/Denom2)*100:ratio2[1]);
          pctK2.Set(CurrentBar==1?ratio2[0]ctK2[1]+(.5*(ratio2[0]-pctK2[1])));

          Plot1.Set(pctK2[0]);
          }
          }

          #region Properties
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries Plot0
          {
          get { return Values[0]; }
          }
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries Plot1
          {
          get { return Values[1]; }
          }

          [Description("")]
          [Category("Parameters")]
          public int StLen
          {
          get { return stLen; }
          set { stLen = Math.Max(1, value); }
          }
          #endregion
          }

          Comment


            #6
            imported post

            Work like a charm

            Thank you very much!



            (



            The difference:

            I -> nom.Set(Close[0] - MIN(Low, Len)[0]);


            You -> Num1=Close[0]-MIN(Low, StLen)[0];

            ):?

            Comment


              #7
              I'm not a programer.

              I copied and paste this and tried to compile as an indicator but got a numer of errors beginning at line 45. Is this because of the change in NT since 2004?
              Can anyone help pls.

              TIA

              Comment


                #8
                This might be the reason momentom, you can double click on each error listed on the bottom and see where it was found...if you don't want to debug this, you can directly import this one - http://www.ninjatrader-support2.com/...&id=86&catid=1
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Tim-c, Today, 10:58 AM
                0 responses
                1 view
                0 likes
                Last Post Tim-c
                by Tim-c
                 
                Started by traderqz, Yesterday, 09:06 AM
                3 responses
                21 views
                0 likes
                Last Post NinjaTrader_ThomasC  
                Started by f.saeidi, Today, 10:19 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by kujista, Today, 06:23 AM
                5 responses
                18 views
                0 likes
                Last Post kujista
                by kujista
                 
                Started by traderqz, Today, 12:06 AM
                3 responses
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X