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

RE: [amibroker] Re: AmiBroker 4.60.1 BETA -Relative Performance Chart



PureBytes Links

Trading Reference Links




 
Hi, 
 
below I add simple STOP code embedded in a 
simple system (see PROGRAM 1). This code is for long trades only. Below this 
code I add the conventional AFL code for the same simple system (see PROGRAM 2) 
which should give the same result. For a backtest on a single 
symbol I get the same result. However a 
portfolio backtest using a list of symbols gives a 
different result.
 
Can someone explain how this works / why 
this is and how I would get the same result using my own stop code when 
doing a portfolio backtest instead of the ApplyStop code?
 
thnx, Ed
 
 
<FONT face="Courier New" color=#800000 
size=2> 
<FONT face="Courier New" color=#800000 
size=2>--------------------------------------------------------------------------------
PROGRAM 
1
<FONT face="Courier New" color=#800000 
size=2> 
<FONT 
color=#800000>procedure 
sell_at_close(Buy<FONT 
color=#000000>,BuyPrice<FONT 
color=#000000>,Open<FONT 
color=#000000>,High<FONT 
color=#000000>,Low<FONT 
color=#000000>,Close<FONT 
face="Courier New" color=#000000 size=2>,nbar) { <FONT 
face="Courier New" color=#008000 size=2>/* Jul 2004 
*/ 
global 
Sell<FONT 
face="Courier New">; <FONT 
color=#800000>global <FONT 
color=#000000>SellPrice<FONT 
face="Courier New">; <FONT 
color=#800000>global<FONT 
size=2> BuyAdjusted; <FONT 
color=#800000>global<FONT 
size=2> BuyPriceAdjusted; <FONT 
color=#008000>// initialise arrays<FONT 
face="Courier New"> <FONT 
color=#000000>SellPrice = <FONT 
color=#000000>BuyPrice; <FONT 
color=#000000>SellPrice = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; Sell<FONT 
color=#000000> = Buy<FONT 
color=#000000>; Sell<FONT 
color=#000000> = 0<FONT 
face="Courier New">; BuyAdjusted = 
Buy; BuyAdjusted = 
0<FONT 
size=2>; BuyPriceAdjusted = <FONT 
color=#000000>BuyPrice; BuyPriceAdjusted = 
0<FONT 
size=2>; <FONT 
color=#800000>for (i = <FONT 
color=#ff00ff>0; i < <FONT 
color=#000000>BarCount<FONT 
size=2>; i++) {    <FONT 
color=#008000>// <FONT 
face="Courier New" size=2>   <FONT 
face="Courier New">if<FONT 
color=#000000> (Buy<FONT 
color=#000000>[ i ] == 1<FONT 
face="Courier New">) {    
          <FONT 
color=#008000>// buy at open<FONT 
size=2>       BuyAdjusted[ 
i ] = 1<FONT 
face="Courier New">; 
      BuyPriceAdjusted[ i ] = <FONT 
color=#000000>Open<FONT 
size=2>[ i ];        
      // find a 
sell position + sellprice <FONT 
face="Courier New" 
size=2>      <FONT 
face="Courier New">for<FONT 
color=#000000> (j = i; j < <FONT 
color=#000000>BarCount<FONT 
size=2>; j++) {     
         <FONT 
color=#008000>// nbar stop exit at the open<FONT 
face="Courier New"> 
         <FONT 
color=#800000>if<FONT 
size=2> ((j - i) == nbar) { 
                   
            <FONT 
color=#000000>Sell[ j ] = <FONT 
color=#ff00ff>1<FONT 
color=#000000>; 
            <FONT 
color=#000000>SellPrice[ j ] = <FONT 
color=#000000>Close<FONT 
size=2>[ j ]; 
             
            <FONT 
color=#008000>// enter i-loop starting from the last 
sell<FONT 
color=#000000> 
            i = 
j; 
                
            <FONT 
color=#008000>// escape from loop<FONT 
face="Courier New"> 
            j = 
BarCount<FONT 
face="Courier New">; 
             
         } 
          
      } 
          } 
                
} } // end 
procedure<FONT 
color=#000000> // initial settings 
for portfolio trading (also see Settings window)<FONT 
face="Courier New"> <FONT 
color=#0000ff>SetBarsRequired(<FONT 
color=#ff00ff>10000,<FONT 
color=#ff00ff>10000<FONT 
size=2>); <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"MaxOpenPositions", <FONT 
color=#ff00ff>250<FONT 
size=2> ); <FONT 
color=#000000>PositionSize = -<FONT 
color=#ff00ff>15<FONT 
color=#000000>; SetTradeDelays<FONT 
color=#000000>(0<FONT 
color=#000000>,0<FONT 
color=#000000>,0<FONT 
color=#000000>,0<FONT 
face="Courier New">); <FONT 
color=#008000>// initial settings of the variables<FONT 
face="Courier New"> nb = <FONT 
color=#ff00ff>1<FONT 
color=#000000>; Buy<FONT 
color=#000000> = StochK<FONT 
color=#000000>(8) < 
10<FONT 
size=2>; // build in the 
trade delay<FONT 
color=#000000> Buy<FONT 
color=#000000> = Ref<FONT 
color=#000000>(Buy<FONT 
color=#000000>,-1<FONT 
face="Courier New">); <FONT 
color=#000000>BuyPrice = <FONT 
color=#000000>Open<FONT 
size=2>; // calculate 
sell positions <FONT 
face="Courier New" size=2>sell_at_close(<FONT 
face="Courier New">Buy<FONT 
color=#000000>,BuyPrice<FONT 
color=#000000>,Open<FONT 
color=#000000>,High<FONT 
color=#000000>,Low<FONT 
color=#000000>,Close<FONT 
face="Courier New">,nb); <FONT 
color=#000000>Buy<FONT 
size=2> = BuyAdjusted; <FONT 
color=#000000>BuyPrice<FONT 
size=2> = BuyPriceAdjusted; <FONT 
color=#0000ff>Plot(<FONT 
color=#000000>C,<FONT 
color=#ff00ff>"C",<FONT 
color=#ff00ff>1,<FONT 
color=#ff00ff>64<FONT 
color=#000000>); PlotShapes<FONT 
color=#000000>(shapeUpArrow<FONT 
color=#000000>*Buy<FONT 
color=#000000>,colorWhite<FONT 
color=#000000>, layer = 0, 
yposition = BuyPrice<FONT 
color=#000000>, offset = 0<FONT 
face="Courier New"> ); <FONT 
color=#0000ff>PlotShapes(<FONT 
color=#000000>shapeDownArrow*<FONT 
color=#000000>Sell,<FONT 
color=#000000>colorYellow, layer = 
0, yposition = 
SellPrice, offset = 
0<FONT 
size=2> ); <FONT 
color=#000000>Title=<FONT 
color=#0000ff>Name()+ ", 
O: "+WriteVal<FONT 
color=#000000>(O)+ 
", H: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>H)+ <FONT 
color=#ff00ff>", L: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>L)+ <FONT 
color=#ff00ff>", C: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>C<FONT 
size=2>); <FONT 
color=#000000>PositionScore = (<FONT 
color=#ff00ff>50-<FONT 
color=#0000ff>StochK(<FONT 
color=#ff00ff>8));
 
 

<FONT face="Courier New" color=#800000 
size=2> 
<FONT face="Courier New" color=#800000 
size=2> 
<FONT face="Courier New" color=#800000 
size=2>-------------------------------------------------------------------
PROGRAM 
2
<FONT face="Courier New" color=#800000 
size=2> 
/* */<FONT 
face="Courier New"> <FONT 
color=#008000>// initial settings for portfolio trading (also see Settings 
window)<FONT 
color=#000000> SetOption<FONT 
color=#000000>("MaxOpenPositions"<FONT 
color=#000000>, 250<FONT 
face="Courier New"> ); <FONT 
color=#000000>PositionSize = -<FONT 
color=#ff00ff>15<FONT 
color=#000000>; SetTradeDelays<FONT 
color=#000000>(1<FONT 
color=#000000>,1<FONT 
color=#000000>,1<FONT 
color=#000000>,1<FONT 
face="Courier New">); <FONT 
color=#008000>// initial settings of the variables<FONT 
face="Courier New"> nb = <FONT 
color=#ff00ff>1<FONT 
color=#000000>; Buy<FONT 
color=#000000> = StochK<FONT 
color=#000000>(8) < 
10<FONT 
size=2>; <FONT 
color=#000000>BuyPrice = <FONT 
color=#000000>O<FONT 
size=2>; <FONT 
color=#000000>Sell = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; ApplyStop<FONT 
color=#000000>(stopTypeNBar<FONT 
color=#000000>,stopModeBars<FONT 
color=#000000>,nb,ExitAtStop = 1<FONT 
color=#000000>,Volatile = False<FONT 
color=#000000>, ReentryDelay = <FONT 
color=#ff00ff>1<FONT 
color=#000000> ); SellPrice<FONT 
color=#000000> = C<FONT 
face="Courier New">; <FONT 
color=#0000ff>Equity(<FONT 
color=#ff00ff>1<FONT 
color=#000000>); // Output to the Chart 
window<FONT 
color=#000000> bplot = Ref<FONT 
color=#000000>(Buy<FONT 
color=#000000>,-1<FONT 
face="Courier New">); splot = <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>Sell,-<FONT 
color=#ff00ff>1<FONT 
color=#000000>); bplot = IIf<FONT 
color=#000000>(bplot != 0, 
1, <FONT 
color=#ff00ff>0<FONT 
color=#000000>); splot = IIf<FONT 
color=#000000>(splot != 0, 
1, <FONT 
color=#ff00ff>0<FONT 
color=#000000>); Plot<FONT 
color=#000000>(C<FONT 
color=#000000>,"C"<FONT 
color=#000000>,1<FONT 
color=#000000>,64<FONT 
face="Courier New">); <FONT 
color=#0000ff>PlotShapes(<FONT 
color=#000000>shapeUpArrow*bplot,<FONT 
color=#000000>colorWhite, layer = <FONT 
color=#ff00ff>0, yposition = <FONT 
color=#000000>BuyPrice, offset = <FONT 
color=#ff00ff>0<FONT 
color=#000000> ); PlotShapes<FONT 
color=#000000>(shapeDownArrow<FONT 
color=#000000>*splot,colorYellow<FONT 
color=#000000>, layer = 0, 
yposition = SellPrice<FONT 
color=#000000>, offset = 0<FONT 
face="Courier New"> ); <FONT 
color=#000000>Title=<FONT 
color=#0000ff>Name()+ ", 
O: "+WriteVal<FONT 
color=#000000>(O)+ 
", H: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>H)+ <FONT 
color=#ff00ff>", L: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>L)+ <FONT 
color=#ff00ff>", C: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>C<FONT 
face="Courier New">); <FONT 
color=#000000>PositionScore = (<FONT 
color=#ff00ff>50-<FONT 
color=#0000ff>StochK(<FONT 
color=#ff00ff>8)); 


Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












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 the Yahoo! Terms of Service.