Bearish, Bullish Retracement Ind - NinjaTrader Programming | futures trading

Go Back

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming

Bearish, Bullish Retracement Ind
Started:October 17th, 2012 (08:48 PM) by ryangillespie Views / Replies:634 / 2
Last Reply:October 17th, 2012 (10:10 PM) Attachments:0

Welcome to

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • 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, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

Bearish, Bullish Retracement Ind

Old October 17th, 2012, 08:48 PM   #1 (permalink)
Elite Member
london, England
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: CL
ryangillespie's Avatar
Posts: 34 since Nov 2011
Thanks: 9 given, 1 received

Bearish, Bullish Retracement Ind

I am trying to adjust the code of the gartley indicator to plot XAB .786 Bullish, Bearish retracement triangles showing target 61.8 retracement of A-B. I must have errors in the code still, I would appreciate it if someone can point out whats missing.

/// <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)
/// <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.


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;



else {
// bearish case
if(ThirdHigh==-1) return;





// 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) {

tag+="0.786 Bearish Retracement";


else {
tag+="0.786 Bullish Retracement";



#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
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
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
public DataSeries PatternType
get { return patternType; }


[Description("Pen Color Pattern")]
public Color PenColor
get { return penColor; }
set { penColor = value; }
// Serialize our Color object
public string PenColorSerialize
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(penColor); }
set { penColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }

[Description("Dash Style")]
public DashStyle DashStyle
get { return dashStyle; }
set { dashStyle = value; }

[Description("Pen Width")]
public int PenWidth
get { return penWidth; }
set { penWidth = Math.Max(0,value); }

[Description("Bars back")]
public int BarsBack
get { return barsBack; }
set { barsBack = Math.Max(5,value); }

public double ZigZagPercentDeviation
get { return zigZagPercentDeviation; }
set { zigZagPercentDeviation = Math.Max(0.001, value); }

public double TolerancePercent
get { return tolerancePercent; }
set { tolerancePercent = Math.Max(0.0, value); }

Reply With Quote

Old October 17th, 2012, 08:48 PM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.


Old October 17th, 2012, 10:10 PM   #3 (permalink)
Elite Member
Houston, Texas
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: futures
learning0101's Avatar
Posts: 239 since Aug 2011
Thanks: 3,350 given, 178 received

Hi @ryangillespie
you may get more response/help if you post here

Reply With Quote
The following user says Thank You to learning0101 for this post:

Reply > Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming > Bearish, Bullish Retracement Ind

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

An Afternoon with FIO trader bobwest

Elite only

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
Needed.Color coded script for ema(changes from red to green with trend)&Volume ind. Rad4633 NinjaTrader 5 October 16th, 2012 02:24 PM
help with Fib retracement please slip The Elite Circle 15 January 13th, 2012 10:46 AM
Bearish Report on ES for 7/21? ron99 Index Futures Trading 2 July 21st, 2011 08:54 AM
Post your favorite Divergence ind. here zacharydw00 NinjaTrader Programming 22 January 6th, 2011 07:52 AM
How to know when a retracement ends? ikeaboy Traders Hideout 9 August 25th, 2010 06:06 AM

All times are GMT -4. The time now is 12:27 PM.

Copyright © 2016 by 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 2016-10-22 in 0.13 seconds with 19 queries on phoenix via your IP