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

RE: [amibroker] Re: Help Limiting number of positions added per day



PureBytes Links

Trading Reference Links



Since you have not posted your code I can not debug it for you but the following code works for me:

 

MaxBuys = 5;
SetBacktestMode( backtestRegularRaw2 );
SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
   bo =
GetBacktesterObject();
   bo.PreProcess();
   
for ( i = 0; i < BarCount; i++ )
   {
      cntBuys =
0;
      
for ( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
      {
         
if ( sig.IsEntry() )
         {
            
// this handles limiting of number of order per day
            CanEnter = False;
            
if ( CntBuys <= MaxBuys )
            {
               bo.EnterTrade( i, sig.Symbol, True, sig.Price, sig.PosSize, sig.PosScore, RoundLotSize =
1);
               CanEnter = True;
               CntBuys++;
            }
            
if ( ! CanEnter ) sig.Price = -1;
         }
        }
   bo.ProcessTradeSignals( i );
   }
   bo.PostProcess();
}

 

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of woodshedder_blogspot
Sent: Saturday, September 26, 2009 3:52 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Help Limiting number of positions added per day

 

 

TA, thanks for the help.
I'm having a problem with this line:
bo.PostProcess();

This is the error I'm getting: "Error 18 COM object variable is not initialized or has invalid type (valid COM object handle required)

Wood

--- In amibroker@xxxxxxxxxxxxxxx, "ta" <tagroups@xxx> wrote:
>
> You need to use Custom Backtester as follows:
>
>
>
> MaxBuys = 5;
>
> SetBacktestMode( backtestRegularRaw2 );
>
> SetCustomBacktestProc("");
>
> if ( Status( "action" ) == actionPortfolio )
>
> {
>
> bo = GetBacktesterObject();
>
> bo.PreProcess();
>
>
>
> for ( sig = bo.GetFirstSignal( i ); sig; sig =
> bo.GetNextSignal( i ) )
>
> {
>
> if ( sig.IsEntry() )
>
> {
>
> // this handles limiting of number of order
> per day
>
> CanEnter = False;
>
> if ( CntBuys <= MaxBuys )
>
> {
>
>
> bo.EnterTrade( i, sig.Symbol, True, sig.Price, sig.PosSize, sig.PosScore,
> RoundLotSize = 1);
>
> CanEnter =
> True;
>
> CntBuys++;
>
> }
>
>
>
> if ( ! CanEnter )
>
> sig.Price =
> -1;
>
> }
>
> }
>
> bo.ProcessTradeSignals( i );
>
> }
>
> bo.PostProcess();
>
> }
>
>
>
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
> Of woodshedder_blogspot
> Sent: Thursday, September 24, 2009 8:25 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Help Limiting number of positions added per day
>
>
>
>
>
> Greetings group.
>
> I want to limit the number of positions a system will take on any given day.
>
>
> For example, if a system can handle 20 max positions, I would like it to
> only take on 5 new positions a day (assuming there are more than 5 valid
> signals per day) until it arrives at 20 positions, rather than taking on all
> available positions on day 1.
>
> Thanks for your help.
>



__._,_.___


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





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

JPEG image

JPEG image