What that means is that I will provide the code that you want for the Long side; the Short side will follow the same ideas. You will have to copy and paste the code into the correct places in a new indicator that you write (or modify your current one, as required).
#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.Gui.Chart; using System.Collections; //must be added #endregion
#region Variables private int RayCount = 0; private ArrayList RaysToBeDeleted = new ArrayList(); private ArrayList RaysToBeDeletedTags = new ArrayList(); #endregion
protected override void Initialize() { Overlay = true; DrawOnPricePanel = false; }
protected override void OnBarUpdate() { if (CurrentBar < 2) return; bool LongSetup = false; LongSetup = High[0] <= Low[2] && Low[1] < Low[2]; if (LongSetup) { RayCount++; //increase count, to use in creating unique ID DrawRay("ray"+RayCount.ToString(), false, 2, Low[2], 0, Low[2], Color.Lime, DashStyle.Solid, 2); } //find rays to be handled foreach (IDrawObject draw in DrawObjects) { if (draw.UserDrawn) continue; if (draw is IRay && draw.Tag.StartsWith("ray")) //most likely one that the script drew { IRay tempRay = (IRay)draw; if (High[0] > tempRay.Anchor1Y) //ray to be converted by overwriting and deletion { this.RaysToBeDeleted.Add(tempRay); //add ray to list of rays to be deleted this.RaysToBeDeletedTags.Add(tempRay.Tag); //add tag to list of rays to be deleted } } } //process rays - draw line where there was a ray. Stop one bar ahead of CurrentBar. foreach (IRay tempRay in this.RaysToBeDeleted) { string rayNumber = tempRay.Tag.Substring(3); //extract ray number int startBarsAgo = tempRay.Anchor1BarsAgo; int endBarsAgo = 1; double lineLevel = tempRay.Anchor1Y; DrawLine("line"+rayNumber, false, startBarsAgo, lineLevel, endBarsAgo, lineLevel, Color. Cyan, DashStyle.Solid, 2); } //delete rays foreach (string str in this.RaysToBeDeletedTags) { RemoveDrawObject(str); } this.RaysToBeDeleted.Clear(); //reset the ArrayList this.RaysToBeDeletedTags.Clear(); //reset the ArrayList } }
Comment