First I have to create a dataserie that is:
[(Askvolume(0) + Askvolume(1) + Askvolume(2) + Askvolume(3) + Askvolume(4)) - (Bidvolume(0) + Bidvolume(1) + Bidvolume(2) + Bidvolume(3) + Bidvolume(4))] / [(Askvolume(0) + Askvolume(1) + Askvolume(2) + Askvolume(3) + Askvolume(4)) + (Bidvolume(0) + Bidvolume(1) + Bidvolume(2) + Bidvolume(3) + Bidvolume(4))]
What do I need to ad to the SMA code for developing this indicator? Thank you
The SMA code is:
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
[Description("The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.")]
public class SMA : Indicator
{
#region Variables
private int period = 14;
#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(Color.Orange, "SMA"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(Input[0]);
else
{
double last = Value[1] * Math.Min(CurrentBar, Period);
if (CurrentBar >= Period)
Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
else
Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
}
}
#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
}
Comment