To accomplish this I am using:
anchor.SlotIndex = anchor.SlotIndex + 1;
The problem is that if an Anchor is in a slot of an existing bar then it "cannot" be moved, but if the anchor is in an empty slot where there are no bars then the anchor "is" movable.
Here is the code of a simple test indicator that will move a manually placed dot:
namespace NinjaTrader.NinjaScript.Indicators.Cam.Development { public class Test5 : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Move dot 1 bar on bar close"; Name = "Test5"; Calculate = Calculate.OnBarClose; IsOverlay = true; } else if (State == State.Configure) { ClearOutputWindow(); } } protected override void OnBarUpdate() { Print(" "); foreach (DrawingTool dt in DrawObjects) { if(dt.Name == "Dot") { Print("Got the dot"); foreach (ChartAnchor anchor in dt.Anchors) { Print(anchor.DisplayName); if(anchor.DisplayName == "Anchor") { Print("Before incrementing, anchor.SlotIndex = " + anchor.SlotIndex); anchor.SlotIndex = anchor.SlotIndex + 1; Print("After incrementing, anchor.SlotIndex = " + anchor.SlotIndex); } } } } } #region Properties #endregion } }
- Start the indicator.
- Draw a dot over an existing bar. (see screen shot "a")
- Observe that it does not advance on bar update.
- Draw a dot forward of the bars 2 slots to be sure. (see screen shot "b")
- Observe that the dot advances 1 slot on each bar update.
Any help would be greatly appreciated.
Comment