HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise Man)

#1
Hi,

I am trying to plot arrows based on Bill William's Third wise man. I am looking for five price bars at a time and comparing High values. If the middle high is higher than previous two highs and next two highs, I want to plot up Arrow symbol. However with the following code, I end up plotting uparrow on every bar (even when value of tmp is false). What am I doing wrong here?

for( i = 3; i < (BarCount-2); i++ )
{
tmp = (High > High[i-1]) AND (High[i-1] > High[i-2]) AND (High > High[i+1]) AND (High[i+1] > High[i+2]);
//_TRACE("tmp : " + tmp);
PlotShapes( IIf( tmp, shapeUpArrow, shapeNone ), colorGreen,0, H,10 );
}
 
#2
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

OHLC are all arrays. You dont need to, and, should not use it as array. Just try the following :

tmp = (High > Ref(High,-1)) AND (High > Ref(High,-2)) AND (High > Ref(High,1)) AND (High > Ref(High,2));
PlotShapes( IIf( tmp, shapeUpArrow, shapeNone ), colorGreen,0, H,10 );
 
#3
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

OHLC are all arrays. You dont need to, and, should not use it as array. Just try the following :

tmp = (High > Ref(High,-1)) AND (High > Ref(High,-2)) AND (High > Ref(High,1)) AND (High > Ref(High,2));
PlotShapes( IIf( tmp, shapeUpArrow, shapeNone ), colorGreen,0, H,10 );
Thanks a lot "TheTrader". This resolved the issue. Thanks for all your help. I was banging my head from last one week on this :eek:

Once again, thank you for helping me!
 

kkseal

Well-Known Member
#4
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

That still doesn't explain why the original code was not working. Think the for loop should have started with i=2, but is that the reason?
 

aad

Active Member
#5
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

That still doesn't explain why the original code was not working. Think the for loop should have started with i=2, but is that the reason?
for loop can start with i=2 but the correct code is

_SECTION_BEGIN("William's Third Wise Man");

for( i = 3; i < (BarCount-2); i++ )
{
tmp = (High > High[i-1]) AND (High[i-1] > High[i-2]) AND (High > High[i+1]) AND (High[i+1] > High[i+2]);
}
PlotShapes( IIf( tmp, shapeUpArrow, shapeNone ), colorGreen,0, H,10 );

_SECTION_END();

We need to store value of tmp in an array corresponding to each value of i when we use for loop. Once that is done, we then use PlotShapes() function only once (using capabilities of array in Amibroker).

Best regards,

Abhay
 

kkseal

Well-Known Member
#6
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

for loop can start with i=2 but the correct code is

_SECTION_BEGIN("William's Third Wise Man");

for( i = 3; i < (BarCount-2); i++ )
{
tmp = (High > High[i-1]) AND (High[i-1] > High[i-2]) AND (High > High[i+1]) AND (High[i+1] > High[i+2]);
}
PlotShapes( IIf( tmp, shapeUpArrow, shapeNone ), colorGreen,0, H,10 );

_SECTION_END();

We need to store value of tmp in an array corresponding to each value of i when we use for loop. Once that is done, we then use PlotShapes() function only once (using capabilities of array in Amibroker).

Best regards,

Abhay


Thanks a lot. I too felt 'tmp' was being treated as an array rather than a variable. (Moreover IIF expects an array rather than a variable though it works fine with the reserved ones like 'Buy','Sell').

But shouldn't we be using tmp[i-3] to store the array values correctly in the tmp array?

Or maybe we should simply use IF-ELSE in the original code rather than IIF.
Regards
 
Last edited:

aad

Active Member
#7
Re: HELP NEEDED: What's wrong with the PlotShapes in this AFL (William's Third wise M

But shouldn't we be using tmp[i-3] to store the array values correctly in the tmp array?
No need. Corresponding to the value i, you will have to store high and tmp in same column only. If you store at tmp[i-3] then you are asking Amibroker to store tmp[i-3] in the column of high, which will give wrong results i.e. when the condition for tmp returns 'true', it will be shown at 3 bars prior to actual bar... :)

Or maybe we should simply use IF-ELSE in the original code rather than IIF.
Regards
As you know very well, IIF will be faster than IF-ELSE, although both will function the same.

Regards,

Abhay
 

Similar threads