Simple Coding Help - No Promise.

Snake.Head

Well-Known Member
Following code so show alternate Bar count on current day by sudris
I have edit code to add Toggle function to it
But when i Toggle it to NO it show Number on 1 on current bar
Can anyone point out what mistake i am doing in it

iBars = ParamToggle("BarCount","No|Yes",1);
if (iBars)
iBars = BarsSince( Day() != Ref( Day(), -1 ) );
for ( i = BarCount - ( LastValue( iBars ) + 1 ); i < BarCount; i=i+2 )
{
j = abs( ( LastValue( BarCount ) - 2 * i - ( LastValue( iBars - i ) ) - 2 ) );
PlotText( NumToStr( j, 1 ), i, L - L*0.001, colorBlack );
}



 

pratapvb

Well-Known Member
Following code so show alternate Bar count on current day by sudris
I have edit code to add Toggle function to it
But when i Toggle it to NO it show Number on 1 on current bar
Can anyone point out what mistake i am doing in it




iBars is a boolean? why have you used lastvalue with iBars or Barcount?

Edit: oh you have overwritten it with a calcuation...using same variable for both is confusing
 

Snake.Head

Well-Known Member
@pratapvb
Did't get you
Very novice on afl coding learning mostly trial and error method
Got it fixed by editing Value from 1 to 0
( LastValue( iBars ) + 1 )
iBars = ParamToggle("BarCount","No|Yes",1);
if (iBars)
iBars = BarsSince( Day() != Ref( Day(), -1 ) );
for ( i = BarCount - ( LastValue( iBars ) + 0 ); i < BarCount; i=i+2 )
{
j = abs( ( LastValue( BarCount ) - 2 * i - ( LastValue( iBars - i ) ) - 2 ) );
PlotText( NumToStr( j, 1 ), i, L - L*0.001, colorBlack );
}
 

pratapvb

Well-Known Member
@pratapvb
Did't get you
Very novice on afl coding learning mostly trial and error method
Got it fixed by editing Value from 1 to 0
( LastValue( iBars ) + 1 )
yes the loop was executing once because of that condition.....but was trying to hint at some programming standards for cleaner code also....because else when you start writing larger code you will only get confused as to what it is doing, when you go to modify it a few months later for something
 

Similar threads