0% found this document useful (0 votes)
163 views9 pages

XTL - TQR Template

This document contains code for an indicator called CharlieF_XTL in NinjaTrader. The indicator analyzes CCI values to determine trend (up, down, flat) and plots colored bars and zones to identify signals. It initializes settings, updates the bar color on each tick based on CCI crossings, and draws/removes entry and stop lines and colored zones when signals occur.

Uploaded by

laqui backup3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views9 pages

XTL - TQR Template

This document contains code for an indicator called CharlieF_XTL in NinjaTrader. The indicator analyzes CCI values to determine trend (up, down, flat) and plots colored bars and zones to identify signals. It initializes settings, updates the bar color on each tick based on CCI crossings, and draws/removes entry and stop lines and colored zones when signals occur.

Uploaded by

laqui backup3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

#region Using declarations

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Reflection;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript.DrawingTools;
using NinjaTrader.NinjaScript.Indicators;
///basura del 7

/// using NinjaTrader.Gui.Design;

using System.Drawing;
/// using System.Drawing.Drawing2D;

#endregion

namespace NinjaTrader.NinjaScript.Indicators
{
[Description("Expert Trend Locator. Similar to eSignal Advanced Get XTL")]
public class CharlieF_XTL : Indicator
{
private int indxx;
private bool showalerts = false; // Default setting for ShowAlerts
private bool showarrows = false; // Default setting for ShowArrows
private int CCI_period = 35; // Default setting for CCI_Period
private int TGT_value = 37; // Default setting for TGT_value
private Brush candleColorUp = Brushes.Blue;
private Brush candleColorDown = Brushes.Red;
private Brush candleColorFlat = Brushes.Black;
private int TQRActived;
private double TQREntry;
private int TQRstarted;
private double TQRStop;
private int TQRtrend;
private int trend_0;
private int trend_1;
private int trend_2;
private int trend_3;
private int trend_upd = -1;

/// <summary>
/// This method is used to configure the indicator and is called once
before any bar data is loaded.
/// </summary>
private void Initialize()
{
IsOverlay = true;
Calculate = Calculate.OnEachTick;
/* NT8 REMOVED: PriceTypeSupported = false */;
PaintPriceMarkers = false;
}

protected override void OnStateChange()


{
switch (State)
{
case State.SetDefaults:
Name = "XTL con TQR";
Description = "X T L - con el traquer";
Initialize();
break;
}
}

public override string ToString()


{
return Name;
}

protected override void OnBarUpdate()


{
if (base.CurrentBar != this.trend_upd)
{
this.trend_3 = this.trend_2;
this.trend_2 = this.trend_1;
this.trend_1 = this.trend_0;
this.trend_upd = base.CurrentBar;
}
///if (base.SMA(base.Close, this.period1)[0] > base.SMA(base.Close,
this.period2)[0])
if ( (base.CCI(this.CCI_period)[0]) > this.TGT_value ) //XTL Up
Calculation
{
base.CandleOutlineBrush = Brushes.Blue;
this.trend_0 = 1;

if (base.Open[0] < base.Close[0])


{
base.BarBrush = Brushes.Transparent;
}
else
{
base.BarBrush = Brushes.Blue;
}

/* CandleOutlineColor = candleColorUp;
BarColor = candleColorUp;
this.trend_0 = 1; */
}
else if ( (base.CCI(this.CCI_period)[0]) < -(this.TGT_value) ) //XTL Dn
Calculation
{
base.CandleOutlineBrush = Brushes.Red;
this.trend_0 = 2;

if (base.Open[0] < base.Close[0])


{
base.BarBrush = Brushes.Transparent;
}
else
{
base.BarBrush = Brushes.Red;
}

/* CandleOutlineColor = candleColorDown;
BarColor = candleColorDown;
this.trend_0 = 2; */
}
else ///if (((base.CCI(this.CCI_Period)[0]) <= this.TGT_value) &&
((base.CCI(this.CCI_Period)[0]) >= -(this.TGT_value))) //XTL Flat calculation
{
base.CandleOutlineBrush = Brushes.Black;
///this.trend_0 = 3; Find the solution for this trend NOT show the
BOX.

if (base.Open[0] < base.Close[0])


{
base.BarBrush = Brushes.Transparent;
}
else
{
base.BarBrush = Brushes.Black;
}

/* CandleOutlineColor = candleColorFlat;
BarColor = candleColorFlat; */
}

///===ShowAlerts: When Candle changes Color===///


// if (showalerts)
// {
// if (CrossAbove(base.CCI(this.CCI_period), this.TGT_value,
1))
// {
// Alert("XLT Blue
Bar",NinjaTrader.Cbi.Priority.Low,"XLT Blue
Bar","Alert4.wav",60,Color.Navy,Color.PaleGreen);
// }
// else if (CrossBelow(base.CCI(this.CCI_period), -
this.TGT_value, 1))
// {
// Alert("XLT Red Bar",NinjaTrader.Cbi.Priority.Low,"XLT
Red Bar","Alert4.wav",60,Color.Navy,Color.LightSalmon);
// }
// }
///===ShowArrows===///
if (showarrows)
{
if (CrossAbove(base.CCI(this.CCI_period), this.TGT_value,
1))
{
//DrawArrowUp("My up arrow" + CurrentBar, false, 0,
High[0] + (High[0]-Low[0]), Color.Cyan);

Draw.ArrowUp(this, "My up arrow" + CurrentBar, false,


0, High[0] + (High[0]-Low[0]), Brushes.Cyan);

}
else if (CrossBelow(base.CCI(this.CCI_period), -
this.TGT_value, 1))
{
// DrawArrowDown("My dn arrow" + CurrentBar, false, 0,
Low[0] - (High[0]-Low[0]), Color.Magenta);
Draw.ArrowDown(this, "My dn arrow" + CurrentBar, false, 0,
Low[0] - (High[0]-Low[0]), Brushes.Magenta);
}
}

if (base.CurrentBar >= 4) ///Change 4 to 2


{
if(
((this.TQRActived == 1) && (((this.TQRtrend == 1) &&
(base.Low[0] < this.TQRStop)) || ((this.TQRtrend == 2) && (base.High[0] >
this.TQRStop))))
||
(((base.CCI(this.CCI_Period)[0]) <= this.TGT_value)
&& ((base.CCI(this.CCI_Period)[0]) >= -(this.TGT_value))) ///Added this line for
rePlotZone after black color state.
)
{
this.RemoveZone();
}

if (base.IsFirstTickOfBar)
{
if ( (this.trend_1 != this.trend_2) || ( this.TQRActived == 0
&& (((base.CCI(this.CCI_period)[1]) > this.TGT_value ) ||
((base.CCI(this.CCI_period)[1]) < -(this.TGT_value)))) )
{
this.RemoveZone();
this.SetZone();
this.PlotZone(0); ///this.PlotZone(0);
}
else if ( this.TQRActived == 1 )
{
this.PlotZone(1);
}
}
}
}

private void PlotZone(int BarEnd)


{
Draw.Line(this, "EntryLine", true, base.CurrentBar - this.TQRstarted,
this.TQREntry, BarEnd, this.TQREntry, (this.TQRtrend == 1) ? Brushes.Blue :
Brushes.Red, DashStyleHelper.Solid, (BarEnd > 0) ? 2 : 1);
Draw.Line(this, "StopLine", true, base.CurrentBar - this.TQRstarted,
this.TQRStop, BarEnd, this.TQRStop, Brushes.Red, DashStyleHelper.Dash, (BarEnd > 0)
? 2 : 1);

if (BarEnd > 0)
{
Draw.Rectangle(this, "ColourZone", false, base.CurrentBar -
this.TQRstarted, this.TQREntry, BarEnd, this.TQRStop, Brushes.Transparent,
(this.TQRtrend == 1) ? Brushes.LightBlue : Brushes.LightSalmon, 3);

}
}

private void RemoveZone()


{
this.TQRActived = 0;
this.TQRstarted = 0;
this.TQRtrend = 0;
this.TQREntry = 0.0;
this.TQRStop = 0.0;
base.RemoveDrawObject("EntryLine");
base.RemoveDrawObject("StopLine");
base.RemoveDrawObject("ColourZone");
}

private void SetZone()


{
this.TQRActived = 1;
this.TQRstarted = base.CurrentBar - 1;
this.TQRtrend = (this.trend_1 == 1) ? 1 : 2;
this.TQREntry = (this.TQRtrend == 1) ? (base.High[1] + ((base.High[1] -
base.Low[1]) / 2.0)) : (base.Low[1] - ((base.High[1] - base.Low[1]) / 2.0));
this.TQRStop = (this.TQRtrend == 1) ? (base.Low[1] - ((base.High[1] -
base.Low[1]) / 2.0)) : (base.High[1] + ((base.High[1] - base.Low[1]) / 2.0));
}

#region Properties

[XmlIgnore()] // this line ensures that the indicator can be


saved/recovered as part of a chart template, do not remove
[NinjaScriptProperty]
[Display(Name = "Candle Color Up", Description = "Candle Color Up.",
GroupName = "Parameters", Order = 1)]
public Brush CandleColorUp
{
get { return candleColorUp; }
set { candleColorUp = value; }
}

/// <summary>
/// </summary>
[Browsable(false)]
public string candleColorUpSerialize
{
get { return Serialize.BrushToString(candleColorUp); }
set { candleColorUp = Serialize.StringToBrush(value); }
}

/// <summary>
/// </summary>
[XmlIgnore()]

[NinjaScriptProperty]

[Display(Name = "Candle Color Flat", Description = "Candle Color


Flat.", GroupName = "Parameters", Order = 1)]
public Brush CandleColorFlat
{
get { return candleColorFlat; }
set { candleColorFlat = value; }
}

/// <summary>
/// </summary>
[Browsable(false)]
public string candleColorFlatSerialize
{
get { return Serialize.BrushToString(candleColorFlat); }
set { candleColorFlat = Serialize.StringToBrush(value); }
}

/// <summary>
/// </summary>
[XmlIgnore()]

[NinjaScriptProperty]
[Display(Name = "Candle Color Down", Description = "Candle Color
Down.", GroupName = "Parameters", Order = 1)]
public Brush CandleColorDown
{
get { return candleColorDown; }
set { candleColorDown = value; }
}

/// <summary>
/// </summary>
[Browsable(false)]
public string candleColorDownSerialize
{
get { return Serialize.BrushToString(candleColorDown); }
set { candleColorDown = Serialize.StringToBrush(value); }
}
[Display(Name="CCI_Period", Description = "CCI_Period", GroupName
= "Parameters")]

public int CCI_Period


{
get
{
return this.CCI_period;
}
set
{
this.CCI_period = Math.Max(1, value);
}
}

//basura del 7
//[Category("Parameters"),
NinjaTrader.Gui.Design.DisplayName("TGT_Value"), Description("TGT_Value")]

[Display(Name="TGT_Value", Description = "TGT_Value", GroupName =


"Parameters")]
public int TGT_Value
{
get
{
return this.TGT_value;
}
set
{
this.TGT_value = Math.Max(1, value);
}
}

[Description("Determines whether arrows are shown")]


[Category("Parameters")]
public bool ShowArrows
{
get { return showarrows; }
set { showarrows = value; }
}

[Description("Determines whether alerts are shown")]


[Category("Parameters")]
public bool ShowAlerts
{
get { return showalerts; }
set { showalerts = value; }
}
#endregion
}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator :
NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private CharlieF_XTL[] cacheCharlieF_XTL;
public CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush
candleColorFlat, Brush candleColorDown)
{
return CharlieF_XTL(Input, candleColorUp, candleColorFlat,
candleColorDown);
}

public CharlieF_XTL CharlieF_XTL(ISeries<double> input, Brush


candleColorUp, Brush candleColorFlat, Brush candleColorDown)
{
if (cacheCharlieF_XTL != null)
for (int idx = 0; idx < cacheCharlieF_XTL.Length; idx++)
if (cacheCharlieF_XTL[idx] != null &&
cacheCharlieF_XTL[idx].CandleColorUp == candleColorUp &&
cacheCharlieF_XTL[idx].CandleColorFlat == candleColorFlat &&
cacheCharlieF_XTL[idx].CandleColorDown == candleColorDown &&
cacheCharlieF_XTL[idx].EqualsInput(input))
return cacheCharlieF_XTL[idx];
return CacheIndicator<CharlieF_XTL>(new CharlieF_XTL()
{ CandleColorUp = candleColorUp, CandleColorFlat = candleColorFlat, CandleColorDown
= candleColorDown }, input, ref cacheCharlieF_XTL);
}
}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush
candleColorFlat, Brush candleColorDown)
{
return indicator.CharlieF_XTL(Input, candleColorUp,
candleColorFlat, candleColorDown);
}

public Indicators.CharlieF_XTL CharlieF_XTL(ISeries<double> input ,


Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
{
return indicator.CharlieF_XTL(input, candleColorUp,
candleColorFlat, candleColorDown);
}
}
}

namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy :
NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.CharlieF_XTL CharlieF_XTL(Brush candleColorUp, Brush
candleColorFlat, Brush candleColorDown)
{
return indicator.CharlieF_XTL(Input, candleColorUp,
candleColorFlat, candleColorDown);
}

public Indicators.CharlieF_XTL CharlieF_XTL(ISeries<double> input ,


Brush candleColorUp, Brush candleColorFlat, Brush candleColorDown)
{
return indicator.CharlieF_XTL(input, candleColorUp,
candleColorFlat, candleColorDown);
}
}
}

#endregion

You might also like