By using the information contained in the pages below, you understand and agree with the following terms:

  1. I AGREE that SharkIndicators does not warrant the functionality contained in the provided software code will meet your requirements or the operation of the software in conjunction with BloodHound will be uninterrupted or error-free.
  2. I AGREE that using any of the information, including software code samples, are at my own risk. I shall defend, indemnify and hold SharkIndicators, its employees and associates harmless from any and all claims, damages, or losses resulting from its use.
  3. I AGREE that SharkIndicators is not under any obligation to provide support for the operation of any code derived from these examples and that I assume all associated risks and costs.
  4. I AGREE that in no event will SharkIndicators or its distributors be liable to you or others for any damages, including any lost profit, savings, lost patience or other incidental, or consequential damage.

-- I AGREE --

BloodHound Simple Strategy Example 1


Please note, SharkIndicators does not provide any NinjaScript, programming, or coding support.
This information is provided as-is and for knowledgeable programmers.

Overview


Note:
You must have ‘Developer Extensions’ checked when you ran the SharkIndicators Installer.   That will also install the example code file.

This example file is included in the 'Developer Extensions' and can be found in the 'MyDocuments\NinjaTrader 8\bin\Custom\Strategies' folder as 'SiBloodHoundStrategExample.cs'.  For NT 7, see the Downloads section below.  You can safely delete this file when you are done with it.

This example illustrates the bare minimum BloodHound strategy implementation.  It mimics the functionality already accomplished by the base class SiBloodHoundStrategy but overrides the OnBarUpdate method which can be extended with your code.

Entry signals are taken when BloodHound has a signal in that direction.  This is governed  by the active logic template.

Example Code


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#region Using declarations
using System.ComponentModel.DataAnnotations;
using NinjaTrader.Cbi;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
    public class SiBloodHoundStrategyExample : SiBloodHoundStrategy
    {
        #region Fields
        private double _StopLoss;
        private double _ProfitTarget;
        private CalculationMode _MeasurementUnit;
        #endregion

        #region Properties
        [Display(Name = "Measurement Unit", GroupName = "Trade Management", Order = 0, 
            Description= "The unit of measurement for the Profit Target and Stop Loss")]
        public CalculationMode MeasurementUnit
        {
            get { return _MeasurementUnit; }
            set { _MeasurementUnit = value; }
        }
        [Display(Name = "Profit Target", GroupName = "Trade Management", Order =2, 
            Description = "The profit target measured in the units specified by Measurement Unit")]
        public double ProfitTarget
        {
            get { return _ProfitTarget; }
            set { _ProfitTarget = value; }
        }

        [Display(Name = "Stop Loss", GroupName = "Trade Management", Order = 3, 
            Description = "The stop loss measured in the units specified by Measurement Unit")]
        public double StopLoss
        {
            get { return _StopLoss; }
            set { _StopLoss = value; }
        }
        #endregion

        #region Methods
        protected override void OnStateChange()
        {
            base.OnStateChange(); // this is necessary to initialize the 
                                  // BloodHound Template

            if (State == State.Configure)
            {
                // Trade Management
                SetProfitTarget(MeasurementUnit, ProfitTarget);
                SetStopLoss(MeasurementUnit, StopLoss);
            }
            if (State == State.DataLoaded)
            {
		// Add BloodHound plots to chart
		if (BloodHoundTemplate != null && !BloodHoundTemplate.IsEmpty)
		{
		    AddChartIndicator(BloodHound);
		}
            }
        }

        protected override void OnBarUpdate()
        {
            // Do not call this because the base class' default 
            // implementation is to handle entry signals exactly 
            // like below - but we are overriding it to illustrate
            // how the code works.
            // base.OnBarUpdate();

            /* 
             * EXAMPLE - this mimics the entries performed by the 
             * base class: SiBloodHoundStrategy you can now add 
             * additional program logic to the lines below if desired.
             * 
             */

            // Ensure that we aren't long already
            if (Position.MarketPosition != MarketPosition.Long)
            {
                // see if BloodHound has produced a long signal 
                // (on the selected logic template)
                if (BloodHound.LongSignals[0])
                {
                    EnterLong();
                }
            }
            // check to see if we aren't short already
            if (Position.MarketPosition != MarketPosition.Short)
            {
                // see if BloodHound has produced a short signal 
                // (on the selected logic template)
                if (BloodHound.ShortSignals[0])
                {
                    EnterShort();
                }
            }
        }
        #endregion
    }
}


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
#region Using declarations
using System.ComponentModel.DataAnnotations;
using NinjaTrader.Cbi;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
    public class SiBloodHoundStrategyExample : SiBloodHoundStrategy
    {
        #region Fields
        private double _StopLoss;
        private double _ProfitTarget;
        private CalculationMode _MeasurementUnit;
        #endregion

        #region Properties
        [Display(Name = "Measurement Unit", GroupName = "Trade Management", Order = 0, 
            Description= "The unit of measurement for the Profit Target and Stop Loss")]
        public CalculationMode MeasurementUnit
        {
            get { return _MeasurementUnit; }
            set { _MeasurementUnit = value; }
        }
        [Display(Name = "Profit Target", GroupName = "Trade Management", Order =2, 
            Description = "The profit target measured in the units specified by Measurement Unit")]
        public double ProfitTarget
        {
            get { return _ProfitTarget; }
            set { _ProfitTarget = value; }
        }


        [Display(Name = "Stop Loss", GroupName = "Trade Management", Order = 3, 
            Description = "The stop loss measured in the units specified by Measurement Unit")]
        public double StopLoss
        {
            get { return _StopLoss; }
            set { _StopLoss = value; }
        }
        #endregion

        #region Methods
        protected override void OnStateChange()
        {
            base.OnStateChange(); // this is necessary to initialize the 
                                  // BloodHound Template

            if (State == State.Configure)
            {
                // Trade Management
                SetProfitTarget(MeasurementUnit, ProfitTarget);
                SetStopLoss(MeasurementUnit, StopLoss);
                if (BloodHoundTemplate != null && !BloodHoundTemplate.IsEmpty)
                {
                    AddChartIndicator(BloodHound);
                }
            }
        }

        protected override void OnBarUpdate()
        {
            // Do not call this because the base class' default 
            // implementation is to handle entry signals exactly 
            // like below - but we are overriding it to illustrate
            // how the code works.
            // base.OnBarUpdate();

            /* 
             * EXAMPLE - this mimics the entries performed by the 
             * base class: SiBloodHoundStrategy you can now add 
             * additional program logic to the lines below if desired.
             * 
             */

            // Ensure that we aren't long already
            if (Position.MarketPosition != MarketPosition.Long)
            {
                // see if BloodHound has produced a long signal 
                // (on the selected logic template)
                if (BloodHound.LongSignals[0])
                {
                    EnterLong();
                }
            }
            // check to see if we aren't short already
            if (Position.MarketPosition != MarketPosition.Short)
            {
                // see if BloodHound has produced a short signal 
                // (on the selected logic template)
                if (BloodHound.ShortSignals[0])
                {
                    EnterShort();
                }
            }
        }
        #endregion
    }
}

Discussion


To begin with a BloodHound strategy, derive your Strategy class with SiBloodHoundStrategy instead of the usual Strategy class as illustrated in line 8 above.

Also note that if you override the OnStateChange() method, you must call thebase.OnStateChange(); method as shown on line 45.

Finally you can see that the entry code uses the BloodHound indicator on line 80 and 90. BloodHound is an accessible property from the SiBloodHoundStrategy class, and LongSignals and ShortSignals are Series<bool> representing signals computed from BloodHound.


Downloads


NinjaTrader 8

The SharkIndicaotor's Installer will install this file to the ...\NinjaTrader 8\bin\Custom\Strategies\  folder when the Developer Extensions are selected.

NinjaTrader 7

The last version to support Developer Extension is Ver 1.233.6603.  It may be downloaded from the Changelog page.  If you have a newer version installed, it must be uninstalled first and then restart the computer.

Download the import file below and import it into NinjaTrader 7 from the Control Center.  Select the File menu » Utilities » Import NinjaScript.
Download import file for NT 7 (.zip)