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

[amibroker] Counting ALL entries. Hi Mark H. could u pls read.



PureBytes Links

Trading Reference Links

Hello, Mark H.,

below is the code you referred me to for Counting all Entry signals on
backtester, even on existing open positions.
I got it to work for my purposes, but I'm stuck.

I'm trying to Enter on the open (1 day delay), while exiting on the
close after X days.

I just can't get it to enter on open while exiting on close. I don't
know what code to write for these.

I tried setting it in trade settings page, but when I set Entry to
Open price, the Exit exit's on Open price too, even though it's set on
Close price.

I've spent ages trying to work this out, if anyone could give some
help i'd be very grateful.


---Below is coding u reffered me to... i used almost same code--

EnableRotationalTrading();
SetOption("WorstRankHeld",160); // this number needs to be big enough.
Only 2*WorstRankHeld signals will be held by CBT each bar.
SetOption("MaxOpenPositions", 100);
SetOption("InitialEquity", 30000);
SetOption("CommissionMode", 1); //% per trade
SetOption("CommissionAmount", 0.5);
SetOption("MarginRequirement", 50);
SetOption("UsePrevBarEquityForPosSizing", True);
SetOption("MinShares", 100);

SetTradeDelays( 1, 1, 1, 1 );
RoundLotSize = 5;

......

ApplyStop( stopTypeNBar, stopModeBars, 10);

Sell0 = ...; // Rename sell/buy to sell0/buy0 since you can have
sell/buy in rotational mode.
Buy0 = ...;
Sell0[0] = 1; // trick to remove leading sell signals
Sell0 = ExRem( Sell0, Buy0 );
Sell0[0] = 0;

RawScore = 100 + ......; // make sure it is greater than 2
PositionScore = 1;
for(i = 0; i < BarCount; i++)
{
        if(Buy0[i]) PositionScore[i] = RawScore[i];
        else if(Sell0[i]) PositionScore[i] = 2;
        else PositionScore[i] = C[i]/H[i]; //semi-random
}

SetOption("UseCustomBacktestProc", True );

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

   bo.PreProcess(); // Initialize backtester

   for(bar=0; bar < BarCount; bar++)
   {
                bo.HandleStops(bar-1); // if use bar not bar-1, the
n-bar exits have one extra bar delay. don't know why.
       for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) )
       {    
           // first handle exit signals  (PosScore = 2)
               if ((sig.PosScore == 2 OR sig.isExit()) AND sig.Price
!= -1 )
          {
               bo.ExitTrade(bar,sig.symbol,sig.Price);
          }
       }

        // update stats after closing trades
             bo.UpdateStats(bar, 1 );
      
             for ( sig=bo.GetFirstSignal(bar); sig;
sig=bo.GetNextSignal(bar))
             {
          // Entry Signals (PosScore > 2)
          // Only one position per symbol
            if (sig.PosScore > 2 AND sig.Price != -1 AND IsNull(
bo.FindOpenPos( sig.Symbol )))
             { 
                         // long only
              bo.EnterTrade(bar, sig.symbol, True, sig.Price,
sig.PosSize, sig.PosScore,sig.RoundLotSize);
                    } 
            }

             bo.UpdateStats(bar,1); // MAE/MFE is updated when
timeinbar is set to 1.
             bo.UpdateStats(bar,2);  
   }
   bo.PostProcess(); // Finalize backtester
}



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006