Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Adding amaSuperTrendU11 to custom strategy - compile error
I'm developing a strategy and want to rely on amaSuperTrendU11 indicator. However when I try to declare it as a private amaSuperTrendU11 myIndie; I get a compile error right at the start. CS0118 - Saying something like a method constructor used as a type. What I don't understand is that in the indicator itself the definition is public class amaSuperTrendU11 : Indicator, hence it should be correct.
Can you help answer these questions from other members on NexusFi?
Basically I want to have a reference to the indicator in my strategy.
private amaSuperTrendU11 myIndie;
When I add the line above I can't compile my strategy anymore. (CS0118 - method used like a type.) I recon the compiler thinks the amaSuperTrendU11 is a constructor call instead of the type definition. However as I looked into the source of the indicator I saw the following definition:
public class amaSuperTrendU11 : Indicator{...}
So if the class name is indeed amaSuperTrendU11 then I should be able to use it as a type right?
(While doing this I was following this forum:
My 2 cents to what you showed so far.
Cent 1: In trading you want to foul other traders but not yourself. So always run backtests with commissions.
Cent 2: More compact way to deal with indicators -
a. In variables make new variable - private anaSuperTrend …
)
In the end I want to have a reference (myIndie), that I initialize at startup (myIndie = amaSuperTrendU11(...) and then finally get the Trend variable of the indicator in my strategy. Meanwhile the forum uses anaSuperTrend as I'm on Ninja 8 I decided to use amaSuperTrendU11
That is exactly what I did (but swapped the EMA name to the amaSuperTrendU11)... And it broke somehow immediately. Maybe I will ask Fat Tails. Thanks for the blog post snippet!
The amaSuperTrendU11 may be used with automated strategies without restrictions. I have already created a few SuperTrend strategies that were just doing fine.
In case that you do not know, how to call the amaSuperTrendU11 from a strategy, this is what I recommend:
- open the strategy builder and create a simple stop and reverse strategy by using the trend plot from the amaSuperTrendU11
- unlock and compile the strategy to make sure that it works as expected
Now study the code of the strategy and copy what you need. Below is a sample strategy that compiles. I think it will probably answer your questions.
I am trying to imply this indicator into the strategy builder NT8 but error coming.
namespace NinjaTrader.NinjaScript.Indicators.Sim22
{
/// <summary>
/// The Stochastic Oscillator is made up of two lines that oscillate between a vertical scale of 0 to 100. The %K is the main line and it is drawn as a solid line. The second is the %D line and is a moving average of %K. The %D line is drawn as a dotted line. Use as a buy/sell signal generator, buying when fast moves above slow and selling when fast moves below slow.
/// Sim22 May 2016 NT8b11.
/// Update V1.1: Moved input code to State.DataLoaded due to exceptions when placed in the market analyzer
/// </summary>
public class Sim22_DoubleStochastic_Colored_AnyInputGLV1 : Indicator
{
#region Variables
private EMA emaP1;
private EMA emaP3;
private MIN minLow;
private MIN minP2;
private MAX maxHigh;
private MAX maxP2;
private Series<double> p1;
private Series<double> p2;
private Series<double> p3;
private int barNumberFromSessOpen;
private double gap = 0.0;
bool isPriceSeries = true;
}
else if (State == State.DataLoaded)
{
////Update 1.1. Moved code here due to exceptions raised when placed in a market analyzer
///
/// Instrument price type
if (Input.GetType() == typeof(NinjaTrader.NinjaScript.PriceSeries))
{
isPriceSeries = true;
maxHigh = MAX(High, Period);
minLow = MIN(Low, Period);
}
else
/// Indicator
{
isPriceSeries = true;
UseGapless = false;
maxHigh = MAX(Input, Period);
minLow = MIN(Input, Period);
}
}
}
public override void OnCalculateMinMax()
{
/// Maintains a fixed scale to show full range of stochastic.
MinValue = 0.0;
MaxValue = 100.00;
if (PlotReversals)
{
MinValue -= Plots[3].Width * 2;
MaxValue += Plots[4].Width * 2;
}
}
public override string DisplayName
{
get { return String.Format("DStoch" + (UseGapless ? "'GL'" : "") + "({0})", Period); }
}
public override string FormatPriceMarker(double value)
{
/* using static class Sim22_PriceFormatter in the Addons folder */
if (dpEnum == Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum.SameAsInstrument)
return Sim22_PriceFormatter.FormatSameAsInstrumentPrice(value, TickSize);
else
return value.ToString("N" + Sim22_PriceFormatter.FormatNumberDecimalPlaces(dpEnum).ToString());
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KUpper
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KMiddle
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KLower
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KReversalUp
{
get { return Values[3]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KReversalDown
{
get { return Values[4]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KPopUp
{
get { return Values[5]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> KPoopDown
{
get { return Values[6]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> K
{
get { return Values[7]; }
}
[NinjaScriptProperty]
[Display(Name="Decimal Places", Description="", Order=0, GroupName="Set up")]
public Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum DPEnum
{
get { return dpEnum; }
set { dpEnum = value; }
}
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "(Intraday) Plot gapless?", GroupName = "NinjaScriptParameters", Order = 0)]
public bool UseGapless
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 2)]
public int Period
{ get; set; }
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,020
Fat Tails, created the simple sample reverse strategy in Strategy Builder exactly as you have posted here to confirm amaSupertrend11 would work in a strategy. It compiled fine but Strategy Analyzer would not take any trades with it. I was not expecting it to be a winning trade but at least one in a year back test.
SO I was going to ask for help here. Then I realized how dumb I was to think that the trend would be less than zero when it is based on price.
So now it works - not a winning strategy but it does take trades. Any chance you would post a strategy builder created one that is at least marginally profitable? Or for that matter any strategy marginally profitable. Thanks for your continued support.
I only do a few postings here compared to what you have done. So I did not use "@" before your name because I expect you get way too many emails telling you've been mentioned.