NexusFi: Find Your Edge


Home Menu

 





TD SEQUENTIAL


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Markus with 4 posts (0 thanks)
    2. looks_two Big Mike with 2 posts (0 thanks)
    3. looks_3 Silvester17 with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 24,142 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 5 attachments




 
Search this Thread
  #1 (permalink)
Markus
Frankfurt am Main
 
Posts: 38 since May 2010
Thanks Given: 6
Thanks Received: 33

Would you please to tell me the reason why when I compile this study I have errors?
Thanks!



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

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    
/// <summary>
    /// TdSequential
    ///
    
[Description("Td Countdown")]
    public class 
TdSequential : Indicator
    
{
#region Variables
        
int countdownBuyCount = 0;
        
int countdownSellCount = 0;
        
bool countdownBuy = false;
        
bool countdownSell = false;
        
bool logic = false;
//        double fiveBuy = 0;
        
double eightBuy = 0;
        
double eightSell = double.PositiveInfinity;
        
double support = 0;
        
double resistance = double.PositiveInfinity;
        
int[] currentBuy = new int[13];
        
int[] currentSell = new int[13];
      
        
int        setupCount        = 0;
        
bool    initSetupBull    = false;
        
bool    initSetupBear    = false;
        
int        setupBuyCount    = 0;
        
int        setupSellCount    = 0;
        
double    buyPerfection    = 0;
        
double    sellPerfection    = double.PositiveInfinity;
#endregion

        ///
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        ///
        
protected override void Initialize()
        {
            
CalculateOnBarClose    = true;
            
Overlay                = true;
            
PriceTypeSupported    = false;
        }
      
                
#region Resets
        
void ResetBull()
        {
            
initSetupBull = false;
            
setupBuyCount = 0;
        }
      
        
void ResetBear()
        {
            
initSetupBear = false;
            
setupSellCount = 0;
        }
        
#endregion
      
        #region TD Price Bull
        
bool PriceBull(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 4;
            if (
Close[i] < Close[j])
            {
                return 
true;
            }
            return 
false;
        }
        
#endregion
      
        #region TD Price Bear
        
bool PriceBear(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 4;
            if (
Close[i] > Close[j])
            {
                return 
true;
            }
            return 
false;
        }
        
#endregion
      
        #region TD Price Flip Bull
        
bool PriceFlipBull(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 1;
            if (
PriceBull(i) && PriceBear(j))
            {
                return 
true;
            }
            return 
false;
        }
        
#endregion
      
        #region TD Price Flip Bear
        
bool PriceFlipBear(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 1;
            if (
PriceBear(i) && PriceBull(j))
            {
                return 
true;
            }
            return 
false;
        }
        
#endregion
      
        #region TD Setup Buy
        
public bool SetupBuy()
        {
            
// Begins TD Buy Setup
            
if (PriceFlipBull(0))
            {
                
initSetupBull = true;
                
setupBuyCount++;
                
double position = (Low[0] + Low[0] + Low[1] + Low[2] + Low[3])/5 - (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/2;
                
DrawText((CurrentBar.ToString() + "BullSetup"), setupBuyCount.ToString(), 0, position, Color.Green);  
            }
            
// Continues TD Buy Setup
            
else if (initSetupBull && PriceBull(0))
            {
                
setupBuyCount++;
                
double position = (Low[0] + Low[0] + Low[1] + Low[2] + Low[3])/5 - (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/2;
                
DrawText((CurrentBar.ToString() + "BullSetup"), setupBuyCount.ToString(), 0, position, Color.Green);
            }
            
// Cancels TD Buy Setup
            
else if (PriceFlipBear(0))
            {
                for (
int i = 0; i <= (setupBuyCount % 9); i++)
                {
                    
string myTag = (CurrentBar - i).ToString() + "BullSetup";
                    
RemoveDrawObject(myTag);
                }
                
ResetBull();
            }
          
            
// TD Resistance Lines
            
if (initSetupBull && (setupBuyCount % 9) == 0)
            {
                
DrawLine((CurrentBar.ToString() + "Resistance 1"), false, 8, MAX(High, 9)[0], 0, MAX(High, 9)[0], Color.Red, DashStyle.Dash, 1);
                
DrawLine((CurrentBar.ToString() + "Resistance 2"), false, 12, MAX(High, 13)[0], 0, MAX(High, 13)[0], Color.Red, DashStyle.Solid, 2);
                
// TD Buy Setup Perfection
                
if ((Low[0] < Low[2] || Low[0] < Low[3] || Low[1] < Low[2] || Low[1] < Low[3]) && Low[0] < Low[1])
                {
                    
DrawArrowUp((CurrentBar.ToString() + "Arrow"), 0, Low[0] - (ATR(1)[0]), Color.Green);
                }
                else
                {
                    
buyPerfection = MIN(Low, 4)[0];  
                }
                return 
true;
            }
          
            
// TD Buy Setup Perfection After Completion of Setup
            
if (Low[0] < buyPerfection)
            {
                
DrawArrowUp((CurrentBar.ToString() + "Arrow"), 0, Low[0] - (ATR(1)[0]), Color.Green);
                
buyPerfection = 0;          
            }
          
            return 
false;
        }
        
#endregion
      
        #region TD Setup Sell
        
public bool SetupSell()
        {
            
// Begins TD Sell Setup
            
if (PriceFlipBear(0))
            {
                
initSetupBear = true;
                
setupSellCount++;
                
double position = (High[0] + High[0] + High[1] + High[2] + High[3])/5 + (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/2;
                
DrawText((CurrentBar.ToString() + "BearSetup"), setupSellCount.ToString(), 0, High[0] + ATR(4)[0], Color.Red);  
            }
            
// Continues TD Sell Setup
            
else if (initSetupBear && PriceBear(0))
            {
                
setupSellCount++;
                
double position = (High[0] + High[0] + High[1] + High[2] + High[3])/5 + (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/2;
                
DrawText((CurrentBar.ToString() + "BearSetup"), setupSellCount.ToString(), 0, position, Color.Red);
            }
            
// Cancels TD Sell Setup
            
else if (PriceFlipBull(0))
            {
                for (
int i = 0; i <= (setupSellCount % 9); i++)
                {
                    
string myTag = (CurrentBar - i).ToString() + "BearSetup";
                    
RemoveDrawObject(myTag);
                }
                
ResetBear();
            }
          
            
// TD Support Lines
            
if (initSetupBear && (setupSellCount % 9) == 0)
            {
                
DrawLine((CurrentBar.ToString() + "Support 1"), false, 8, MIN(Low, 9)[0], 1, MIN(Low, 9)[0], Color.Green, DashStyle.Dash, 1);
                
DrawLine((CurrentBar.ToString() + "Support 2"), false, 12, MIN(Low, 13)[0], 1, MIN(Low, 13)[0], Color.Green, DashStyle.Solid, 2);
              
                
// TD Sell Setup Perfection
                
if ((High[0] > High[2] || High[0] > High[3] || High[1] > High[2] || High[1] > High[3]) && High[0] > High[1])
                {
                    
DrawArrowDown((CurrentBar.ToString() + "Arrow"), 0, High[0] + (ATR(1)[0]), Color.Red);  
                }
                else
                {
                    
sellPerfection = MAX(High, 4)[0];
                }
                return 
true;
            }
            
// TD Sell Setup Perfection After Comletion of Setup
            
if (High[0] > sellPerfection)
            {
                
DrawArrowDown((CurrentBar.ToString() + "Arrow"), 0, High[0] + (ATR(1)[0]), Color.Red);
                
sellPerfection = Double.PositiveInfinity;
            }
          
            return 
false;
        }
        
#endregion
      
        #region Buy
        
public void Buy(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 2;
            if (
Close[i] < Close[j])
            {
                
countdownBuyCount++;
                switch (
countdownBuyCount)
                {
//                    case 5:
//                        fiveBuy = Close[0];
//                        goto default;
                    
case 8:
//                        if (Close[0] < fiveBuy)
//                        {
                            
eightBuy = Close[0];
                            goto default;
//                        }
//                        else
//                        {
//                            countdownBuyCount--;  
//                        }
//                        break;
                      
                    
case 13:
                        if (
Close[0] <= eightBuy)
                        {
                            
DrawText((CurrentBar.ToString() + "Bull"), countdownBuyCount.ToString(), 0, Low[0] - (Range()[0] * 0.6), Color.LightSeaGreen);                          
                            
DrawArrowUp((CurrentBar.ToString() + "Arrow"), 0, Low[0] - (Range()[0] * 0.6), Color.LightSeaGreen);
                            
countdownBuyCount = 0;
                            
countdownBuy = false;
                        }
                        else
                        {
                            
DrawText((CurrentBar.ToString() + "Bull"), "+", 0, Low[0] - (Range()[0] * 0.6), Color.LightSeaGreen);
                            
countdownBuyCount--;
                        }
                        break;
                      
                    default:
                        
double position = (Low[0] + Low[0] + Low[1] + Low[2] + Low[3])/5 - (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/1.5;                      
                        
DrawText((CurrentBar.ToString() + "Bull"), countdownBuyCount.ToString(), 0, position, Color.LightSeaGreen);
                        
currentBuy[countdownBuyCount] = CurrentBar;
                        break;
                }
            }
          
            
// Recycle Count
            
if (Low[0] > resistance || TdSetup().Sell())
            {
                
double position = (Low[0] + Low[0] + Low[1] + Low[2] + Low[3])/5 - (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/2;
                
DrawText((CurrentBar.ToString() + "Bull"), "R", 0, position, Color.LightSeaGreen);
                
countdownBuy = false;
                for (
int k = 0; k <= countdownBuyCount; k++)
                {
                    
RemoveDrawObject(currentBuy[k] + "Bull");  
                }
                
countdownBuyCount = 0;
              
            }
        }
        
#endregion
      
        #region Sell
        
public void Sell(int barsAgo)
        {
            
int i = barsAgo;
            
int j = i + 2;
            if (
Close[i] > Close[j])
            {
                
countdownSellCount++;
                switch (
countdownSellCount)
                {

                    case 
8:
                            
eightSell = Close[0];
                            goto default;
                      
                    case 
13:
                        if (
Close[0] >= eightSell)
                        {
                            
DrawText((CurrentBar.ToString() + "Bear"), countdownSellCount.ToString(), 0, High[0] + (Range()[0] * 0.6), Color.Salmon);                          
                            
DrawArrowDown((CurrentBar.ToString() + "Arrow"), 0, High[0] + (Range()[0] * 0.6), Color.Salmon);
                            
countdownSellCount = 0;
                            
countdownSell = false;
                        }
                        else
                        {
                            
DrawText((CurrentBar.ToString() + "Bear"), "+", 0, High[0] + (Range()[0] * 0.6), Color.Salmon);
                            
countdownSellCount--;
                        }
                        break;
                      
                    default:
                        
double position = (High[0] + High[0] + High[1] + High[2] + High[3])/5 + (ATR(4)[0] + ATR(4)[1] + ATR(4)[2] + ATR(4)[3])/1.5;
                        
DrawText((CurrentBar.ToString() + "Bear"), countdownSellCount.ToString(), 0, position, Color.Salmon);
                        
currentSell[countdownSellCount] = CurrentBar;
                        break;
                }
            }
          
            
// Recycle Count
            
if (High[0] < support || TdSetup().Buy())
            {
                
DrawText((CurrentBar.ToString() + "Bear"), "R", 0, High[0] + (Range()[0] * 0.6), Color.Salmon);
                
countdownSell = false;
                for (
int k = 0; k <= countdownSellCount; k++)
                {
                    
RemoveDrawObject(currentSell[k] + "Bear");  
                }
                
countdownSellCount = 0;
              
            }
        }
        
#endregion

        ///
        /// Called on each bar update event (incoming tick)
        ///
        
protected override void OnBarUpdate()
        {
            if (
CurrentBar > 30)
            {
                if (
SetupBuy())
                {
                    
countdownBuy = true;
                    
resistance = MAX(High, 13)[0];
                }
                if (
countdownBuy)
                {
                    
Buy(0);
                }
                if (
SetupSell())
                {
                    
countdownSell = true;
                    
support = MIN(Low, 13)[0];
                }
                if (
countdownSell)
                {
                    
Sell(0);
                }
            }
        }

        
#region Properties

        #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 
TdSequential[] cacheTdSequential = null;

        private static 
TdSequential checkTdSequential = new TdSequential();

        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
public TdSequential TdSequential()
        {
            return 
TdSequential(Input);
        }

        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
public TdSequential TdSequential(Data.IDataSeries input)
        {

            if (
cacheTdSequential != null)
                for (
int idx = 0; idx < cacheTdSequential.Length; idx++)
                    if (
cacheTdSequential[idx].EqualsInput(input))
                        return 
cacheTdSequential[idx];

            
TdSequential indicator = new TdSequential();
            
indicator.BarsRequired = BarsRequired;
            
indicator.CalculateOnBarClose = CalculateOnBarClose;
            
indicator.Input = input;
            
indicator.SetUp();

            
TdSequential[] tmp = new TdSequential[cacheTdSequential == null ? 1 : cacheTdSequential.Length + 1];
            if (
cacheTdSequential != null)
                
cacheTdSequential.CopyTo(tmp, 0);
            
tmp[tmp.Length - 1] = indicator;
            
cacheTdSequential = tmp;
            
Indicators.Add(indicator);

            return 
indicator;
        }

    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public 
partial class Column : ColumnBase
    
{
        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
[Gui.Design.WizardCondition("Indicator")]
        public 
Indicator.TdSequential TdSequential()
        {
            return 
_indicator.TdSequential(Input);
        }

        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
public Indicator.TdSequential TdSequential(Data.IDataSeries input)
        {
            return 
_indicator.TdSequential(input);
        }

    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public 
partial class Strategy : StrategyBase
    
{
        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
[Gui.Design.WizardCondition("Indicator")]
        public 
Indicator.TdSequential TdSequential()
        {
            return 
_indicator.TdSequential(Input);
        }

        
/// <summary>
        /// Td Countdown
        /// </summary>
        /// <returns></returns>
        
public Indicator.TdSequential TdSequential(Data.IDataSeries input)
        {
            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.TdSequential(input);
        }

    }
}
#endregion 


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
My Rant with AMP Futures
Trading Reviews and Vendors
[WTS] ATAS Lifetime ULTRA license – EU buyers only – …
Platforms and Indicators
EA
Platforms and Indicators
No book, only a stair: journaling fills where price move …
Cryptocurrency
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Would you consider buying or leasing an algo?
6 thanks
Trading Journal (Neural Network Production Pipeline Mode …
4 thanks
Trading psychology articles
4 thanks
Big Mike in Ecuador
3 thanks
The Scalpers Journey
2 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,597



Markus View Post
Would you please to tell me the reason why when I compile this study I have errors?
Thanks!

Only if you tell us the errors

Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
Markus
Frankfurt am Main
 
Posts: 38 since May 2010
Thanks Given: 6
Thanks Received: 33


Big Mike View Post
Only if you tell us the errors

Mike

Would you please to help me by copying and paste this study into NT6.5...? .....and see the errors that appear after the compile function? Thanks


Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,597


Markus View Post
Would you please to help me by copying and paste this study into NT6.5...? .....and see the errors that appear after the compile function? Thanks

Sorry, but I don't use NinjaTrader anymore. Others may be interested in doing it, but if you get no response its because you didn't provide the errors so people can't help.

Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 845

it's not letting me cut and paste, can you put in a word file?


Reply With Quote
  #7 (permalink)
 
Silvester17's Avatar
 Silvester17 
Columbus, OH
Market Wizard
 
Experience: None
Platform: NT 8, TOS
Trading: ES
Posts: 3,603 since Aug 2009
Thanks Given: 5,139
Thanks Received: 11,531


Markus View Post
Would you please to help me by copying and paste this study into NT6.5...? .....and see the errors that appear after the compile function? Thanks

here you can see the errors.


Attached Thumbnails
Click image for larger version

Name:	2010-09-25_2351.png
Views:	287
Size:	131.9 KB
ID:	20773  
Attached Files
Elite Membership required to download: TdSequential.cs
Reply With Quote
Thanked by:
  #8 (permalink)
Markus
Frankfurt am Main
 
Posts: 38 since May 2010
Thanks Given: 6
Thanks Received: 33

It looks like a programmers nightmare
I am not familiar with Ninja script, I simply asked if anybody here is able to correct this script


Reply With Quote
  #9 (permalink)
Markus
Frankfurt am Main
 
Posts: 38 since May 2010
Thanks Given: 6
Thanks Received: 33


vegasfoster View Post
it's not letting me cut and paste, can you put in a word file?

Here's the word file


Attached Files
Elite Membership required to download: TD SEQUENTIAL.docx
Reply With Quote
  #10 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184



Markus View Post
Would you please to help me by copying and paste this study into NT6.5...? .....and see the errors that appear after the compile function? Thanks

Maybe just me, but I havent ever seen a strategy or indicator compile without something being declared in the 'Properties'

TJ


Reply With Quote




Last Updated on September 30, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts