Sorry, I don't understand your question. However, I see that you've used a break statement inside your loop, which means that it will terminate on the first iteration. I'm guessing that's not what you want.
Your code does not seem to have properly balanced braces. There is extra brace before 'while':
Instead of:
do
{
MS[ i ] = 2 + IIf( prevMS[ i ] == 3, 1, IIf(prevMS[ i ] == 4, 2, prevMS[ i ]));
break;
} // one brace too much
}while( a[ i ] <= max_b And a[ i ] >= min_d );
you should rather have:
do
{
MS[ i ] = 2 + IIf( prevMS[ i ] == 3, 1, IIf(prevMS[ i ] == 4, 2, prevMS[ i ]));
break;
}
while( a[ i ] <= max_b And a[ i ] >= min_d );
Use Edit->Code Prettify to quickly find such things. Prettify does the indenting and makes it easier to spot such mistakes.
Please listen to what @mradtke wrote - you've got break inside do-while which means exit the loop immediately. Also there can be other issues in your code (but it is incomplete and we can't run it because there are missing parts). You should use advice given here: How do I debug my formula?
i have some doubt for do statement while (expression) the following the below code.
i had using time frame inDaily.
previous Day 3 bar index value, that means past 3 days. suppose to yesterday (a[ f ]) value in between of previous 2 day (max_b & min_d). Do-While expression executive. a[ f ] array value check every day with max_b & min_d, if expression is false, statement terminate, if expression is true, statement repeated.
i tried many times but _Trace showing 0. where i am mistake.
bi = LastValue( BarIndex() );
max_b = Max( MSF[ bi-1 ] , MSF[ bi-2 ] ) ;
min_d = Min( MSF[ bi-1 ] , MSF[ bi-2 ] ) ;
prevMSFC[ f ] = MSFC[ f-1 ];
if( a[ f ] <= max_b And a[ f ] >= min_d )
{
do
{
MSFC[ f ] = 2 + IIf( prevMSFC[ f ] == 3, 1, IIf(prevMSFC[ f ] == 4, 2, prevMSFC[ f ]));
f++;
}while( a[ f ] <= max_b And a[ f ] >= min_d );
}
MSFC[ 1 ] = 1; // G
MSFC[ 2 ] = iif(MSF[ 2 ] > MSF[ 1 ],1,2);
max_b[ 0 ] = 0; // Dummy Value for first Array
min_d[ 0 ] = 0; // Dummy Value for first Array
f = 3; // starting point
do
{
d[ f ] = MSF[ f-2 ];
b[ f ] = MSF[ f-1 ];
a[ f ] = MSF[ f ];
MSFColor[ f ] = MSFC[ f-1 ];
if(a[ f ] > b[ f ] And a[ f ] > d[ f ])
{
MSFC[ f ] = 1; // G
}else
{
if(a[ f ] < b[ f ] And a[ f ] < d[ f ])
{
MSFC[ f ] = 2; // R
}else
{
bi = LastVisiblevalue( BarIndex() );
max_b[ bi ] = Max( MSF[ bi-1 ] , MSF[ bi-2 ] ) ;
min_d[ bi ] = Min( MSF[ bi-1 ] , MSF[ bi-2 ] ) ;
prevMSFC[ f ] = MSFC[ f-1 ];
if( a[ f ] <= max_b[ bi ] And a[ f ] >= min_d[ bi ] )
{
do
{
MSFC[ f ] = 2 + IIf( prevMSFC[ f ] == 3, 1, IIf(prevMSFC[ f ] == 4, 2, prevMSFC[ f ]));
f++;
}while( a[ f ] <= max_b[ bi ] And a[ f ] >= min_d[ bi ] );
}
}
}
}while( ++f < BarCount );