NexusFi: Find Your Edge


Home Menu

 





Double Stochs for TOS


Discussion in ThinkOrSwim

Updated
    1. trending_up 3,306 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 3 posts
    2. attach_file 3 attachments




 
Search this Thread

Double Stochs for TOS

  #1 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24

Good day coders.
I have two versions of Double Stochastics that I am overlaying in different periods on the NT platform.
Even with the same settings, they plot differently, but they accomplish my goal.
TOS has a Double Stoch, but it does not mimic the precision of the NT indicators and I'd like to have the same setup in TOS

I saw\how Fattails converted a Kelter from TOS to NT; is there someone who can convert the two codes below into TOS.
There is a subtle difference between the two.

Side note: if anyone knows how to plot a MA line in TOS with the Square style from NT, that would be fantastic!

This is the code for the larger DS in the picture:
//

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Double stochastics
/// </summary>
[Description("Double Stochastics")]
[Gui.Design.DisplayName("anaDoubleStochastics")]
public class anaDoubleStochastics : Indicator
{
#region Variables
private int period = 34;
private int periodEMA = 21;
private Color upColor = Color.Blue;
private Color downColor = Color.Red;
private int plot0Width = 2;
private PlotStyle plot0Style = PlotStyle.Line;
private DashStyle dash0Style = DashStyle.Solid;
private DataSeries p1;
private DataSeries p2;
private DataSeries p3;
#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.Gray, PlotStyle.Line, "K"));
Add(new Line(Color.LightSteelBlue, 90, "Upper"));
Add(new Line(Color.LightSteelBlue, 50, "Middle"));
Add(new Line(Color.LightSteelBlue, 10, "Lower"));
Lines[0].Pen.DashStyle = DashStyle.Dash;
Lines[1].Pen.DashStyle = DashStyle.Dash;

p1 = new DataSeries(this);
p2 = new DataSeries(this);
p3 = new DataSeries(this);

PlotsConfigurable = false;
}

/// <summary>
/// </summary>
protected override void OnStartUp()
{
Plots[0].Pen.Width = plot0Width;
Plots[0].PlotStyle = plot0Style;
Plots[0].Pen.DashStyle = dash0Style;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
double r = MAX(High, Period)[0] - MIN(Low, Period)[0];
r = r.Compare(0, 0.000000000001) == 0 ? 0 : r;

if (r == 0)
p1.Set(CurrentBar == 0 ? 50 : p1[1]);
else
p1.Set(Math.Min(100, Math.Max(0, 100 * (Close[0] - MIN(Low, Period)[0]) / r)));

p2.Set(EMA(p1, periodEMA)[0]);

double s = MAX(p2, Period)[0] - MIN(p2, Period)[0];
s = s.Compare(0, 0.000000000001) == 0 ? 0 : s;

if (s == 0)
p3.Set(CurrentBar == 0 ? 50 : p3[1]);
else
p3.Set(Math.Min(100, Math.Max(0, 100 * (p2[0] - MIN(p2, Period)[0]) / s)));

K.Set(EMA(p3, periodEMA)[0]);

if(CurrentBar < 1)
{
PlotColors[0][0] = upColor;
return;
}
else if (Rising(K))
PlotColors[0][0] = upColor;
else
PlotColors[0][0] = downColor;
}

#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 K
{
get { return Values[0]; }
}

[Description("Select Period for Double Stochastics")]
[GridCategory("Options")]
[Gui.Design.DisplayName("Double Stoch Period")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}

[Description("Select Period for Smoothing Average")]
[GridCategory("Options")]
[Gui.Design.DisplayName("EMA Period")]
public int PeriodEMA
{
get { return periodEMA; }
set { periodEMA = Math.Max(1, value); }
}

/// <summary>
/// </summary>
[XmlIgnore()]
[Description("Select color for rising Double Stochastics")]
[Category("Plot Colors")]
[Gui.Design.DisplayName("Double Stoch Rising")]
public Color UpColor
{
get { return upColor; }
set { upColor = value; }
}

// Serialize Color object
[Browsable(false)]
public string UpColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(upColor); }
set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
}

/// <summary>
/// </summary>
[XmlIgnore()]
[Description("Select color for falling Double Stochastics")]
[Category("Plot Colors")]
[Gui.Design.DisplayName("Double Stoch Falling")]
public Color DownColor
{
get { return downColor; }
set { downColor = value; }
}

// Serialize Color object
[Browsable(false)]
public string DownColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(downColor); }
set { downColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
}

/// <summary>
/// </summary>
[Description("Width for Double Stochastics.")]
[Category("Plot Parameters")]
[Gui.Design.DisplayNameAttribute("Line Width")]
public int Plot0Width
{
get { return plot0Width; }
set { plot0Width = Math.Max(1, value); }
}

/// <summary>
/// </summary>
[Description("DashStyle for Double Stochastics")]
[Category("Plot Parameters")]
[Gui.Design.DisplayNameAttribute("Plot Style")]
public PlotStyle Plot0Style
{
get { return plot0Style; }
set { plot0Style = value; }
}

/// <summary>
/// </summary>
[Description("DashStyle for Double Stochastics")]
[Category("Plot Parameters")]
[Gui.Design.DisplayNameAttribute("Dash Style")]
public DashStyle Dash0Style
{
get { return dash0Style; }
set { dash0Style = value; }
}
#endregion
}
}

#region NinjaScript generated code. Neither change nor remove.


This is the code for the two, faster DS' in the the picture:

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Double stochastics
/// </summary>
[Description("Double stochastics")]
[Gui.Design.DisplayName("DoubleStochastics")]
public class DoubleStochastics : Indicator
{
#region Variables
private int period = 10;
private DataSeries p1;
private DataSeries p2;
private DataSeries p3;
#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.Red, PlotStyle.Line, "K"));
Add(new Line(Color.Blue, 90, "Upper"));
Add(new Line(Color.Blue, 10, "Lower"));
Lines[0].Pen.DashStyle = DashStyle.Dash;
Lines[1].Pen.DashStyle = DashStyle.Dash;

p1 = new DataSeries(this);
p2 = new DataSeries(this);
p3 = new DataSeries(this);
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
double r = MAX(High, Period)[0] - MIN(Low, Period)[0];
r = r.Compare(0, 0.000000000001) == 0 ? 0 : r;

if (r == 0)
p1.Set(CurrentBar == 0 ? 50 : p1[1]);
else
p1.Set(Math.Min(100, Math.Max(0, 100 * (Close[0] - MIN(Low, Period)[0]) / r)));

p2.Set(EMA(p1, 3)[0]);

double s = MAX(p2, Period)[0] - MIN(p2, Period)[0];
s = s.Compare(0, 0.000000000001) == 0 ? 0 : s;

if (s == 0)
p3.Set(CurrentBar == 0 ? 50 : p3[1]);
else
p3.Set(Math.Min(100, Math.Max(0, 100 * (p2[0] - MIN(p2, Period)[0]) / s)));

K.Set(EMA(p3, 3)[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 K
{
get { return Values[0]; }
}

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

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private DoubleStochastics[] cacheDoubleStochastics = null;

private static DoubleStochastics checkDoubleStochastics = new DoubleStochastics();

/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public DoubleStochastics DoubleStochastics(int period)
{
return DoubleStochastics(Input, period);
}

/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
if (cacheDoubleStochastics != null)
for (int idx = 0; idx < cacheDoubleStochastics.Length; idx++)
if (cacheDoubleStochastics[idx].Period == period && cacheDoubleStochastics[idx].EqualsInput(input))
return cacheDoubleStochastics[idx];

lock (checkDoubleStochastics)
{
checkDoubleStochastics.Period = period;
period = checkDoubleStochastics.Period;

if (cacheDoubleStochastics != null)
for (int idx = 0; idx < cacheDoubleStochastics.Length; idx++)
if (cacheDoubleStochastics[idx].Period == period && cacheDoubleStochastics[idx].EqualsInput(input))
return cacheDoubleStochastics[idx];

DoubleStochastics indicator = new DoubleStochastics();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();

DoubleStochastics[] tmp = new DoubleStochastics[cacheDoubleStochastics == null ? 1 : cacheDoubleStochastics.Length + 1];
if (cacheDoubleStochastics != null)
cacheDoubleStochastics.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheDoubleStochastics = tmp;
return indicator;
}
}
}
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.DoubleStochastics DoubleStochastics(int period)
{
return _indicator.DoubleStochastics(Input, period);
}

/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public Indicator.DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
return _indicator.DoubleStochastics(input, period);
}
}
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.DoubleStochastics DoubleStochastics(int period)
{
return _indicator.DoubleStochastics(Input, period);
}

/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public Indicator.DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

return _indicator.DoubleStochastics(input, period);
}
}
}
#endregion


Much Thanks, KySt

Attached Thumbnails
Click image for larger version

Name:	Two DoubleStochs.JPG
Views:	323
Size:	97.8 KB
ID:	169557  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
61 thanks
NexusFi site changelog and issues/problem reporting
46 thanks
Battlestations: Show us your trading desks!
37 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
25 thanks

  #2 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441


KySt View Post
I have two versions of Double Stochastics that I am overlaying in different periods on the NT platform.

Is the second double stochastics one of the default NinjaTrader indicators or custom?

Attached Thumbnails
Click image for larger version

Name:	CL 03-15 (800 Tick)  1_21_2015.jpg
Views:	238
Size:	461.4 KB
ID:	172425  
Reply With Quote
  #3 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441


The faster lines look like regular exponential stochastics but don't know the settings from your chart to compare:



 
Code
declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.EXPONENTIAL;

plot SlowK = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullK;
SlowK.setDefaultColor(GetColor(5));

plot SlowD = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullD;
SlowD.setDefaultColor(GetColor(0));

plot OverBought = over_bought;
OverBought.SetDefaultColor(GetColor(1));

plot OverSold = over_sold;
OverSold.SetDefaultColor(GetColor(1));



# Slow Line
input N2_Period = 21;
input R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);


def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;


def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);

plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Cyan else Color.Red);
DSSsignal.SetLineWeight(3);

Reply With Quote
The following user says Thank You to rmejia for this post:
  #4 (permalink)
 KySt 
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24

Thanks Rmejia.
The slow stochastic with my settings is perfect.
Its behavior is like that of the anaDoubleStochastic in NT.
The mid and faster lines, not so much.
They are true EMA double stochastics. Only need ofor TOS that has the same behavior as that of NT.

-Ky

Started this thread Reply With Quote





Last Updated on January 22, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts