Question about the use of StaticVarGenerateRanks, it's different between 6.00.2 & 6.40.4 versions, and i'm wondering how to use StaticVarGenerateRanks in the right way. Here's the situation:
The version of my previous Amibroker was 6.00.2.
I follwed the guide ( StaticVarGenerateRanks - guide ) and update to 6.40.4 version, but the use of StaticVarGenerateRanks seems to have changed (different from the guide) :
6.00.2 version --> when SetForeign every Symbols which need to be Rank inside the LOOP,
6.40.4 version --> alerm: "Warning 512"
Warning 512 is in regards to inefficient use of SetForeign within loop. StaticVarGenerateRanks can be used without loop.
Codes have been posted already.
Re-read 2nd post. Read slowly and try to understand.
You got response and reason for warning already (as well as alternative way without any loop and where to find it... well, forum search).
Warning 512 says exactly what is all about. It says:
Warning 512. Calling Foreign() or SetForeign() too many times (in a loop or in repeated code) is very inefficient.
It means, that IF ONLY YOU CAN you should avoid calling Foreign lots of times.
If you can't, the code continues to WORK FINE. The warning just indicates that your code is inefficient. Inefficient, but still working.
You can use StaticVarGenerateRanks without Foreign calls at all. In 6.40.4 there is a #pragma sequence command that allows to run StaticVarGenerateRanks in first step of sequence (scan). For examples see this thread:
Generally Foreign-less scheme would look something like that:
Version( 6.40 ); // required version
// IMPORTANT RUN THIS CODE AS SEQUENCE in 6.40.4
#pragma sequence( scan, explore )
if( Status( "action" ) == actionScan )
{
if( Status( "StockNum" ) == 0 )
{
StaticVarRemove( "ValuesToSort*" );
}
Values = - Close; // NO NEED TO CALL Foreign !
StaticVarSet( "ValuesToSort" + Name(), Values );
_exit(); // we are done - don't proceed further
}
if( Status("StockNum") == 0 )
{
// remove previous rankings if any
StaticVarRemove( "rank*" );
// do the ranking
StaticVarGenerateRanks("rank", "ValuesToSort", 0, 1224);
}