Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 01-17-2009, 09:20 PM   #1

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

TTM Scalp Average for Ninja

Looking for some help on an average based off of the TTM scalp easy language code. Most of it has been successfully translated but I'm need some tweak help. Attached is the zipped file and screen shot. I would like to reduce the times the paint bar fires. It seems redundant to me. So, adding a "no plot if a swing hi/ swing low fired 2 bars ago" kind of scenario. I also would like to be able to turn the paint bar off as well. I have little knowledge of coding for ninja and need some guidance. If anyone wants to offer it up here in this thread so others can learn great, but if someone would rather get paid for the tweak I am up for that as well. Thx
Attached Thumbnails
TTM Scalp Average for Ninja-screen-capture-1.png  
Attached Files
File Type: zip SeansAveragev3.zip (7.6 KB, 79 views)
thehaul is offline  
Reply With Quote
Old 01-17-2009, 09:46 PM   #2

Join Date: Feb 2008
Location: zip
Posts: 54
Ignore this user

Thanks: 20
Thanked 11 Times in 8 Posts

Re: TTM Scalp Average for Ninja

Not quite sure what you want here. Can you explain the indicator in plain english step by step?
justlurkin is offline  
Reply With Quote
Old 01-17-2009, 09:54 PM   #3

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

Re: TTM Scalp Average for Ninja

Its basically an average of swing hi/lo. That's it. There's a round to the nearest tick function added and I like to use it with the square parameter to get the step looking line. I feel the ES likes to revisit certain areas and depending on market thrust it tends to retrace back to this average. I like the way the code acts but would like to limit the number of times it fires. Does this help??
thehaul is offline  
Reply With Quote
Old 01-17-2009, 11:11 PM   #4

Join Date: Feb 2008
Location: zip
Posts: 54
Ignore this user

Thanks: 20
Thanked 11 Times in 8 Posts

Re: TTM Scalp Average for Ninja

A couple of things. The code does not use ttm scalper code to define swing highs and lows. It uses Ninja's built in Swing indicator which is not the same thing. The square line is also not just a simple average of the swings as there are points in between which I can't figure out. Some more details would be nice. The code seems to be averaging using a user length on a series called midpoints. Midpoints of swing high and lows is straightforward, but what is used in between? if I had more patience I would decipher the code but I'd rather know a description of that line from you and see what I can do from there.
justlurkin is offline  
Reply With Quote
Old 01-18-2009, 01:02 AM   #5

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

Re: TTM Scalp Average for Ninja

Let's see if this video shines any light. I hope it plays. It's just a section from 12th playing back at 500x.
Attached Files
File Type: avi average8.avi (16.77 MB, 94 views)
thehaul is offline  
Reply With Quote
Old 01-18-2009, 01:30 AM   #6

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

Re: TTM Scalp Average for Ninja

I think that video is before market open so it's really choppy.
thehaul is offline  
Reply With Quote
Old 01-18-2009, 01:30 AM   #7

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

Re: TTM Scalp Average for Ninja

How do i delete ?????????????

Last edited by thehaul; 01-18-2009 at 01:34 AM. Reason: trying to delete a repeat
thehaul is offline  
Reply With Quote
Old 01-18-2009, 01:38 AM   #8

thehaul's Avatar

Join Date: Dec 2008
Location: West Coast, USA
Posts: 35
Ignore this user

Thanks: 10
Thanked 1 Time in 1 Post

Re: TTM Scalp Average for Ninja

Here's the code to look at... for anybody to look at...


//
// Copyright (C) 2008, SBG Trading Corp. www.affordableindicators.com
// Use this indicator/strategy at your own risk. No warranty expressed or implied.
// Trading financial instruments is risky and can result in substantial loss.
// The owner of this indicator/strategy holds harmless SBG Trading Corp. from any
// and all trading losses incurred while using this indicator/strategy.
//
//


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

namespace NinjaTrader.Indicator
{
/// <summary>
///
/// </summary>
[Description("Translated from tradestation")]
[Gui.Design.DisplayName("S eans Average")]
public class SeansAverage_v3 : Indicator
{
#region Variables
private const int _UP = 1;
private const int _DOWN = -1;
// Wizard generated variables
private int pLen=4;
private bool pRoundToTick = false;
private Color pSwingBarColor = Color.White;

private DataSeries Midpoints;
private int highBarsAgo=1;
private int possibleHighBarsAgo = 1;
private double possibleHigh = double.MinValue;
private double hightoBeat = double.MinValue+1;
private int barsSincePaint = 1;
private int lowBarsAgo = 1;
private int possibleLowBarsAgo = 1;
private double possibleLow = double.MaxValue;
private double lowtoBeat = double.MaxValue-1;
private double triggerPriceSell = double.MinValue+1;
private double triggerPriceBuy = double.MaxValue-1;
private double theavg=double.MinValue;
private int trend = _UP;
private double s_low = 1;
private double s_high = 1;
private bool RunInit = true;
#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()
{
Add(new Plot(new Pen(Color.Gold,1), PlotStyle.Line, "SeansAvg"));
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
Midpoints = new DataSeries (this);
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(RunInit) {
s_low=Low[0];
s_high=High[0];
RunInit=false;
}
int b=0;

if(CurrentBar<highBarsAgo || CurrentBar<lowBarsAgo) return;
//************************* ************************* *
//****** Find and plot the highest swing high *******
//************************* ************************* *
if (trend == _UP) {
b = Swing(1).SwingHighBar(0, 1, barsSincePaint+2);
if (b > -1) {
possibleHighBarsAgo = b;
possibleHigh = High[possibleHighBarsAgo];
}

if (possibleHigh >= hightoBeat) {
highBarsAgo = possibleHighBarsAgo;
hightoBeat = possibleHigh;
triggerPriceSell = Low[highBarsAgo - 1];
}

double temp=High[0];
for(int i=1;i<highBarsAgo;i++)//this calculates the highest high since
temp = Math.Max(temp,High[i]);

if (Close[0] < triggerPriceSell || temp < hightoBeat) {
if(pSwingBarColor != Color.Transparent) {
DrawLine("bar"+(CurrentBa r-highBarsAgo),highBarsAgo, High[highBarsAgo],highBarsAgo,Low[highBarsAgo],pSwingBarColor,DashStyle .Solid,ChartControl.BarWi dth+2);
// BarColor = pSwingBarColor;
// CandleOutlineColor = ChartControl.BarOutlinePe n.Color;
}
trend = _DOWN;
barsSincePaint = highBarsAgo-1;
hightoBeat = double.MinValue+1;
lowtoBeat = double.MaxValue-1;
triggerPriceBuy = double.MaxValue-1;
triggerPriceSell = double.MinValue;
possibleHigh = double.MinValue;
highBarsAgo = 1;
s_high = Low[0];
}
}

// //************************* ************************* *
// //****** Find and plot the lowest swing low *********
// //************************* ************************* *

if (trend == _DOWN) {
b = Swing(1).SwingLowBar(0, 1, barsSincePaint+2);
if (b > -1) {
possibleLowBarsAgo = b;
possibleLow = Low[possibleLowBarsAgo];
}

if (possibleLow <= lowtoBeat) {
lowBarsAgo = possibleLowBarsAgo;
lowtoBeat = possibleLow;
triggerPriceBuy = High[lowBarsAgo - 1];
}

double temp=Low[0];
for(int i=1;i<lowBarsAgo;i++) //this calculates the lowest low since lowBarsAgo
temp = Math.Min(temp,Low[i]);

if (Close[0] > triggerPriceBuy || temp > lowtoBeat) {
if(pSwingBarColor != Color.Transparent) {
DrawLine("bar"+(CurrentBa r-lowBarsAgo),lowBarsAgo,Hi gh[lowBarsAgo],lowBarsAgo,Low[lowBarsAgo],pSwingBarColor,DashStyle .Solid,ChartControl.BarWi dth+2);
// BarColor = pSwingBarColor;
// CandleOutlineColor = ChartControl.BarOutlinePe n.Color;
}
trend = _UP;
barsSincePaint = lowBarsAgo-1;
lowtoBeat = double.MaxValue-1;
hightoBeat = double.MinValue+1;
triggerPriceBuy = double.MaxValue-1;
triggerPriceSell = double.MinValue+1;
possibleLow = double.MaxValue;
lowBarsAgo = 1;
s_low = High[0];
}
}


Midpoints.Set((s_low + s_high)/2.0);
theavg = SMA(Midpoints, pLen)[0];

if(pRoundToTick) theavg = NormalizePrice(theavg);
Avg.Set(theavg);

barsSincePaint = barsSincePaint+1;
if (trend == _UP) highBarsAgo = highBarsAgo + 1;
if (trend == _DOWN) lowBarsAgo = lowBarsAgo + 1;
}
//========================= ========================= ===============
private double NormalizePrice(double ThePrice)
{
int Temp = (int) Math.Round(ThePrice / TickSize);
return ((double) Temp * TickSize);
}
//========================= ========================= ===============

#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 Avg
{
get { return Values[0]; }
}

[Description("Round to nearest tick?")]
[Category("Parameters")]
public bool RoundToTick
{
get { return pRoundToTick; }
set { pRoundToTick = value; }
}
[Description("Period")]
[Category("Parameters")]
public int Period
{
get { return pLen; }
set { pLen = Math.Max(1, value); }
}
[XmlIgnore()]
[Description("Color of swing pivot bar (set to 'Transparent' to disengage coloring)")]
[Category("Visual")]
public Color SwingBarColor{ get { return pSwingBarColor; } set { pSwingBarColor = value; } }
[Browsable(false)]
public string ClSerialize
{ get { return NinjaTrader.Gui.Design.Se rializableColor.ToString( pSwingBarColor); } set { pSwingBarColor = NinjaTrader.Gui.Design.Se rializableColor.FromStrin g(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 SeansAverage_v3[] cacheSeansAverage_v3 = null;

private static SeansAverage_v3 checkSeansAverage_v3 = new SeansAverage_v3();

/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
public SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick)
{
return SeansAverage_v3(Input, period, roundToTick);
}

/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
public SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick)
{
checkSeansAverage_v3.Peri od = period;
period = checkSeansAverage_v3.Peri od;
checkSeansAverage_v3.Roun dToTick = roundToTick;
roundToTick = checkSeansAverage_v3.Roun dToTick;

if (cacheSeansAverage_v3 != null)
for (int idx = 0; idx < cacheSeansAverage_v3.Leng th; idx++)
if (cacheSeansAverage_v3[idx].Period == period && cacheSeansAverage_v3[idx].RoundToTick == roundToTick && cacheSeansAverage_v3[idx].EqualsInput(input))
return cacheSeansAverage_v3[idx];

SeansAverage_v3 indicator = new SeansAverage_v3();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarC lose = CalculateOnBarClose;
indicator.Input = input;
indicator.Period = period;
indicator.RoundToTick = roundToTick;
indicator.SetUp();

SeansAverage_v3[] tmp = new SeansAverage_v3[cacheSeansAverage_v3 == null ? 1 : cacheSeansAverage_v3.Leng th + 1];
if (cacheSeansAverage_v3 != null)
cacheSeansAverage_v3.Copy To(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheSeansAverage_v3 = tmp;
Indicators.Add(indicator) ;

return indicator;
}

}
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyze r
{
public partial class Column : ColumnBase
{
/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
[Gui.Design.WizardConditio n("Indicator")]
public Indicator.SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick)
{
return _indicator.SeansAverage_v 3(Input, period, roundToTick);
}

/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
public Indicator.SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick)
{
return _indicator.SeansAverage_v 3(input, period, roundToTick);
}

}
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
[Gui.Design.WizardConditio n("Indicator")]
public Indicator.SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick)
{
return _indicator.SeansAverage_v 3(Input, period, roundToTick);
}

/// <summary>
/// Translated from tradestation
/// </summary>
/// <returns></returns>
public Indicator.SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick)
{
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.SeansAverage_v 3(input, period, roundToTick);
}

}
}
#endregion
thehaul is offline  
Reply With Quote

Reply

Tags
average, coding, ninja, ttm

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free MP for Ninja darthtrader Market Profile 17 01-19-2009 04:55 PM
? Ninja Trader bobby Introduce Yourself 2 11-22-2008 01:02 PM
Using .eld Indicators in Ninja Trader coldsigh Coding Forum 3 10-09-2008 12:44 AM
Ninja Trader and Interactive Brokers Freddie Brokers and Data Feeds 3 02-21-2007 10:30 PM
Question with Ninja.... Soultrader Brokers and Data Feeds 9 01-25-2007 11:18 AM

All times are GMT -4. The time now is 09:54 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.