rg83 Posted October 17, 2012 Report Share Posted October 17, 2012 Can someone help me, I am trying to adjust the code to show bullish and bearish .786 retracement triangles. I have an error as it wont plot, any help would be great! #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 namespace NinjaTrader.Indicator { /// <summary> /// detects bullish and bearish and sets value to 1 or -1 or 0 if not found /// </summary> [Description("detects bullish and bearish and sets value to 1 or -1 or 0 if not found")] public class RetracementAtempt1 : Indicator { #region Variables // Wizard generated variables private double zigZagPercentDeviation = 0.05; // Default setting for ZigZagPercentDeviation private double tolerancePercent = 5; // Default setting for TolerancePercent private IntSeries ipatternType; private DataSeries patternType; private DataSeries x; private DataSeries idealProfitTarget; private Color penColor = Color.Orange; private int penWidth= 20; private DashStyle dashStyle=System.Drawing.Drawing2D.DashStyle.Dash; private int barsBack=250; // 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() { CalculateOnBarClose = true; Overlay = true; PriceTypeSupported = true; ipatternType=new IntSeries(this); patternType=new DataSeries(this); x=new DataSeries(this); idealProfitTarget=new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> private double Diagonal(double A,double B){ return Math.Sqrt(A*A+B*B); } protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. patternType.Set(0); double B=0; double A=0; //double x=0; double AB=0; double XA=0; double time_CD=0; bool useHighLow=false; bool bBearish=false; int FirstHigh=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).HighBar(0,1,barsBack); int SecondHigh=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).HighBar(0,2,barsBack); int FirstLow=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).LowBar(0,1,barsBack); int SecondLow=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).LowBar(0,2,barsBack); int ThirdLow=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).LowBar(0,3,barsBack); int ThirdHigh=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow).HighBar(0,3,barsBack); if(FirstHigh==-1 || SecondHigh==-1 || FirstLow==-1 || SecondLow==-1) return; if(FirstLow<FirstHigh) { // bullish case if(SecondLow==-1) return; B=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[FirstLow]; A=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[FirstHigh]; x.Set(ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[secondLow]); AB=Diagonal(B-A,FirstLow-FirstHigh); XA=Diagonal(A-X[0],FirstHigh-SecondLow); } else { // bearish case if(ThirdHigh==-1) return; B=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[FirstHigh]; A=ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[FirstLow]; x.Set(ZigZag(DeviationType.Percent,ZigZagPercentDeviation,useHighLow)[secondHigh]); AB=Diagonal(B-A,FirstLow-FirstHigh); XA=Diagonal(A-X[0],SecondHigh-FirstLow); bBearish=true; } //Print("Currentbar="+CurrentBar.ToString()); // Print(AB); // Print(time_CD); // Print(XA); // Print(BC); // Print(CD); if(AB<=0.618*(1-TolerancePercent/100)*XA || AB>=0.786*(1+TolerancePercent/100)*XA) return; // now conditions: string tag=CurrentBar.ToString(); bool bautoscale=true; if(bBearish) { ipatternType.Set(GartleyButterflyPatternType.Bearish); patternType.Set((double)GartleyButterflyPatternType.Bearish); idealProfitTarget.Set(B-0.618*AB); tag+="0.786 Bearish Retracement"; DrawLine(tag+"AB",bautoscale,SecondHigh,B,SecondLow,A,PenColor,DashStyle,PenWidth); DrawLine(tag+"XA",bautoscale,SecondLow,A,ThirdHigh,X[0],PenColor,DashStyle,PenWidth); } else { //bullish ipatternType.Set(GartleyButterflyPatternType.Bullish); patternType.Set((double)GartleyButterflyPatternType.Bullish); idealProfitTarget.Set(B+0.618*AB); tag+="0.786 Bullish Retracement"; DrawLine(tag+"AB",bautoscale,SecondLow,B,SecondHigh,A,PenColor,DashStyle,PenWidth); DrawLine(tag+"XA",bautoscale,SecondHigh,A,ThirdLow,X[0],PenColor,DashStyle,PenWidth); } } #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 X { get { return x; } } [browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] public DataSeries IdealProfitTarget { get { return idealProfitTarget; } } [browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] public IntSeries Value { get { return ipatternType; } } [browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] public DataSeries PatternType { get { return patternType; } } [Description("Pen Color Pattern")] [GridCategory("Plot")] [XmlIgnore()] public Color PenColor { get { return penColor; } set { penColor = value; } } // Serialize our Color object [browsable(false)] public string PenColorSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(penColor); } set { penColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } [Description("Dash Style")] [GridCategory("Plot")] public DashStyle DashStyle { get { return dashStyle; } set { dashStyle = value; } } [Description("Pen Width")] [GridCategory("Plot")] public int PenWidth { get { return penWidth; } set { penWidth = Math.Max(0,value); } } [Description("Bars back")] [GridCategory("Parameters")] public int BarsBack { get { return barsBack; } set { barsBack = Math.Max(5,value); } } [Description("")] [GridCategory("Parameters")] public double ZigZagPercentDeviation { get { return zigZagPercentDeviation; } set { zigZagPercentDeviation = Math.Max(0.001, value); } } [Description("")] [GridCategory("Parameters")] public double TolerancePercent { get { return tolerancePercent; } set { tolerancePercent = Math.Max(0.0, value); } } #endregion } } Quote Link to comment Share on other sites More sharing options...
tryitagainmf Posted October 18, 2012 Report Share Posted October 18, 2012 rg83...the NT Support Forum is a good place to find help for ninjascript issues. Both the members and support staff are helpful. You do have to register in the Forum but you do not have to be an NT subscriber to participate. http://www.ninjatrader.com/support/forum/index.php Cheers! Mick rg83 1 Quote Link to comment Share on other sites More sharing options...
tryitagainmf Posted October 18, 2012 Report Share Posted October 18, 2012 (edited) You're welcome, mate. I see on the NT Forum that one of the CS techs has weighed-in. Hopefully a user code guru will give you some help...either there or here. Cheers! Mick By the way...what does the error code show when you try to compile...that screenshot of the error listing may motivate a code guru to jump in and assist (here and over there). Edited October 18, 2012 by tryitagainmf Quote Link to comment Share on other sites More sharing options...
rg83 Posted October 21, 2012 Author Report Share Posted October 21, 2012 Thanks Mick, I was trying to adjust the code from a gartley indicator but my force is **** when it comes to coding...no error when compiling it just wont plot the patterns when they show. I see you are in the isle of man, in jersey myself. Do you know of any trading rooms, arcades in the islands? Quote Link to comment Share on other sites More sharing options...
newbie0101 Posted October 23, 2012 Report Share Posted October 23, 2012 Hi rg83, any luck with getting your indi working. Would like to check it out if/when you get it working. Thanks in advance Quote Link to comment Share on other sites More sharing options...
thaomoua Posted October 23, 2012 Report Share Posted October 23, 2012 rg83, I'm looking at your code and compilation complains that 'GartleyButterflyPatternType' does not exist. Did you leave out this enum? Quote Link to comment Share on other sites More sharing options...
tryitagainmf Posted October 23, 2012 Report Share Posted October 23, 2012 rg83, I'm looking at your code and compilation complains that 'GartleyButterflyPatternType' does not exist. Did you leave out this enum? thaouma...where would that expression of code be inserted? (since I am not a coder and do not understand what these various declarations mean) Thanks, mate! Cheers! Mick Quote Link to comment Share on other sites More sharing options...
thaomoua Posted October 23, 2012 Report Share Posted October 23, 2012 tryitagainmf, you can insert the code below line # 37 or anywhere as long as it is not inside another block of code. From the looks of the code, the missing 'GartleyButterflyPatternType' code is probably not an enum but a class that returns two properties. When I created 'GartleyButterflyPatternType' as an enum, line 129, 130, 140, 141 failed because it is expecting an INT and not an enum. So what I'm thinking is 'GartleyButterflyPatternType' is probably provided by anothing indicator. Quote Link to comment Share on other sites More sharing options...
tryitagainmf Posted October 23, 2012 Report Share Posted October 23, 2012 If I am understanding you correctly, thaomoua, we do not yet know what that line of code should look like since we would need the "other" indicator to tell this to call on?! Thanks! Cheers! Mick Quote Link to comment Share on other sites More sharing options...
thaomoua Posted October 23, 2012 Report Share Posted October 23, 2012 This is the code you need. class GartleyButterflyPatternType { public const int Bullish=1; public const int Bearish=-1; }; Place it before 'namespace NinjaTrader.Indicator' tryitagainmf 1 Quote Link to comment Share on other sites More sharing options...
thaomoua Posted October 23, 2012 Report Share Posted October 23, 2012 The more I look at this code and its logic, it looks like something the indicator neoharmonic/midasTouch already do. I could be wrong though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.