please be patient with me cause I'm kinda new in NinjaScript. I'm struggling and cannot solve it on my own. In OnBarUpdate method I am checking if the current close is within the actual bar price range. When this condition occurs I am starting drawing two horizontal dashed lines which are indicating the upper and lower range of the high and low of the bar before. The blue diamond is indicating the bar that triggered the condition. See following screenshot how this looks like for better understanding:
[...] private double myOffset; int initBarIndex = 0; [...] if ( Close[0]>=Low[1] && Close[0]<=High[1] ) { int initBarIndex = CurrentBar-1; initBarHigh = High[1]; initBarLow = Low[1]; Draw.Line(this, "initBarTop", false, CurrentBar - initBarIndex, initBarHigh, -1, initBarHigh, Brushes.LimeGreen, DashStyleHelper.Dot, 2); Draw.Line(this, "initBarBot", false, CurrentBar - initBarIndex, initBarLow, -1, initBarLow, Brushes.LimeGreen, DashStyleHelper.Dot, 2); Diamond myDiamond = Draw.Diamond(this, "hit", true, 0, Low[0] - myOffset, Brushes.RoyalBlue); myDiamond.AreaBrush = Brushes.RoyalBlue; }
The current issues I'm facing:
As this condition is checked on each bar update, whenever a new bar has closed within its previous bar it's matched, too. That results in a nested triggering. In the screenshot above, when the most right bar (red) would close, it would trigger the condition and the middle green bar will become the new reference bar. I don't want this. I want to keep the most left bar as the important (=flagged) reference bar and as long as no close has occured above or below the most left reference bar.
I tried assigning initBarIndex = 0 and include this condition at very first check or integrate it in the existing if clause, something like:
if ( Close[0]>=Low[1] && Close[0]<=High[1] && initBarIndex == 0 ) ... else if ( Close[0]>initBarHigh || Close[0]<initBarLow) { initBarIndex = 0; RemoveDrawObject("initBarTop"); RemoveDrawObject("initBarBot"); }
thanks to all in advance
Patricia
Comment