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

Re: [amibroker] Nested Optimizing Loops



PureBytes Links

Trading Reference Links




Hi Lou,
 
Just guessing here, I have not really tried to 
understand your system, but...I dont think you want to keep track of 2 different 
equities, x and y. I made some quick changes, see if this is what you were 
trying to do...
 
Steve
 
<FONT face=Arial 
size=2>***************************************
 
PositionSize = 2000;
 
//range.bestequity = 0;xbestrange = 
0;ybestrange = 0;
 
// optimization loopfor( xrange = 5; xrange 
< 17; xrange = (xrange + 1) ){ // optimization 
loop for( yrange = 4; yrange < 19; yrange = (yrange + 1) 
) {  // spot for z score 
code  ZScore=(Close-MA(Close,xrange))/StDev(Close,yrange);// 13 
11  zLive = MA(zscore,4);  zsig = MA(MA(zscore,4), 
3);
 
  Buy = Cross(Zlive, 
zsig);  Sell = IIf(zlive < (zsig ), 1, 0);
 
  Le = LastValue( Equity() 
);  if( Le > bestequity 
)  {   bestequity = 
Le;   xbestrange = xrange;   ybestrange = 
yrange;  } }}
 
Filter = BarIndex() == BarCount - 1;AddColumn( 
xbestrange, "xBest range" );AddColumn( ybestrange, "yBest range" 
);AddColumn( Buy, "buy" );AddColumn( Sell, "sell" );PositionSize = 
2000;
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Lou 
  H 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">AMI Group 
  Sent: Sunday, October 05, 2003 9:38 
  AM
  Subject: [amibroker] Nested Optimizing 
  Loops
  
  I'm having trouble getting these loops to work 
  properly.  Can anyone point out the error(s)?
   
  Thanks
  lou
  <FONT 
size=2>------------------------------------------------
   
  
  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<FONT 
  size=1>
  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 = 
  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<FONT 
  size=1>(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 
  size=1>(MA<FONT 
  size=1>(zscore,4), 
  3);
  Buy = Cross<FONT 
  size=1>(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<FONT 
  size=1>
  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 = 
  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<FONT 
  size=1>(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 
  size=1>(MA<FONT 
  size=1>(zscore,4), 
  3);
  Buy = Cross<FONT 
  size=1>(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>" );Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 







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.