Help! - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help!
Updated: Views / Replies:1,622 / 2
Created: by cclsys Attachments:2

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Help!

  #1 (permalink)
Elite Member
Sydney, NS
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: Zen-Fire
Favorite Futures: TF,S,GC
 
cclsys's Avatar
 
Posts: 607 since Nov 2009
Thanks: 248 given, 379 received

Help!

I tried to code an extremely simple thing this afternoon. In TS it would take me about 2 minutes to write. After 30 minutes, I am nowhere.

The idea is simple and something I might put into the FibRatioBand indicator and also was going to offer to Cory to experiment with in Volume Stop, which is actually why I thought of it.

The idea: if the Donchian Range x period is less than the ATR (period) * Multiplier, then the current swing range is too narrow for a volume stop (or in FibBand case, for a band target to be triggered).

Now how simple is that?

I cannot get the code to work the way I want it. I had no problem at all to code in:

ATR value changing color if narrower or wider than Donchian range.

But when I tried to have 2 plots for the Donchian range line, one 1 color if the swing is up and a different color when down, using a simple condition (if the EMA(period)[0] > EMA(period)[1]), although it compiles fine, it gets an error and won't plot.

Err msg: Error on calling the onbar update method ....index was out of range, must be non-negative and less than the size of the parameter name: index. Have no idea what that means.

And no idea what is wrong with my code.

Would be grateful if anyone could explain what it is I am doing wrong here. After one year with Ninja I still find problems like this doing the most simple of things and still cannot figure out why.

+++++++++++++++++++++++

PS. I have worked around the problem by using Slope(...) instead, but I would still appreciate learning why the original won't work, simple as it is. Attached is picture. I think Cory might find this useful for filtering out some of the volume stops in the additional patterns that are being worked on somewhere on the forum. It's not meant so much as an 'indicator' as a condition. I made it first into an indicator to see it, that's all.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


+++++++++++++++++++++++

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

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
[Description("Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.")]
public class ATRDonchian : Indicator
{
#region Variables
// Wizard generated variables
private int drange = 5; // Default setting for Drange
private double aTRMult = 2; // Default setting for ATRMult
private int aTRPeriod = 37; // Default setting for ATRPeriod
private double atrv = 0; // ATR value
private double drangev = 0; // Donchian range value
// User defined variables (add any user defined variables below)
#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()
{
if (CurrentBar < ATRPeriod *2) return;

Add(new Plot(Color.FromKnownColor(KnownColor.Fuchsia), PlotStyle.Bar, "ATRnarrow"));
Add(new Plot(Color.FromKnownColor(KnownColor.LimeGreen), PlotStyle.Bar, "ATRwide"));
Add(new Plot(Color.FromKnownColor(KnownColor.DarkTurquoise), PlotStyle.Line, "Ddown"));
Add(new Plot(Color.FromKnownColor(KnownColor.Goldenrod), PlotStyle.Line, "Dup"));
CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
atrv = ATR(ATRPeriod)[0]*ATRMult;
drangev = DonchianChannel(drange).Upper[0] - DonchianChannel(drange).Lower[0];

if ( drangev <= atrv)
{ATRnarrow.Set(atrv);}
else ATRwide.Set(atrv);

//if (EMA(drange)[0] < EMA(drange)[1])

Ddown.Set(drangev);
//else
//Dup.Set(drangev);
}

#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 ATRnarrow
{
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 ATRwide
{
get { return Values[1]; }
}

[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 Ddown
{
get { return Values[2]; }
}

[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 Dup
{
get { return Values[3]; }
}

[Description("Donchian Period")]
[Category("Parameters")]
public int Drange
{
get { return drange; }
set { drange = Math.Max(1, value); }
}

[Description("ATR Multiplier")]
[Category("Parameters")]
public double ATRMult
{
get { return aTRMult; }
set { aTRMult = Math.Max(.1, value); }
}

[Description("Default ATR Period")]
[Category("Parameters")]
public int ATRPeriod
{
get { return aTRPeriod; }
set { aTRPeriod = 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 ATRDonchian[] cacheATRDonchian = null;

private static ATRDonchian checkATRDonchian = new ATRDonchian();

/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
public ATRDonchian ATRDonchian(double aTRMult, int aTRPeriod, int drange)
{
return ATRDonchian(Input, aTRMult, aTRPeriod, drange);
}

/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
public ATRDonchian ATRDonchian(Data.IDataSeries input, double aTRMult, int aTRPeriod, int drange)
{
checkATRDonchian.ATRMult = aTRMult;
aTRMult = checkATRDonchian.ATRMult;
checkATRDonchian.ATRPeriod = aTRPeriod;
aTRPeriod = checkATRDonchian.ATRPeriod;
checkATRDonchian.Drange = drange;
drange = checkATRDonchian.Drange;

if (cacheATRDonchian != null)
for (int idx = 0; idx < cacheATRDonchian.Length; idx++)
if (Math.Abs(cacheATRDonchian[idx].ATRMult - aTRMult) <= double.Epsilon && cacheATRDonchian[idx].ATRPeriod == aTRPeriod && cacheATRDonchian[idx].Drange == drange && cacheATRDonchian[idx].EqualsInput(input))
return cacheATRDonchian[idx];

ATRDonchian indicator = new ATRDonchian();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.ATRMult = aTRMult;
indicator.ATRPeriod = aTRPeriod;
indicator.Drange = drange;
indicator.SetUp();

ATRDonchian[] tmp = new ATRDonchian[cacheATRDonchian == null ? 1 : cacheATRDonchian.Length + 1];
if (cacheATRDonchian != null)
cacheATRDonchian.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheATRDonchian = tmp;
Indicators.Add(indicator);

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>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRDonchian ATRDonchian(double aTRMult, int aTRPeriod, int drange)
{
return _indicator.ATRDonchian(Input, aTRMult, aTRPeriod, drange);
}

/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
public Indicator.ATRDonchian ATRDonchian(Data.IDataSeries input, double aTRMult, int aTRPeriod, int drange)
{
return _indicator.ATRDonchian(input, aTRMult, aTRPeriod, drange);
}

}
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRDonchian ATRDonchian(double aTRMult, int aTRPeriod, int drange)
{
return _indicator.ATRDonchian(Input, aTRMult, aTRPeriod, drange);
}

/// <summary>
/// Showing both ATR*multiplier and Donchian H-L range to compare. Can be used as condition for triggers in other methods.
/// </summary>
/// <returns></returns>
public Indicator.ATRDonchian ATRDonchian(Data.IDataSeries input, double aTRMult, int aTRPeriod, int drange)
{
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.ATRDonchian(input, aTRMult, aTRPeriod, drange);
}

}
}
#endregion


Last edited by cclsys; November 23rd, 2009 at 05:05 PM.
Reply With Quote
 
  #2 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,366 since Jun 2009
Thanks: 3,573 given, 3,982 received

Try this one (bad idea in initialize ).
Bad:
 
Code
                            
protected override void Initialize()
{
    if (
CurrentBar ATRPeriod *2) return; 
Better:
 
Code
                            
protected override void OnBarUpdate()
{
if (
CurrentBar ATRPeriod *2
    return; 

Success requires no deodorant! (Sun Tzu)
Attached Files
Register to download File Type: zip ATRDonchian.zip (8.5 KB, 24 views)

Last edited by sam028; November 23rd, 2009 at 05:14 PM. Reason: add details
Reply With Quote
 
  #3 (permalink)
Elite Member
Sydney, NS
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: Zen-Fire
Favorite Futures: TF,S,GC
 
cclsys's Avatar
 
Posts: 607 since Nov 2009
Thanks: 248 given, 379 received


Sam thanks. I figured that out this morning. Am in a Ninja script slump right now. Everything I try to do is bass ackwards. I think it's because I was working with a little TS script over the weekend. Scrambled me.

Reply With Quote

Reply



futures io > > > > > Help!

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     


All times are GMT -4. The time now is 09:39 PM.

Copyright © 2017 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
Page generated 2017-12-15 in 0.12 seconds with 19 queries on phoenix via your IP 54.91.171.137