You are on page 1of 4

#region Using declarations

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

//This namespace holds Strategies in this folder and is required. Do not change it.

namespace NinjaTrader.NinjaScript.Strategies
{
public class HighestVolumeHODonSameCandle : Strategy
{
public double HighestVolume; // Value of Highest Volume Till last Bar
formed.
public double LastBarVolume; // Last Bar Volume

public double HighOfDay; // High Of Day Till last Bar


formed.
public double LastBarHigh; // Last Bar High

public bool HighestVolChanged; // Condition to check that last bar has


the highest volume
public bool HighOfDayChanged; // Condition to check that last bar high
has borken last high of day
public bool BothConditionsMet; // To check that both condition met on
same 1 Minute Candle

public string InstrumentFullName; // To Find Name of Instrument

protected override void OnStateChange()


{
if (State == State.SetDefaults)
{
Description
= @"Find High Of Day & Highest Volume on Same 1 Minute Candle.";
Name
= "HighestVolumeHODonSameCandle";
Calculate
= Calculate.OnBarClose;
EntriesPerDirection
= 1;
EntryHandling
= EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch
= false;
MaximumBarsLookBack
= MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution
= OrderFillResolution.Standard;
Slippage
= 0;
StartBehavior
= StartBehavior.WaitUntilFlat;
TimeInForce
= TimeInForce.Gtc;
TraceOrders
= false;
RealtimeErrorHandling =
RealtimeErrorHandling.StopCancelClose;
StopTargetHandling
= StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade
= 20;
// Disable this property for performance gains in Strategy
Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;

HighestVolume=0; // Initial Condition is 0.


LastBarVolume=0; // Initial Condition is 0.

HighOfDay=0; // Initial Condition is 0.


LastBarHigh=0; // Initial Condition is 0.

HighestVolChanged=false; // Initial Condition is 0.


HighOfDayChanged=false; // Initial Condition is 0.
BothConditionsMet=false; // Initial Condition is 0.
InstrumentFullName =null;
}
else if (State == State.Configure)
{
AddDataSeries("TCS", Data.BarsPeriodType.Minute, 1);
}
}

protected override void OnBarUpdate()


{
if (BarsInProgress != 0)
return;

//InstrumentFullName = Instrument.FullName;
LastBarVolume = Volumes[0][0];
LastBarHigh = High[0];
// Logic for Highest Volume Bar Calculation

if (LastBarVolume > HighestVolume)


{
HighestVolume = LastBarVolume;
HighestVolChanged = true;
Print("The Volume of the current bar is : " +
LastBarVolume);
}
else
{
HighestVolume = HighestVolume;
HighestVolChanged = false;

Print("The Volume of the current bar is : " +


LastBarVolume);

// Logic for High of Day Calculation

if (LastBarHigh > HighOfDay)


{
HighOfDay = LastBarHigh;
HighOfDayChanged = true;

Print("The high of the current bar is : " + High[0]);


}
else
{
HighOfDay = HighOfDay;
HighOfDayChanged = false;

Print("The high of the current bar is : " + High[0]);


}

// Alert Pop Up when both the Conditions Met.

if ( HighestVolChanged == true && HighOfDayChanged == true)

// Alert("HOD_HOV_On_Same_Bar", Priority.High, "High of Day &


Highest Volume Done on Same Bar",
NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert1.wav", 10, Brushes.Black,
Brushes.Yellow);

NinjaTrader.NinjaScript.Alert.AlertCallback(NinjaTrader.Cbi.Instrument.GetInstrumen
t("TCS"), this, "2011", NinjaTrader.Core.Globals.Now, Priority.High, "ZEEL HOD &
HOV ON SAME BAR", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert1.wav", new
SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.White), 0);
}

else

{
HighestVolChanged = false;
HighOfDayChanged =false;

}
}

You might also like