[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Nested Optimizing Loops



PureBytes Links

Trading Reference Links




I'm having trouble getting these loops to work properly.  
Can anyone point out the error(s)?
 
Thanks
lou
------------------------------------------------
 

PositionSize = 2000<FONT 
size=1>;
//range.
xbestequity = 0;
xbestrange = 0;

// optimization loop<FONT 
size=1>

<FONT 
color=#800000 size=1>for( xrange = <FONT 
face="Courier New" color=#ff00ff size=1>5; xrange < 
17; xrange = (xrange + 
1) )
{

//----------------------------------------------------------------------------------------------------<FONT 
size=1>
// spot for second loop<FONT 
face="Courier New" size=1>
ybestequity = <FONT 
color=#ff00ff size=1>0<FONT 
face="Times New Roman">;
ybestrange = <FONT 
color=#ff00ff size=1>0;

// optimization loop<FONT 
size=1>

<FONT 
color=#800000 size=1>for( yrange = <FONT 
face="Courier New" color=#ff00ff size=1>4; yrange < 
19; yrange = (yrange + 
1) )
{

// 
---------------------------------------------------------------------------------------------<FONT 
size=1>
// spot for z score code<FONT 
face="Courier New" size=1>
<FONT 
size=1>ZScore=(Close-MA<FONT 
size=1>(Close,xrange))/<FONT color=#0000ff 
size=1>StDev(Close,yrange);<FONT color=#008000 
size=1>// 13 11
zLive = <FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4);
zsig = <FONT 
color=#0000ff size=1>MA(<FONT color=#0000ff 
size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>Cross(Zlive, 
zsig);
Sell<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>IIf(zlive < (zsig ), <FONT 
color=#ff00ff size=1>1, <FONT color=#ff00ff 
size=1>0);
 <FONT color=#008000 
size=1>
// 
---------------------------------------------------------------------------------------------<FONT 
size=1>
Le = <FONT 
color=#0000ff size=1>LastValue( <FONT color=#0000ff 
size=1>Equity() );

<FONT 
color=#800000 size=1>if( Le > ybestequity )
{
ybestequity = 
Le;
ybestrange = 
yrange;
}
}

yrange = 
ybestrange;
 
//----------------------------------------------------------------------------------------------------<FONT 
size=1>

<FONT 
size=1>ZScore=(Close-MA<FONT 
size=1>(Close,<FONT face="Courier New" 
size=1>xrange))/<FONT 
color=#0000ff size=1>StDev(Close,<FONT 
face="Courier New" size=1>yrange<FONT 
face="Times New Roman">);
zLive = <FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4);
zsig = <FONT 
color=#0000ff size=1>MA(<FONT color=#0000ff 
size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>Cross(Zlive, 
zsig);
Sell<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>IIf(zlive < (zsig ), <FONT 
color=#ff00ff size=1>1, <FONT color=#ff00ff 
size=1>0);
Le = <FONT color=#0000ff 
size=1>LastValue( <FONT color=#0000ff 
size=1>Equity() );

if( Le > 
xbestequity )
{
xbestequity = Le;
xbestrange = xrange;
}
}

xrange = xbestrange;


ZScore=(Close-MA<FONT 
size=1>(Close,xrange<FONT 
size=1>))/StDev<FONT 
size=1>(Close,yrange<FONT 
size=1>);
zLive = MA<FONT 
size=1>(zscore,4);
zsig = MA(<FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy = Cross(Zlive, 
zsig);
Sell = IIf(zlive 
< (zsig ), 1, 
0);
 
//Buy = 
ExRem(Buy, Sell);<FONT face="Courier New" color=#008000 
size=1>
//Sell = 
ExRem(Sell, Buy);

Filter = BarIndex<FONT 
size=1>() == BarCount - 1<FONT 
size=1>;


AddColumn( <FONT face="Courier New" 
size=1>xbestrange, <FONT color=#ff00ff 
size=1>"x<FONT 
color=#ff00ff size=1>Best range" );<FONT 
color=#0000ff size=1>
AddColumn( <FONT face="Courier New" 
size=1>ybestrange, <FONT color=#ff00ff 
size=1>"y<FONT 
color=#ff00ff size=1>Best range" );<FONT 
color=#0000ff size=1>
AddColumn( <FONT face="Courier New" 
size=1>Buy, <FONT color=#ff00ff 
size=1>"buy<FONT 
color=#ff00ff size=1>" );<FONT color=#0000ff 
size=1>
AddColumn( <FONT face="Courier New" 
size=1>Sell, <FONT color=#ff00ff 
size=1>"sell<FONT 
color=#ff00ff size=1>" );
PositionSize = 2000<FONT 
size=1>;
//range.
xbestequity = 0;
xbestrange = 0;

// optimization loop<FONT 
size=1>

<FONT 
color=#800000 size=1>for( xrange = <FONT 
face="Courier New" color=#ff00ff size=1>5; xrange < 
17; xrange = (xrange + 
1) )
{

//----------------------------------------------------------------------------------------------------<FONT 
size=1>
// spot for second loop<FONT 
face="Courier New" size=1>
ybestequity = <FONT 
color=#ff00ff size=1>0<FONT 
face="Times New Roman">;
ybestrange = <FONT 
color=#ff00ff size=1>0;

// optimization loop<FONT 
size=1>

<FONT 
color=#800000 size=1>for( yrange = <FONT 
face="Courier New" color=#ff00ff size=1>4; yrange < 
19; yrange = (yrange + 
1) )
{

// 
---------------------------------------------------------------------------------------------<FONT 
size=1>
// spot for z score code<FONT 
face="Courier New" size=1>
<FONT 
size=1>ZScore=(Close-MA<FONT 
size=1>(Close,xrange))/<FONT color=#0000ff 
size=1>StDev(Close,yrange);<FONT color=#008000 
size=1>// 13 11
zLive = <FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4);
zsig = <FONT 
color=#0000ff size=1>MA(<FONT color=#0000ff 
size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>Cross(Zlive, 
zsig);
Sell<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>IIf(zlive < (zsig ), <FONT 
color=#ff00ff size=1>1, <FONT color=#ff00ff 
size=1>0);
 <FONT color=#008000 
size=1>
// 
---------------------------------------------------------------------------------------------<FONT 
size=1>
Le = <FONT 
color=#0000ff size=1>LastValue( <FONT color=#0000ff 
size=1>Equity() );

<FONT 
color=#800000 size=1>if( Le > ybestequity )
{
ybestequity = 
Le;
ybestrange = 
yrange;
}
}

yrange = 
ybestrange;
 
//----------------------------------------------------------------------------------------------------<FONT 
size=1>

<FONT 
size=1>ZScore=(Close-MA<FONT 
size=1>(Close,<FONT face="Courier New" 
size=1>xrange))/<FONT 
color=#0000ff size=1>StDev(Close,<FONT 
face="Courier New" size=1>yrange<FONT 
face="Times New Roman">);
zLive = <FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4);
zsig = <FONT 
color=#0000ff size=1>MA(<FONT color=#0000ff 
size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>Cross(Zlive, 
zsig);
Sell<FONT 
face="Times New Roman"> = <FONT 
color=#0000ff size=1>IIf(zlive < (zsig ), <FONT 
color=#ff00ff size=1>1, <FONT color=#ff00ff 
size=1>0);
Le = <FONT color=#0000ff 
size=1>LastValue( <FONT color=#0000ff 
size=1>Equity() );

if( Le > 
xbestequity )
{
xbestequity = Le;
xbestrange = xrange;
}
}

xrange = xbestrange;


ZScore=(Close-MA<FONT 
size=1>(Close,xrange<FONT 
size=1>))/StDev<FONT 
size=1>(Close,yrange<FONT 
size=1>);
zLive = MA<FONT 
size=1>(zscore,4);
zsig = MA(<FONT 
color=#0000ff size=1>MA(zscore,<FONT color=#ff00ff 
size=1>4), 3<FONT 
size=1>);
Buy = Cross(Zlive, 
zsig);
Sell = IIf(zlive 
< (zsig ), 1, 
0);
 
//Buy = 
ExRem(Buy, Sell);<FONT face="Courier New" color=#008000 
size=1>
//Sell = 
ExRem(Sell, Buy);

Filter = BarIndex<FONT 
size=1>() == BarCount - 1<FONT 
size=1>;


AddColumn( <FONT face="Courier New" 
size=1>xbestrange, <FONT color=#ff00ff 
size=1>"x<FONT 
color=#ff00ff size=1>Best range" );<FONT 
color=#0000ff size=1>
AddColumn( <FONT face="Courier New" 
size=1>ybestrange, <FONT color=#ff00ff 
size=1>"y<FONT 
color=#ff00ff size=1>Best range" );<FONT 
color=#0000ff size=1>
AddColumn( <FONT face="Courier New" 
size=1>Buy, <FONT color=#ff00ff 
size=1>"buy<FONT 
color=#ff00ff size=1>" );<FONT color=#0000ff 
size=1>
AddColumn( <FONT face="Courier New" 
size=1>Sell, <FONT color=#ff00ff 
size=1>"sell<FONT 
color=#ff00ff size=1>" 
);






Yahoo! Groups Sponsor


  ADVERTISEMENT









Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.