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

[amibroker] Rebalancing dynamic weights



PureBytes Links

Trading Reference Links

Hi,

Please help with this :

EnableRotationalTrading();

weight = 10; // default weight 

if( Name() == "" ) weight = 15;
if( Name() == "" ) weight = 15;
if( Name() == "" ) weight = 70;


AddToComposite(  weight * 
Close ,  "~TickerWithWeights", "X",atcFlagEnableInPortfolio|atcFlagDe
faults|atcFlagResetValues|atcFlagEnableInBacktest);
PositionSize=-weight;PositionScore =1;

//Plot ( Foreign("~TickerWithWeights", "X"), "weight", 
colorBrown,styleHistogram);

SetOption("UseCustomBacktestProc", True ); 


if( Status("action") == actionPortfolio )
{
  bo = GetBacktesterObject();
 
  bo.PreProcess(); 
 
  for(bar=0; bar < BarCount; bar++)
  {
   bo.ProcessTradeSignals( bar );
  
   CurEquity = bo.Equity;
	bo.RawTextOutput("Current Equity: " + bo.Equity());

	  
   for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
   {
    posval = pos.GetPositionValue();

     
	diff = posval - Foreign("~TickerWithWeights", "C") * 
CurEquity;
	bo.RawTextOutput(pos.Symbol+" : "+ pos.GetPositionValue() 
+ " diff: "+ diff );

	 
    price = pos.GetPrice( bar, "O" );
   
   
 
   if( diff != 0 AND
        abs( diff ) > 0.005 * CurEquity AND
        abs( diff ) > price )
    {
		bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, abs
( diff ) );
		bo.RawTextOutput("Number of open positions: " + 
bo.GetOpenPosQty() );

    }

   }
  }
  bo.PostProcess(); 
}

Thanks.



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/579 - Release Date: 12/7/2006 1:31 PM