Double Stochs for TOS - futures io
futures io futures trading



Double Stochs for TOS


Discussion in ThinkOrSwim

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Double Stochs for TOS

(login for full post details)
  #1 (permalink)
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
 
Posts: 91 since Mar 2011
Thanks: 17 given, 24 received

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:	122
Size:	97.8 KB
ID:	169557  
Started this thread Reply With Quote

Journal Challenge February 2021 results:
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(172 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(120 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: ES
 
rmejia's Avatar
 
Posts: 377 since Oct 2010
Thanks: 3,600 given, 432 received


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:	89
Size:	461.4 KB
ID:	172425  
Reply With Quote
 
(login for full post details)
  #3 (permalink)
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: ES
 
rmejia's Avatar
 
Posts: 377 since Oct 2010
Thanks: 3,600 given, 432 received


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:
 
(login for full post details)
  #4 (permalink)
Accokeek, USA
 
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
 
Posts: 91 since Mar 2011
Thanks: 17 given, 24 received

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


futures io Trading Community Platforms and Indicators ThinkOrSwim > Double Stochs for TOS


Last Updated on January 22, 2015


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts