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

[amibroker] Re: how to modify MarginDeposit by trade ?



PureBytes Links

Trading Reference Links

FWIW, I've found that, once you're within CBT, VarSet is VERY 
flexible, because it allows you, for example, to pre-assign any 
specific arrays to symbols:

SetOption("UseCustomBacktestProc", True ); 

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

for (n=0; (sym=strextract(. .. .etc.)
{
VarSet("MyVar_"+sym,YourVar);

. . . etc.

Then, f.ex. in 

for (pos=GetFirstopenpos . . . .)

you call them:

Stock = pos.Symbol

MyVar = VarGet("MyVar_"+Stock);

Indeed, depending on where you call them / where you want to know the 
value (tradereport/BT-report), you may need to use TJ's / Graham's 
functions.

PS

--- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> wrote:
>
> How do you store the values?
> Normal variables do not pass directly from the base AFL to the CBT.
> You need to use either staticvarset or save them to a composite 
symbol
> and then read these as foreign symbols within the CBT. Of course you
> could always save them to a text file, but this would be slower than
> using compsoites
> Sorry I ahve not read through the CBT document fully that was 
created
> but you have to remember that the bars used in the loop in CBT is 
not
> that same barindex values as per the base symbols. The bars counted 
in
> the loops are based on the backtest bars. So reference to foreign
> symbols needs to be done using datetime values. Tomasz has written a
> function to allow easy referencing for this. This is slightly
> different to the original
> 
> function FindValueAtDateTime( eq, dt, Value )
> {
> 	found = -1;
> 	for( i=0; i<BarCount AND found==-1; i++ )
> 	{
> 		if( dt[i]==Value ) found = i;
> 	}
> 	return IIf( found != -1, eq[found], Null );
> }
> the function is located after SetCustomBacktestProc(""); and before
> if( Status("action") == actionPortfolio )
> ie
> SetCustomBacktestProc("");
> function FindValueAtDateTime( eq, dtm, Value )
> {
> 	found = -1;
> 	for( i=0; i<BarCount AND found==-1; i++ )
> 	{
> 		if( dtm[i]==Value ) found = i;
> 	}
> 	return IIf( found != -1, eq[found], Null );
> }
> if( Status("action") == actionPortfolio )
> {
> ...........................................................
> 
> In this Value is the datetime of the bar you want to reference the
> appropriate foreign symbol
> eq should be the Foreign function where your required data is stored
> 
> Here is an example that is within the open positions part inside 
the loop
> 
> dt = DateTime();
> for(bar=1; bar<BarCount; bar++)
> {
> for( OpenPos = bo.GetFirstOpenPos(); OpenPos; OpenPos = 
bo.GetNextOpenPos() )
> {
> SellStop[bar] = FindValueAtDateTime(
> Foreign("~Stops_"+OpenPos.Symbol,"O"), dt, dt[bar] );
> 
> 
> 
> 
> -- 
> Cheers
> Graham
> AB-Write >< Professional AFL Writing Service
> Yes, I write AFL code to your requirements
> http://www.aflwriting.com
> 
> 
> On 23/06/07, Grant Noble <gruntus@xxx> wrote:
> > Thx for the reply. I've read your wonderful docs on the CBT but 
am struggling with how to get the
> > CBT to use values calculated outside of it's loops. I store the 
correct margin value at the time I
> > generate my signals but, at CBT signal level I'm not actually 
dealing with a symbol/date paradigm am
> >   I ? Whenever I try to access my array I just get zero values. 
Any idea what I can do about this ? G
> >
> > gp_sydney wrote:
> > > I've never used MarginDeposit, but it is a property of the 
Signal
> > > object in the CBT which means it could be adjusted on a per-
trade
> > > basis using the mid-level custom backtester interface.
> > >
> > > GP
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, Grant Noble <gruntus@> wrote:
> > >> Anyone using MarginDeposit ??
> > >>
> > >> gruntusnomore wrote:
> > >>> I need to modify MarginDeposit on a trade-by-trade basis as 
it is
> > >>> calculated using order level & stop points.
> > >>> The backtester always uses the last value of MarginDeposit 
calculated
> > >>> for any test range - and will use this value for all trades 
of the
> > > same
> > >>> symbol.
> > >>> Can anyone advise how I can get around this ? Is it something 
that can
> > >>> be done w/ CBT additions ?
> > >>> Regards, GRANT
> > >>> :-)
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> Please note that this group is for discussion between users 
only.
> > >>>
> > >>> To get support from AmiBroker please send an e-mail directly 
to
> > >>> SUPPORT {at} amibroker.com
> > >>>
> > >>> For NEW RELEASE ANNOUNCEMENTS and other news always check 
DEVLOG:
> > >>> http://www.amibroker.com/devlog/
> > >>>
> > >>> For other support material please check also:
> > >>> http://www.amibroker.com/support.html
> > >>>
> > >>> Yahoo! Groups Links
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >
> > >
> > >
> > >
> > > Please note that this group is for discussion between users 
only.
> > >
> > > To get support from AmiBroker please send an e-mail directly to
> > > SUPPORT {at} amibroker.com
> > >
> > > For NEW RELEASE ANNOUNCEMENTS and other news always check 
DEVLOG:
> > > http://www.amibroker.com/devlog/
> > >
> > > For other support material please check also:
> > > http://www.amibroker.com/support.html
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> >
> >
> > Please note that this group is for discussion between users only.
> >
> > To get support from AmiBroker please send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/