NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-26-2007, 11:49 PM   #1
Creamers
Member
 
Join Date: Dec 2004
Location: , ,
Posts: 68
Thanks: 4
Thanked 3 times in 1 post
Post imported post

{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 is offline  
Reply With Quote
Old 01-28-2007, 04:55 AM   #2
Creamers
Member
 
Join Date: Dec 2004
Location: , ,
Posts: 68
Thanks: 4
Thanked 3 times in 1 post
Post 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?


Creamers is offline  
Reply With Quote
Old 01-28-2007, 06:09 AM   #3
Creamers
Member
 
Join Date: Dec 2004
Location: , ,
Posts: 68
Thanks: 4
Thanked 3 times in 1 post
Post 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?


Creamers is offline  
Reply With Quote
Old 01-28-2007, 09:11 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Bart,

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

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 01-28-2007, 12:06 PM   #5
tquinn
Senior Member
 
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
Post 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.

Quote:
/// <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
}
tquinn is offline  
Reply With Quote
Old 01-29-2007, 04:30 AM   #6
Creamers
Member
 
Join Date: Dec 2004
Location: , ,
Posts: 68
Thanks: 4
Thanked 3 times in 1 post
Post 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];

):?

Creamers is offline  
Reply With Quote
Old 04-06-2009, 09:03 PM   #7
momentom
Member
 
Join Date: Apr 2007
Location: , ,
Posts: 89
Thanks: 0
Thanked 0 times in 0 posts
Default

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
momentom is offline  
Reply With Quote
Old 04-07-2009, 04:23 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:48 PM.