Rebalacing + Rotational Strategy

EnableRotationalTrading(); 

EachPosPercent = 5; 

PositionScore = ROC( C, 20 ); 

PositionSize = -EachPosPercent; 

SetOption("WorstRankHeld", 40 );
SetOption("MaxOpenPositions", 20 ); 

SetOption("UseCustomBacktestProc", True ); 

if( Status("action") == actionPortfolio )
{
  bo = GetBacktesterObject();

  bo.PreProcess(); // Initialize backtester

  for(bar=0; bar < BarCount; bar++)
  {
   bo.ProcessTradeSignals( bar );
  
   CurEquity = bo.Equity;
  
   for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
   {
    posval = pos.GetPositionValue();
   
    diff = posval - 0.01 * EachPosPercent * CurEquity;
    price = pos.GetPrice( bar, "C" );
   
    // rebalance only if difference between desired and
    // current position value is greater than 0.5% of equity
    // and greater than price of single share
    if( diff != 0 AND
        abs( diff ) > 0.005 * CurEquity AND
        abs( diff ) > price )
    {
     bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, abs( diff ) );
    }
   }
  }
  bo.PostProcess(); // Finalize backtester

I get the code from AmiBroker Knowledge Base » Re-balancing open positions

I want to test this strategy on my watch list for last 10 years, but it gives me error
Please help me to remove the error
ERROR

@Siraj, in the posted article, unfortunately, there is a missing closing brace.
Just add it below the code.

   // above code
}

This is the kind of error that you can identify easily using the "Prettify Selection" option of the formula editor (applying it to the entire formula, without any text selection), as further explained in point 5 of this must-read topic..

In this case it doesn't matter, but in general, please don't post screenshots of "code": provide us with the actual code!

1 Like

Thank u so much and that works, though its a loss making strategy

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.