Loop Issue  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Loop Issue

Postby Jobauma » 29 Sep 2013

The problem begins when the second loop and "m_TL_1stHH_curBar" are in the picture. I wonder why this doesn't work.. Hope it's not a bug! Or at least there's some other way around it. :)

Code: Select all

for ( int i = 0; i < 10; i++ )
{
m_TL_Counter++;
if ( m_TL_Value[0] < m_TL_Value[m_TL_Counter] ) m_TL_CheckBack = true;
}
m_TL_Counter = 0;

if (m_TL_CheckBack)
{
do
{
m_TL_Counter++;
if ( m_TL_Value[0] < m_TL_Value[m_TL_Counter] ) m_TL_1stHH_curBar = m_TL_Counter;
}
while ( m_TL_Value[0] > m_TL_Value[m_TL_Counter] );
m_TL_Counter = 0;

do
{
m_TL_Counter++;
if ( m_TL_Value[m_TL_1stHH_curBar] < m_TL_Value[ m_TL_1stHH_curBar + m_TL_Counter ] )
{
m_TL_2ndHH_curBar = m_TL_1stHH_curBar + m_TL_Counter;
Output.WriteLine( "{0}", Bars.CurrentBar );
}
}
while ( m_TL_Value[m_TL_1stHH_curBar] > m_TL_Value[ m_TL_1stHH_curBar + m_TL_Counter ] );
m_TL_Counter = 0;
m_TL_CheckBack = false;
}

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Loop Issue

Postby JoshM » 30 Sep 2013

The problem begins when the second loop and "m_TL_1stHH_curBar" are in the picture. I wonder why this doesn't work..
What is the problem exactly beside 'a loop issue'?

Regarding your code, why do you use a for loop and not use the i increment variable (but instead your m_TL_counter)? Is that an oversight error or deliberate?

A do...while loop is commonly used if you need to execute the code segment at least once. Is that the case here or would a regulary for loop also suffice?

Do you need two do...while loops or can this also be combined in one loop? If your 'loop issue' has to do with an infinite loop, you might want to add a check for that.

Btw, if I understand your code correctly, you don't need a while loop since m_TL_counter < Bars.CurrentBar.

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: Loop Issue  [SOLVED]

Postby Jobauma » 30 Sep 2013

:)

Code: Select all

m_TL_1stRun = true;
for ( int i = 0; i < 20; i++ )
{
if ( m_TL_2ndRun && m_TL_Value[m_TL_1stHH_curBar] < m_TL_Value[i] )
{
m_TL_2ndHH_curBar = i;
m_TL_addTL = true;
m_TL_2ndRun = false;
}
else if ( m_TL_1stRun && m_TL_Value[0] < m_TL_Value[i] )
{
m_TL_1stHH_curBar = i;
m_TL_2ndRun = true;
m_TL_1stRun = false;
}
}


Return to “MultiCharts .NET”