Bruce,

Thanks as always for an exact reply.
Luckily I don't use the backtester... so for me, my rudimentary understanding 
and logic seems to have served my needs.

But always good to really understand what's going on under the hood.

--- In [email protected], "Bruce" <bru...@...> wrote:
>
> 
> 
> Ton, Rob -
> 
> Not exactly.
> 
> Last post on this, I promise, but the details can be important in other 
> situations where AFL cannot make this transparent.
> 
> Ton, let's expand your example slightly -
> 
> // 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 "+ ( mss = mySuperStr) );
> _TRACE("mySuperString2 "+ ( mss1 = Ref(mySuperStr,-1)) );
> _TRACE("mySuperString3 "+ ( mss2 = Ref(mySuperStr,-2)) );
> _TRACE( "TYPES - " + typeof( mss ) + " , " + 
>                               typeof( mss2 ) + " , " + 
>                               typeof( mss2 ) );
> Buy = Sell = Short = Cover = 0;
> 
> 
> All that I've done is made it a Scan and assigned three variables ( mss, 
> mss1, mss2) to the values that you are tracing.  Note that the output in 
> debug that I've added is -
> 
> TYPES - number , array , array
> 
> The variable mySuperStr is a SCALAR NUMBER.  What happens when you reference 
> previous values is that it is PROMOTED to an array of ALL THE SAME VALUE (the 
> last range value of Close).  So, mss1 and mss2 are arrays.
> 
> This promotion is probably what seems confusing.  It is NOT that AFL 
> recognizes all the same value and treats it as a scalar.  It is that AFL 
> recognizes when it wants an array, and promotes a scalar to an array.
> 
> Rob, if you want to prove this, consider the following -
> 
> test = C - C + 5;
> parm = Param( "parm", test, 1, 10, 1 );
> Buy = Sell = Short = Cover = 0;
> 
> In this case, the variable "test" is an array of all 5's.  You can't use it 
> in the Param() statement where it wants a scalar for the default value.
> 
> Hope that this explains it fully.
> 
> -- Bruce
> 
> P.S.  BTW, one example of why this distinction is important relates to the 
> CBT.  When you run a normal AFL, it makes a syntax pass and can detect where 
> parameter types are not correct - as in the Param() example above.  If there 
> is a type problem in the CBT, it doesn't show an error.  This is because the 
> CBT code is usually wrapped in a statement like -
> 
> if ( status( "actionex" ) == actionportfolio )
> {...}
> 
> So, they syntax checking pass can't "get into" that code block to do checking.
> 
> 
> 
> 
> 
> 
> 
> --- In [email protected], "Rob" <sidhartha70@> wrote:
> >
> > Ton,
> > 
> > As I have alluded to several times, AFL can spot an array with the same 
> > value all the way through it and in such a case can treat it like a 
> > scalar... which is what it does here.
> > 
> > Think about it... if an array has exactly the same value all the way 
> > through, and you know it, why would you give an error when accessing the 
> > array as a scalar...?? You'd have to be very pedantic. Luckily AFL isn't so 
> > pedantic!
> > 
> > --- In [email protected], "Ton Sieverding" <ton.sieverding@> wrote:
> > >
> > > Hi Bruce,
> > > 
> > > What I did is 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));
> > > 
> > > Putting Close in myString makes myString an array. Therefore I can access 
> > > all the historical elements in myString. Now we do the String Trick. This 
> > > gives me mySuperString. The fact that all elements are the same does not 
> > > mean that mySuperString no longer is an array. mySuperString is an array 
> > > because I can access all elements ...
> > > 
> > > 
> > > 
> > > So my question is, mySuperString being an array, how than is it possible 
> > > that I can handle this array with a simple IF. Why doesn't AmiBroker give 
> > > me an error ? Saying that I should use the complex IIF ...
> > > 
> > > Regards, Ton.
> > > 
> > > 
> > > 
> > > ----- Original Message ----- 
> > > 
> > >   From: Bruce 
> > >   To: [email protected] 
> > >   Sent: Monday, June 14, 2010 2:29 PM
> > >   Subject: [amibroker] Re: impenetrable AFL
> > > 
> > > 
> > >     
> > >   Yuki, Ton,
> > > 
> > >   Let me make what is hopefully a constructive suggestion.
> > > 
> > >   When in doubt, use AddColumn() for debug. It is your friend. In this 
> > > case, you might do something like the following Explore -
> > > 
> > >   res = StrToNum( NumToStr( C ) );
> > >   Filter = BarIndex( ) >= BarCount - 10;
> > >   AddColumn( C, "C", 8.2 );
> > >   AddColumn( res, "RES", 8.2 );
> > >   Plot( C, "C", colorred );
> > >   Title = "" + NumtoStr( C );
> > > 
> > >   Here's what happens in the code above. NumtoStr(C) must result in a 
> > > single string. So, in an Explore it takes the last Range value and 
> > > converts it to a string. (An indicator is a little different.) Then, the 
> > > StrtoNum just converts it back to a single scalar number. The easiest way 
> > > to see this is to "print it out" via AddColumn() statements.
> > > 
> > >   The promotion that Rob alluded to is a little different. It is when a 
> > > single scalar number of "promoted" to an array to carry out a 
> > > calculation. Consider the following -
> > > 
> > >   fact = 1.1;
> > >   array = Close * fact;
> > > 
> > >   The second statement multiples an array (Close) by a scalar number 
> > > (fact). There are a couple of ways to do this internally, but the easiest 
> > > way to visualize it is that fact is "promoted" to an array of numbers 
> > > with a value of 1.1 , and then the two arrays are multiplied.
> > > 
> > >   Hope this helps.
> > > 
> > >   -- Bruce
> > > 
> > >   --- In [email protected], "Rob" <sidhartha70@> wrote:
> > >   >
> > >   > It doesn't give you the same array... it gives you a scalar.
> > >   > (as Bruce mentioned it seems sometimes AFL can see an array has the 
> > > same value all the way through and treats it as a scalar).
> > >   > 
> > >   > --- In [email protected], Yuki Taga <yukitaga@> wrote:
> > >   > >
> > >   > > That was exactly my take on it. Wonderful that I can use IF, but why
> > >   > > is it possible?
> > >   > > 
> > >   > > Tomasz ???? (The layman's interpretation, please.) ^_^
> > >   > > 
> > >   > > Yuki
> > >   > > 
> > >   > > Monday, June 14, 2010, 5:11:34 PM, you wrote:
> > >   > > 
> > >   > > TS> Rick changing a string to a number THAT'S COMING FROM AN ARRAY
> > >   > > TS> and after that changing a number to a string again, should give
> > >   > > TS> me the same array with the initial strings. But the fact that I
> > >   > > TS> can use IF after the string manipulation shows me that I am no
> > >   > > TS> longer having an array ... I still do not get this. Weird ...
> > >   > > 
> > >   > > TS> Tomasz ????
> > >   > > 
> > >   > > TS> Regards, Ton.
> > >   > > 
> > >   > > 
> > >   > > TS> ----- Original Message ----- 
> > >   > > TS> From: Rick Osborn 
> > >   > > TS> To: [email protected] 
> > >   > > TS> Sent: Sunday, June 13, 2010 5:33 PM
> > >   > > TS> Subject: Re: [amibroker] impenetrable AFL
> > >   > > 
> > >   > > 
> > >   > > TS> 
> > >   > > 
> > >   > > TS> First off let me repeat - this is not my original code.
> > >   > > TS> I found it in someone's code for TD Sequential (with apologies
> > >   > > TS> to the original coder - didn't keep your name)
> > >   > > 
> > >   > > TS> The Buysignal is a Flip(Buy,Sell) type - or could be a 
> > > true/false item.
> > >   > > 
> > >   > > TS> Checking the help file the NunToStr says
> > >   > > TS> FUNCTION It is used to convert numeric value of NUMBER or ARRAY 
> > > to string.
> > >   > > TS> Next the StrToNum function
> > >   > > TS> FUNCTION It is used to convert numeric value of NUMBER or ARRAY 
> > > to string.
> > >   > > TS> So the combination of changing that value of the array from a
> > >   > > TS> number to a string and then "that string" back to "a number" 
> > > (not an array)
> > >   > > 
> > >   > > TS> LastValue works the same but I still don't understand that 
> > > function well enough.
> > >   > > TS> From the help file
> > >   > > TS> FUNCTION Returns last calculated value of the specified
> > >   > > TS> ARRAY. The result of this function can be used in place of a
> > >   > > TS> constant (NUMBER) in any function argument. 
> > >   > > TS> If ARRAY is undefined (e.g., only 100-days loaded and
> > >   > > TS> you request the last value of a 200-day moving average) then the
> > >   > > TS> lastvalue function returns zero. 
> > >   > > TS> Caveat: since this function fills an entire data array
> > >   > > TS> with the last value of another array, it allows a formula to 
> > > look into the future.
> > >   > > TS> so if there are repeated events (buy signals and sell
> > >   > > TS> signals), I'm not sure if lastvalue sees any but the last one. 
> > > Plus I worry about the Caveat!!
> > >   > > 
> > >   > > 
> > >   > > TS> Best Regards
> > >   > > TS> Rick Osborn
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > TS> ----------------------------------------------------------
> > >   > > TS> From: Ton Sieverding <ton.sieverding@>
> > >   > > TS> To: [email protected]
> > >   > > TS> Sent: Sun, June 13, 2010 2:55:32 AM
> > >   > > TS> Subject: Re: [amibroker] impenetrable AFL
> > >   > > 
> > >   > > TS> 
> > >   > > TS>  
> > >   > > 
> > >   > > TS> That's interesting code, Rick. Can you explain me why this 
> > > works ?
> > >   > > 
> > >   > > TS> 1. First I assume BuySignal to be BUY. Therefore being an
> > >   > > TS> array. So IF should not work. Should be IIF. But even when I put
> > >   > > TS> there BUY to be sure it's an array, it does work. Why ?
> > >   > > 
> > >   > > TS> 2. What's the difference between StrToNum(NumtoStr( BUY)) and
> > >   > > TS> BUY ? Should give me the same result. But is does not. Without
> > >   > > TS> this trick I cannot use IF. What's going on here ????
> > >   > > 
> > >   > > TS> Regards, Ton.
> > >   > > 
> > >   > > 
> > >   > > TS> ----- Original Message ----- 
> > >   > > TS> From: Rick Osborn 
> > >   > > TS> To: amibro...@yahoogrou ps.com 
> > >   > > TS> Sent: Saturday, June 12, 2010 10:52 PM
> > >   > > TS> Subject: Re: [amibroker] impenetrable AFL
> > >   > > 
> > >   > > 
> > >   > > TS> 
> > >   > > 
> > >   > > TS> Yuki
> > >   > > 
> > >   > > TS> I have the following code which changes the background
> > >   > > TS> gradient color depending on whether a buy or sell signal is 
> > > given.
> > >   > > 
> > >   > > TS> if(StrToNum(NumToStr(BuySignal)) ) 
> > >   > > TS> bgColor = ColorRGB(0,66, 2); 
> > >   > > TS> else 
> > >   > > TS> bgColor = ColorRGB(66,2, 0); 
> > >   > > TS> SetChartBkGradientF ill( colorBlack, bgColor); 
> > >   > > 
> > >   > > 
> > >   > > TS> Perhaps you can change this to meet your needs
> > >   > > 
> > >   > > 
> > >   > > TS> Best Regards
> > >   > > TS> Rick Osborn 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > TS> ----------------------------------------------------------
> > >   > > TS> From: Yuki Taga <yukit...@tkh. att.ne.jp>
> > >   > > TS> To: amibro...@yahoogrou ps.com
> > >   > > TS> Sent: Sat, June 12, 2010 1:24:58 AM
> > >   > > TS> Subject: [amibroker] impenetrable AFL
> > >   > > 
> > >   > > TS> 
> > >   > > TS> Impenetrable! (At least to me.)
> > >   > > 
> > >   > > TS> xcolor = IIf(TSI >= SigLine, SetChartBkGradientF ill(
> > >   > > TS> ParamColor(" BgTop", ColorRGB( 172,172,172 )),
> > >   > > TS> ParamColor(" BgBottom" , ColorRGB( 172,172,172 ))),
> > >   > > TS> SetChartBkGradientF ill( ParamColor(" BgTop", ColorRGB(140, 
> > > 140,140)) ,
> > >   > > TS> ParamColor(" BgBottom" , ColorRGB(140, 140,140)) ));
> > >   > > 
> > >   > > TS> SetChartBkColor( SelectedValue( xcolor));
> > >   > > 
> > >   > > TS> I tried that line above as
> > >   > > TS> SetChartBkGradientF ill(SelectedValu e(xcolor) ); but that 
> > > produced a
> > >   > > TS> syntax error.
> > >   > > 
> > >   > > TS> I think you can see what I'm trying to do here. The idea is 
> > > simple:
> > >   > > TS> change the background gradient depending on a true/false 
> > > result. The
> > >   > > TS> gradients in this example are not the gradients I would 
> > > actually use
> > >   > > TS> (in fact they are not gradients at all, as your intelligent 
> > > eyes will
> > >   > > TS> quickly have seen). They are just test code to see if I can even
> > >   > > TS> make it work. I cannot.
> > >   > > 
> > >   > > TS> For one thing, the gradient does not change no matter the 
> > > selected
> > >   > > TS> value. It's static. For another thing, the margin background 
> > > goes
> > >   > > TS> to black, a hideous (although somewhat foreseen) result.
> > >   > > 
> > >   > > TS> Okay, what am I doing wrong, and where did I miss this in the 
> > > docs?
> > >   > > TS> And what, if anything, can I do about this margin result? The 
> > > only
> > >   > > TS> way I can change the *entire* background color is by not using a
> > >   > > TS> gradient??? (Using SetChartBkColor) How sad that would be! I can
> > >   > > TS> make that work, at least. But not with a gradient.
> > >   > > 
> > >   > > TS> Anything is possible in Amibroker, right?
> > >   > > 
> > >   > > TS> Wrong?
> > >   > > 
> > >   > > TS> Thanks,
> > >   > > 
> > >   > > TS> Yuki
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > TS>
> > >   > >
> > >   >
> > >
> >
>


Reply via email to