PureBytes Links
Trading Reference Links
|
Hello,
I have been trying to get a loop to work that has only 7 elements.
Method #1
It keeps giving subscript 'out of range',
The 7 elements are overwritten each iteration.
If I use full array size of barcount it works ok. Method #2
A code section is below to illustrate what I am trying to do.
Which is the method to employ? or is there a basic mistake in method#1?
I suppose I could use non-array variables for each exit condition,
but more it is easier to code (convenient) to use an array later in
the code to determine sell signal and type
thanks for your help
and the heap of tips from the group in the past
fe
=========================================================
SetOption("InitialEquity", 20000 );
SetTradeDelays(1,1,1,1);
SetOption("MaxOpenPositions", 20);
// simple system...
p1 = 10;
p2 = 22;
MaxNumExit = 7;
// MA crossover
Sell=0;
Buy=Cross( MA(C,p2) , MA(C,p1) );
Buy =ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Filter = Buy OR Sell;
//set up array to Check if exit Conditions(7) are met;
//an array of 7 elements holds the result of each exit condition per
iteration=i
//the exit array is initialised to zero at beginning of exit condition
code
//at end of exit condition code determine if exit signal and exit type
number
//METHOD #1 - ERROR
in_Trade = 0;
// want to iterate to find exit conditions
for(i=1; i<BarCount; i++)
{
in_Trade[i] = ( in_trade[i-1] OR (Buy[i] AND !Buy[i-1]) ) AND !Sell[i-1];
//-BELOW ALWAYS SUBSCRIPT OUT OF RANGE ERROR
for(k=1; k<=MaxNumExit; k++) { ExitP[k] = 0; } //initialise exit array
// exit condition 1 to 7 here
for(k=1; k<=MaxNumExit; k++)
{
//determine exit type here-SUBSCRIPT OUT OF RANGE
}
}
//METHOD #2 - OK
in_Trade = 0;
//if change to array size,for all loops
for(i=1; i<BarCount; i++)
{
in_Trade[i] = ( in_trade[i-1] OR (Buy[i] AND !Buy[i-1]) ) AND !Sell[i-1];
// NO ERROR
for(k=1; k<BarCount; k++) { ExitP[k] = 0; } //initialise exit array
}
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|