View Full Version : Double Stochastics (bressert dstoch)
Creamers
01-26-2007, 11:49 PM
{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
Creamers
01-28-2007, 04:55 AM
//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?
Creamers
01-28-2007, 06:09 AM
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?
NinjaTrader_Ray
01-28-2007, 09:11 AM
Bart,
Could you give me a high level description of what you want to see?
Ray
tquinn
01-28-2007, 12:06 PM
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]:pctK2[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
}
Creamers
01-29-2007, 04:30 AM
Work like a charm:)
:DThank you very much!
(
The difference:
I -> nom.Set(Close[0] - MIN(Low, Len)[0]);
You -> Num1=Close[0]-MIN(Low, StLen)[0];
):?
momentom
04-06-2009, 09:03 PM
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
NinjaTrader_Bertrand
04-07-2009, 04:23 AM
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/vb/local_links.php?action=jump&id=86&catid=1