I'm new in programming.
I have to calculate the ratio between the body and the whole range of the previous day.
I tried using the function Math.abs but I must have done something wrong ...
I enclose here a test script with the function of ratio included, what I did wrong?
#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// This strategy enter simply long at high of previoos day. /// </summary> [Description("This strategy enter simply long at high of previoos day.")] public class BreakExample : Strategy { #region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 private double prevHigh = 0; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { //prova di calcolo del rapporto tra close-open e high-low del giorno precedente if ((Math.Abs(PriorDayOHLC().PriorClose[0] - PriorDayOHLC().PriorOpen[0]) / (PriorDayOHLC().PriorHigh[0] - PriorDayOHLC().PriorLow[0])) < 0.5) return; if (Bars.BarsSinceSession >= 1) { EnterLongStop(DefaultQuantity, PriorDayOHLC().PriorHigh[0], ""); } } #region Properties [Description("")] [GridCategory("Parameters")] public int MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #endregion } }
Comment