You are quite right
All I was referring to is the fact that at that point in the execution of the code, the If statement seems to see it as just a number and not an array.
The explanation of others is, of course, more informative

 
Best Regards
Rick Osborn



From: Ton Sieverding <[email protected]>
To: [email protected]
Sent: Tue, June 15, 2010 3:57:37 AM
Subject: Re: [amibroker] impenetrable AFL

 



Hi Rick,
 
    As you can see, in the mean time I have got several answers. Interesting enough we all have different opinions about this topic. But frankly I do not agree with "It becomes just a number, not an array". Why not ? Because that's not what I see. Did you ever try to access different elements in a number ? Do the following ...
 
// This is an array ...

myString = Close;

_TRACE("myString1 "+myString);

_TRACE("myString2 "+Ref(myString,-1));

_TRACE("myString3 "+Ref(myString,-2));

// This still is an array ...

mySuperStr = StrToNum(NumToStr(Close));

_TRACE("mySuperString1 "+mySuperStr) ;

_TRACE("mySuperString2 "+Ref(mySuperStr, -1));

_TRACE("mySuperString3 "+Ref(mySuperStr, -2));

Giving me :

So for me it's still an array. And according to the AmiBroker Help you cannot handle arrays with an simple IF. For that you need a complex IIF.

Now it seems that if all elements in an array are equal, it's possible to use the simple IF. Because the IF thinks you are working with a number or string. ( Bruce ) If that's the case - and only Tomasz can tell me that - than the above is a simple way to use the simple IF for situations where you normally should use an complex IIF ... Therefore I find this code very interesting ...

Regards, Ton.

 
----- Original Message -----
Sent: Tuesday, June 15, 2010 2:50 AM
Subject: Re: [amibroker] impenetrable AFL

 

Ton
You may have this a little backward.
The first operation is NumToString - which changes the array value to a string.
The next operation is StrToNum - which changes the string back to a number.  It becomes just a number, not an array
 
Best Regards
Rick Osborn



From: Ton Sieverding <ton.sieverding@ scarlet.be>
To: amibro...@yahoogrou ps.com
Sent: Mon, June 14, 2010 4:11:34 AM
Subject: Re: [amibroker] impenetrable AFL

 



Rick changing a string to a number THAT'S COMING FROM AN ARRAY and after that changing a number to a string again, should give me the same array with the initial strings. But the fact that I can use IF after the string manipulation shows me that I am no longer having an array ... I still do not get this. Weird ...
 
Tomasz ????
 
Regards, Ton.
 
 
----- Original Message -----
Sent: Sunday, June 13, 2010 5:33 PM
Subject: Re: [amibroker] impenetrable AFL

 

First off let me repeat - this is not my original code.
I found it in someone's code for TD Sequential (with apologies to the original coder - didn't keep your name)

The Buysignal is a Flip(Buy,Sell) type - or could be a true/false item.

Checking the help file  the NunToStr  says
FUNCTION It is used to convert numeric value of NUMBER or ARRAY to string.
Next the StrToNum function
FUNCTION It is used to convert numeric value of NUMBER or ARRAY to string.
So the combination of changing that value of the array from a number to a string and then "that string" back to "a number" (not an array)

LastValue works the same but I still don't understand that function well enough.
From the help file
FUNCTION Returns last calculated value of the specified ARRAY. The result of this function can be used in place of a constant (NUMBER) in any function argument.
If ARRAY is undefined (e.g., only 100-days loaded and you request the last value of a 200-day moving average) then the lastvalue function returns zero.
Caveat: since this function fills an entire data array with the last value of another array, it allows a formula to look into the future.
so if there are repeated events (buy signals and sell signals), I'm not sure if lastvalue sees any but the last one.  Plus I worry about the Caveat!!
 
Best Regards
Rick Osborn



From: Ton Sieverding <ton.sieverding@ scarlet.be>
To: amibro...@yahoogrou ps.com
Sent: Sun, June 13, 2010 2:55:32 AM
Subject: Re: [amibroker] impenetrable AFL

 



That's interesting code, Rick. Can you explain me why this works ?
 
1. First I assume BuySignal to be BUY. Therefore being an array. So IF should not work. Should be IIF. But even when I put there BUY to be sure it's an array, it does work. Why ?
 
2. What's the difference between StrToNum(NumtoStr( BUY)) and BUY ? Should give me the same result. But is does not. Without this trick I cannot use IF. What's going on here ????
 
Regards, Ton.
 
 
----- Original Message -----
Sent: Saturday, June 12, 2010 10:52 PM
Subject: Re: [amibroker] impenetrable AFL

 

Yuki

I have the following code which changes the background gradient color depending on whether a buy or sell signal is given.

if(StrToNum(NumToStr(BuySignal)) )
bgColor =
ColorRGB(0,66, 2);
else
bgColor =
ColorRGB(66,2, 0);
SetChartBkGradientF ill( colorBlack, bgColor);


Perhaps you can change this to meet your needs

Best Regards
Rick Osborn



From: Yuki Taga <yukit...@tkh. att.ne.jp>
To: amibro...@yahoogrou ps.com
Sent: Sat, June 12, 2010 1:24:58 AM
Subject: [amibroker] impenetrable AFL

 

Impenetrable! (At least to me.)

xcolor = IIf(TSI >= SigLine, SetChartBkGradientF ill( ParamColor(" BgTop", ColorRGB( 172,172,172 )),
ParamColor(" BgBottom" , ColorRGB( 172,172,172 ))), SetChartBkGradientF ill( ParamColor(" BgTop", ColorRGB(140, 140,140)) ,
ParamColor(" BgBottom" , ColorRGB(140, 140,140)) ));

SetChartBkColor( SelectedValue( xcolor));

I tried that line above as
SetChartBkGradientF ill(SelectedValu e(xcolor) ); but that produced a
syntax error.

I think you can see what I'm trying to do here. The idea is simple:
change the background gradient depending on a true/false result. The
gradients in this example are not the gradients I would actually use
(in fact they are not gradients at all, as your intelligent eyes will
quickly have seen). They are just test code to see if I can even
make it work. I cannot.

For one thing, the gradient does not change no matter the selected
value. It's static. For another thing, the margin background goes
to black, a hideous (although somewhat foreseen) result.

Okay, what am I doing wrong, and where did I miss this in the docs?
And what, if anything, can I do about this margin result? The only
way I can change the *entire* background color is by not using a
gradient??? (Using SetChartBkColor) How sad that would be! I can
make that work, at least. But not with a gradient.

Anything is possible in Amibroker, right?

Wrong?

Thanks,

Yuki

Reply via email to