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

Re: [amibroker] Scaling In Question



PureBytes Links

Trading Reference Links


hi,

A post from TJ that could help you. Best regards


separate exits using pyramiding

You could do separate exits using pyramiding code but you would need to 
write a loop
and track which entry matches which exit and set sizes accordingly.

For this particular application, I think that custom backtester is 
better suited and leads to simpler and
shorter code and actual code would look as follows:


Sell=Short=Cover=0; // real rules are defined inside custom backtest proc

Buy = IIf( Close > Open, sigScaleIn, 0 ); // entry rule

SetCustomBacktestProc(""); // enable custom backtest

if( Status("action") == actionPortfolio )
{
   // actual backtest routine
   // (low-level)

   bo = GetBacktesterObject();

  // actual backtest loop
   bo.PreProcess();

   for( i = 0; i < BarCount; i++ )
   {
      // first update backtest stats and handle stops
       bo.UpdateStats( i, 0 );
       bo.HandleStops( i );
      
       _TRACE("Bar " + i );
       for( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) )
       {
         if( sig.IsEntry() OR sig.IsScale() )
         {
          _TRACE("ENTER " + sig.Symbol );
          bo.EnterTrade( i, sig.Symbol, True, sig.Price, 5000 /* $5000 
into one trade */);
         }
       }  

      
      for( OpenPos = bo.GetFirstOpenPos(); OpenPos; OpenPos = 
bo.GetNextOpenPos() )
      {
         // exit positions if their age is > 5 bars and they are profitable
         if( OpenPos.BarsInTrade >= 10 )
         {
             // EXIT WHEN POSITION IS 10 bars old
             _TRACE("EXIT " + OpenPos.Symbol );
             bo.ExitTrade( i, OpenPos.Handle, OpenPos.GetPrice( i, "O" ) );
          }
      }

       bo.UpdateStats( i, 2 );
   }
      
   bo.PostProcess();
}


_TRACEs lines are just for extra debuggin info. You may remove them to 
get more speed.


Tomasz Janeczko





John Bishop a écrit :
> 
> 
> Hi,
> 
> I am trying to write a trading system that scales into buys and sells by 
> using one rule for the initial buy, and then further scales into the 
> position if the C of the current bar is < the last buy price.
> 
> I get how to scale in using one rule but I'm having trouble figuring out 
> how to tell Amibroker to use one rule for the initial buy and then 
> another rule (C < Last BuyPrice) to determine whether to scale in.
> 
> Thank you very much for your help,
> 
> John
> 
> 




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/