Note: forwarded message attached.
       
---------------------------------
Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.
--- Begin Message ---
Hello,


How can you access AFL function values that work on price arrays in a
low level backtest??

I am attempting to handle multiple signals using Custom Backtester.
In version 4.76.0 Tomasz introduced the "Handle" property.

In this simple example I want to use "Handle" to exit if share has
dropped 2xATR(30) from BuyPrice.
(note: 2xATR(30) is calculated on the 'Buy' day)

The middle line of code is obviously incorrect, but HOW should it be
written?

for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() ) 
{
  if(pos.GetPrice(bar,"C") < pos.GetEntryValue() -
2*ATR(30).[bar-pos.BarsInTrade])
        bo.ExitTrade(......);
}


Any ideas on how this can be done would be appreciated.


Complete code is listed below:


/* Backtest is carried out on multiple symbols*/

Buy = Cross(C,Ref(HHV(H,20),-1);
BuyPrice = Open;
Sell = 0;
SellPrice = 0;

if( Status("action") == actionPortfolio )
{
   // actual backtest routine(low-level)
   bo = GetBacktesterObject();
   bo.PreProcess();
        
   for( i = 1; i < BarCount; i++ )
   {
      // first update backtest stats and handle stops
      bo.UpdateStats( i, 0 );
                      
      for( sig = bo.GetFirstSignal(i);sig; sig = bo.GetNextSignal(i) )
      {
        if (sig.IsLong() AND sig.Price != -1)
        {
          bo.RawTextOutput("Bar " + i + " Symbol: " + sig.Symbol);
          bo.EnterTrade(i, sig.Symbol, True, sig.Price,-10);
          for(pos=bo.GetFirstOpenPos();pos;pos = bo.GetNextOpenPos() ) 
          {
             bo.RawTextOutput("Open Pos Found For: " + pos.Symbol);
             /* --- Now Process Exit ---*/
             /* --- This won't work  ---*/
             /* --- Have we closed 2xATR(30) below entry price? */
             if(pos.GetPrice(i,"C") < pos.GetEntryValue() -
2*ATR(30).[i-pos.BarsInTrade])
             bo.ExitTrade( i+1, OpenPos.Handle, OpenPos.GetPrice( i+1, "O" ) );
        
          }             

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



--- End Message ---

Reply via email to