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

Re: [amibroker] Moving average convergence coding



PureBytes Links

Trading Reference Links




Hello,
 
If you read ~~~EQUITY during portfolio backtest it won't 
give you current portfolio equity
because it is not known at this point. This (and possible 
workarounds) were discussed in detail on
amibroker-beta list
<A 
href="">http://www.egroups.com/messages/amibroker-beta/
 
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Paul Ho 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Tuesday, January 27, 2004 4:04 
  AM
  Subject: RE: [amibroker] Re: Backtest 
  using equity curve
  
  <SPAN 
  class=633555202-27012004>thank you I got that one. What I really want to do: 
  
  once 
  my portfolio has dropped below a predefined percentage, say 5%, I would like 
  to sell the stock with the most drawdown, not sure how that can be 
  done?
  For 
  starter
  <SPAN 
  class=633555202-27012004>---------------
  <SPAN 
  class=633555202-27012004>buy=cross(macd(),signal());
  <SPAN 
  class=633555202-27012004>sell=cross(signal(),macd());
  <SPAN 
  class=633555202-27012004>buy=exrem(buy,sell); 
  sell=exrem(sell,buy);
  <SPAN 
  class=633555202-27012004>positionscore=random();
  <SPAN 
  class=633555202-27012004>eq=Foreign<FONT 
  color=#000000 size=2>(<FONT color=#ff00ff 
  size=2>"~~~EQUITY", <FONT 
  color=#ff00ff size=2>"C"<FONT 
  face="Times New Roman" color=#000000>);dr=(<FONT 
  face="Times New Roman">eq - <FONT color=#0000ff 
  size=2>Highest<FONT color=#000000 
  size=2>(eq))/highest(eq);
  sell=iif(dr<-0.05,"choose 
  the stock with the highest drawdown",sell);
  <SPAN 
  class=633555202-27012004>-------------------------------------------
  Firstly, Can I use the 
  ~~equity composite dynamically as it is written and rewritten, (I cant see why 
  i cant i am just reading it).
  Secondly, is it possilbe the 
  find out which stock in the portfolio has the highest drawdown at the 
  time?
   
  Thanks for your 
  help.
  /Paul.
  
    
    <FONT 
    face=Tahoma size=2>-----Original Message-----From: Tomasz 
    Janeczko [mailto:amibroker@xxxxxx] Sent: Tuesday, 27 January 2004 
    2:17 AMTo: amibroker@xxxxxxxxxxxxxxxSubject: Re: 
    [amibroker] Re: Backtest using equity curve
    Hello,
     
    One correction. Portfolio equity is definitelly NOT the 
    sum of individual backtest equities in general case.
    This is so because in portfolio mode some trades can be 
    dropped due to insufficient funds.
     
    Best regards,Tomasz Janeczkoamibroker.com
    <BLOCKQUOTE 
    >
      ----- Original Message ----- 
      <DIV 
      >From: 
      Herman 
      vandenBergen 
      To: <A 
      title=amibroker@xxxxxxxxxxxxxxx 
      href="">amibroker@xxxxxxxxxxxxxxx 
      
      Sent: Monday, January 26, 2004 2:16 
      PM
      Subject: RE: [amibroker] Re: Backtest 
      using equity curve
      
      <FONT face=Arial color=#0000ff 
      size=2>A single Backtest of a single stock's equity is 
      Equity(0) or Equity(1), see Help for more on the 0 and 1 
      arguments.
      <FONT face=Arial color=#0000ff 
      size=2>If you Backtest a series of stocks the equity() will take on a 
      different value for each new stock that is processed. These equities can 
      be summed using an AddToComposite(). This is more or less what happens 
      when you use the portfolio tester and you can access the final portfolio 
      equities using Foreign(), like with this code (originating from TJ I 
      think) that shows how to retrieve the Portfolio Equity. The "~~~EQUITY" 
      composite is created by the portfolio 
      backtest:
      // TJ's Equity 
      Plotseq = Foreign<FONT 
      size=2>("~~~EQUITY", 
      "C");cash = 
      Foreign(<FONT 
      color=#ff00ff size=2>"~~~EQUITY", <FONT 
      color=#ff00ff size=2>"L");dr = eq - <FONT 
      color=#0000ff size=2>Highest(eq);bslh = 
      HighestBars<FONT 
      size=2>(eq);GraphZOrder=<FONT color=#ff0000 
      size=2>1;<FONT color=#0000ff 
      size=2>Plot(eq, <FONT color=#ff00ff 
      size=2>"Portfolio Equity", colorBlue, styleLine 
      );<FONT face="Microsoft Sans Serif" color=#008000 
      size=2>//Plot(cash, "Cash", colorGreen, 
      styleArea );Plot<FONT 
      size=2>(dr, "Drawdown"<FONT 
      size=2>, colorDarkRed, styleArea );<FONT color=#0000ff 
      size=2>Plot( <FONT color=#0000ff 
      size=2>Foreign(<FONT color=#ff00ff 
      size=2>"~~~EQUITY", <FONT color=#ff00ff 
      size=2>"O"), "Long 
      only", colorGreen );<FONT color=#0000ff 
      size=2>Plot( <FONT color=#0000ff 
      size=2>Foreign(<FONT color=#ff00ff 
      size=2>"~~~EQUITY", <FONT color=#ff00ff 
      size=2>"H"), "Short 
      only", colorRed );<FONT 
      face="Microsoft Sans Serif" color=#008000 size=2>//<FONT 
      color=#008000 size=2>Plot(bslh, "#bars since last high", colorDarkYellow, 
      styleLine | styleOwnScale, 0, 10 * LastValue( Highest( bslh ) ) 
      );islastbar = <FONT color=#0000ff 
      size=2>Status(<FONT color=#ff00ff 
      size=2>"lastbarintest");isfirstbar = <FONT 
      color=#0000ff size=2>Status(<FONT color=#ff00ff 
      size=2>"firstbarintest");bar = <FONT 
      color=#0000ff size=2>BarIndex();firstbar = 
      LastValue( 
      ValueWhen( 
      isfirstbar, bar ) );lastbar = <FONT color=#0000ff 
      size=2>LastValue( <FONT color=#0000ff 
      size=2>ValueWhen( islastbar, bar ) );al = 
      LastValue( 
      ValueWhen( 
      islastbar, LinRegSlope<FONT 
      size=2>( eq, Lastbar - firstbar ) ) );bl = <FONT color=#0000ff 
      size=2>LastValue( <FONT color=#0000ff 
      size=2>ValueWhen( islastbar, <FONT 
      color=#0000ff size=2>LinRegIntercept( eq, Lastbar - 
      firstbar ) ) );Lr = al * ( <FONT color=#0000ff 
      size=2>BarIndex() - firstbar ) + bl;Lr = 
      IIf( bar >= 
      firstbar AND bar <= lastbar , Lr, Null );<FONT 
      face="Microsoft Sans Serif" color=#008000 size=2>//<FONT 
      color=#008000 size=2>Plot( Lr , "Linear Reg", colorRed, styleThick 
      );
      
        <FONT face=Tahoma 
        size=2>-----Original Message-----From: paultsho 
        [mailto:paultsho@xxxxxxxxxxxx]Sent: January 26, 2004 6:14 
        PMTo: amibroker@xxxxxxxxxxxxxxxSubject: 
        [amibroker] Re: Backtest using equity curveI've 
        seen many clever use of equityMy question in regard to the system 
        below is Is E1 the equity of just one stock, or the whole portfolio 
        in backtesting. and if I want to use the equity curve of the whole 
        portfolio, do i have to use the addtocomposite function instead of 
        E1=equity(1);thanks in advance./Paul.--- In 
        amibroker@xxxxxxxxxxxxxxx, "Herman vandenBergen" <psytek@xxxx> 
        wrote:> You can cascade as many systems as you like, even 
        different ones, and use> the Equity from the previous one as 
        a parameter in the next system. I know> this can be done with 
        the old backtester and think it should also work in> the new 
        PF tester.> > // system one code here> E1 = 
        Equity(1);> > // System two code here> Buy = Buy 
        and (some function of E1);> E2 = Equity(1);> > // 
        System three code here> Buy = Buy and (some function of 
        E2);> E3 = Equity(1);> etc.> > You 
        essentially redefine the buy signal as often as needed (afl 
        executes> line after line and never looks back), the last 
        definition will be what> determines your results.> 
        > Herman> >   -----Original 
        Message----->   From: Glenn 
        [mailto:glennokb@xxxx]>   Sent: November 12, 2003 1:35 
        PM>   To: amibroker@xxxxxxxxxxxxxxx>   
        Subject: [amibroker] Backtest using equity curve> > 
        >   Hi,> >   I'm was wondering 
        if it is possible in AB to incorporate the equity 
        curve>   of a system within a backtest, using it to 
        test the following:> >   a. No new entries if a 
        closed trade crosses below a moving average of>   
        the equity curve and re-enter when a closed trade crosses above 
        the>   moving average. Another idea is to use a 
        percentage on the equity curve>   instead of a 
        moving average.> >   b. Using the above also 
        test tightening the actual trailing stop on the>   
        open trades. ie: if a closed trade crosses below a moving average 
        (or>   whatever) then instead of using a 3 x ATR stop 
        then use a 2 x ATR stop>   on the open 
        trades.> >   Note that the trades in between the 
        exit and entry need to be tracked for>   the 
        re-entry.> >   If this is possible, do you know 
        how to set it up please?> >   Cheers, 
        Glenn> > 
        >         Yahoo! Groups 
        Sponsor>               
        ADVERTISEMENT> > > > >   
        Send BUG REPORTS to bugs@xxxx>   Send SUGGESTIONS to 
        suggest@xxxx>   
        ----------------------------------------->   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 Yahoo! 
        Terms of Service.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 
        
        
        Yahoo! Groups Links
        
          To visit your group on the web, go to:<A 
          href="">http://groups.yahoo.com/group/amibroker/  

          To unsubscribe from this group, send an email to:<A 
          href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  

          Your use of Yahoo! Groups is subject to the <A 
          href="">Yahoo! Terms of Service. 
          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 
      
      
      Yahoo! Groups Links
      
        To visit your group on the web, go to:<A 
        href="">http://groups.yahoo.com/group/amibroker/  

        To unsubscribe from this group, send an email to:<A 
        href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  

        Your use of Yahoo! Groups is subject to the <A 
        href="">Yahoo! Terms of Service. 
        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 
    
    
    Yahoo! Groups Links
    
      To visit your group on the web, go to:<A 
      href="">http://groups.yahoo.com/group/amibroker/  

      To unsubscribe from this group, send an email to:<A 
      href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  

      Your use of Yahoo! Groups is subject to the <A 
      href="">Yahoo! Terms of Service. 
    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 
  
  
  Yahoo! Groups Links
  
    To visit your group on the web, go to:<A 
    href="">http://groups.yahoo.com/group/amibroker/  

    To unsubscribe from this group, send an email to:<A 
    href="">amibroker-unsubscribe@xxxxxxxxxxxxxxx  

    Your use of Yahoo! Groups is subject to the <A 
    href="">Yahoo! Terms of Service. 
  


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





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.