Below you will see, and assumedly duplicate on your end, an If () condition that when false is still executing the Then {} sequence.
Note the line still prints & the text box prints also but not quite correctly. // at least on my end here
Set the bool to false as per code and it works correctly... // In my actual construct there are two bools and if one is false it won't print at all, which is correct procedure.
Bottom line looking to identify why the executable condition is still printing when the PriorDayOHLC has rendered a false condition.
Code:
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.j2
{
region Defaults
public class Testing : Indicator
{
private PriorDayOHLC PriorDayOHLC1;
private CurrentDayOHL CurrentDayOHL1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "xxx"
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
IsOverlay = true;
PaintPriceMarkers = true;
DrawOnPricePanel = true;
IsAutoScale = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
TextBrush = Brushes.White;
AutoBrush = Brushes.Yellow; /// automated line brush
Opacity = 100;
Size = 12;
Test1 = true;
}
else if (State == State.DataLoaded)
{
PriorDayOHLC1 = PriorDayOHLC(Close);
CurrentDayOHL1 = CurrentDayOHL(Close);
}
}
#endregion
region Code Sets
protected override void OnBarUpdate()
{
NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", Size) { Size = Size, Bold = true };
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
///************************************************** ****************************************
// set 1
if
(
(Close[0] == PriorDayOHLC1.PriorClose[0])
&& (Test1 == true)
// Ninja Forum , above code is the problem... Prior Day close appears to be the culprit and I don't know why... Note when price here is not exact to PD Close, the statement is false
// but the line will still print and the text box is incorrectly positioned.
// If the above prior day condition is false, nothing should print.
||
(Test1 == false)
/// Prints correctly
)
{
Draw.HorizontalLine(this, "pdcl1", true, PriorDayOHLC1.PriorClose[0], AutoBrush, DashStyleHelper.Solid, 2);
Draw.Text(this, "Test3", true, "See me at far right of screen", 0, PriorDayOHLC1.PriorClose[0] , 10, TextBrush, myFont, TextAlignment.Right, Brushes.Transparent, Brushes.Transparent, Opacity);
}
}
#endregion
region Properties
/// Display
[XmlIgnore]
[Display(ResourceType = typeof(Custom.Resource), Name = "TextBrush", GroupName = "Display", Order = 1)]
public Brush TextBrush { get; set; }
[Browsable(false)]
public string TextBrushSerialize
{
get { return Serialize.BrushToString(TextBrush); }
set { TextBrush = Serialize.StringToBrush(value); }
}
[XmlIgnore]
[Display(ResourceType = typeof(Custom.Resource), Name = "Automated Line Brush", GroupName = "Display", Order = 2)]
public Brush AutoBrush { get; set; }
[Browsable(false)]
public string AutoBrushSerialize
{
get { return Serialize.BrushToString(AutoBrush); }
set { AutoBrush = Serialize.StringToBrush(value); }
}
[NinjaScriptProperty]
[Display(Name="Opacity", Description="Opacity", GroupName="Display", Order = 4)]
public int Opacity
{ get; set; }
[NinjaScriptProperty]
[Display(Name = "Font Size", Description = "Font Size in pixels", GroupName = "Display", Order = 5)]
public int Size
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Test1", Description = "xxxx", GroupName="Parameters", Order = 1)]
public bool Test1
{ get; set; }
#endregion
}
}
Comment