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

Re: [amibroker] Re: Bozo attack - How to limit trade entries per day in backtest..



PureBytes Links

Trading Reference Links

There are a number of ways to achieve this
One simple approach could be to use exrem

daystart = datenum()!=ref(datenum(),-1);
short = exrem(short,daystart);

-- 
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com


On 08/02/2008, marc.sterling <marc.sterling@xxxxxxxxx> wrote:
> GP, Thanks for your reply,  I was actually trying to stop a single symbol from trading more
> than once per day. I allow multple symbols to trade on a day.
>
> I have been trying to write, in AFL,  a flag that gets set as soon as a trade is taken by a
> symbol --
> then if the next minute bar is still in the same day and a flag shows a trade
> has been taken, the trade entry is canceled...
>
> I can never get it to work. here is my last try:
>
> Short   =       ((DaysSinceShortSetup == 1)     AND
>                 (TimeNum() >= EnterTadeTime)    AND
>                 (L <= MyShortPrice)             AND
>                 (TradedThisDay != True);
>
> TradedThisDay = Hold( IIf(Short,True,False), 450);
>
> I was trying to get the TradedThisDay flag to hold for a days worth of bars.
>
> I have tried several other ways to do this but I can't get the short logic to set a flag after a
> trade, then check this flag before it orders a trade.
>
> (Can you tell I am getting confused, this array processing has got me crazy).
>
> To stop the extra trades in the backtester, I would have to store each symbol that trades
> ,in an array that lasts for one day; then as it walks thru each minute and sees a new trade,
> it checks if that symbol has traded already... then I would need to empty that array at the
> begining of the next day.
>
> In Perl I know how to empty and array, here I am still confused... like I say, my mind is
> burried.
>
> It's a joy looking at your code... I learn a lot... any Idea?
>
> I know I am missing a n easy way
> of doing this.
>
> Thanks again,
>
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@xxx> wrote:
> >
> > Do you mean one trade a day per symbol, or one trade a day across all
> > symbols?
> >
> > If it's only per symbol, you could filter out all other trades in the
> > main AFL code. If it's across all symbols, then I think you'd have to
> > use the mid-level custom backtester, using a variable to track trades
> > each day.
> >
> > For example, in the custom backtester add something like:
> >
> > dn = DateNum();
> > newDay = dn != Ref(dn,-1);
> > hadTradeToday = False;
> >
> > Then in the loops:
> >
> > for (i = 0; i < BarCount; i++)
> > {
> >     if (newDay[i])
> >         hadTradeToday = False;
> >     for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
> >     {
> >         if (sig.IsEntry() && sig.IsLong())
> >         {
> >             if (hadTradeToday)
> >                 sig.PosSize = 0;
> >             else
> >                 hadTradeToday = True;
> >         }
> >     }
> >     bo.ProcessTradeSignals(i);
> > }
> >
> > This code (which is not a complete custom backtest procedure, and I
> > haven't tested) sets "hadTradeToday" on the very first entry of a day
> > and then sets the position size to zero for all subsequent entries on
> > the same day. The "hadTradeToday" flag is reset on the first bar of
> > each new day.
> >
> > The code as written also assumes there aren't any other reasons within
> > the custom backtester for a valid entry to be rejected, otherwise
> > "hadTradeToday" would need to be set only when the entry was
> > definitely being taken.
> >
> > Regards,
> > GP
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "marc.sterling" <marc.sterling@>
> > wrote:
> > >
> > > I have been having a bozo attack for five days - trying to code a
> > way to limit a trade entry to
> > > one per day on backtesting.
> > >
> > > I am running a back test on minute bars, I enter a trade when my
> > conditions are met... an
> > > hour os so later, the trade is stopped out as a loss when the trade
> > goes against me. The
> > > backtester then enters a second trade as the conditions are met again...
> > >
> > > I have been trying to code a way for it to enter no more than one
> > trade in a day - and getting
> > > nowhere... everything I try fails. (Serious Bozo attack)
> > >
> > > Does anybody have a simple approach to this problem. I am totally
> > locked out of solutions...
> > >
> > > Thanks
> > >
> >


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/