I have a set of conditional code but I don't see any error in my code. I am guessing something is different on Ninja 8.
What I am trying to achieve: I added several time frames but only want to process these additional time frames after I hit a Session begin for BarsInProgress == 1. I am using the variable BarsinProgress1SessionStart to designate I hit a session begin. At first I used a bool but after having issues I tried an integer but currently it is a string.
here is some code snippets:
// Declare the variable
private string BarsinProgress1SessionStart ="0";
----------------------------
// set the variable default to "0" like a bool.
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
BarsinProgress1SessionStart = "0";
//Set the variable to "1" when IsFirstBarOfSession && BarsInProgress == 1). This code works fine.
if (Bars.IsFirstBarOfSession && BarsInProgress == 1)//if New session - reset counters - Reset Arrays
{
Print("2.1 "+ Volume[0] + " , " + Bars.IsFirstBarOfSession + " , " + CurrentBar + " ," + BarsinProgress1SessionStart + " , " + Time[0] + " , " + BarsInProgress);
BarsinProgress1SessionStart = "1";//Flag You have received an session begin
--------------------
// Skip any ticks if the Session Start has not been hit
if (BarsinProgress1SessionStart == "0");// If you have not received a session start or it is BarsInProgress == 0
{
if (DebugCount < 20)//Only print the first 20 ticks showing BarsInProgress and the value of BarsinProgress1SessionStart
{
DebugCount ++;
Print("2.2a " + BarsInProgress + " , " + BarsinProgress1SessionStart);
}
return;//Exit - skip ticks until otherwise false
}
// Her is a debug listing from the above code, you can clearly seethe 2.2a BarsinProgress1SessionStart is "1" but the "if" logic clearly says only do if: if (BarsinProgress1SessionStart == "0").
The value is "1" but executes the code when it should not be.
2.1 1 , True , 0 ,0 , 1/24/2023 2:20:00 AM , 1
2.2a 1 , 1
2.2a 1 , 1
2.2a 2 , 1
2.2a 1 , 1
2.2a 1 , 1
2.2a 1 , 1
2.2a 1 , 1
2.2a 2 , 1
2.2a 5 , 1
2.2a 2 , 1
Any help or suggestions for a blind guy? I have been a software developer for multiple decades so am not a newbie. I just don't see what I am doing wrong.
Cheers
Comment