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 <[EMAIL PROTECTED]> 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 [email protected], "gp_sydney" <[EMAIL PROTECTED]> 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 [email protected], "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 > > > > >
