How do i keep entry parameters valid each day for the next week?

I have a system i'm trying to code and run on daily bars.
The setup and limit entry price is calculated on an end of week basis, with the setup condition and limit entry being valid for each trading day of the next week. I'm doing this by setting the periodicity to daily bars in Amibroker, and in the code changing the timeframe to weekly, calculating the setup condition and limit entry price before restoring the timeframe to daily bars then using TimeFrameExpand to convert the setup condition and limit entry for use with daily bars over the next week. So far, so good.

My question is how do i hold the limit entry valid for each trading day of the next week regardless of how many trading days there are in the next week? Any ideas are much appreciated.

Based on your written description, you should already be there. Since it's obviously not working the way you want, something must be wrong with your code, but you haven't posted that, so there's really no way for anyone here to help you.

1 Like

Good point. Code is below:

//amibroker is set to use daily bars as i want the trading to be done on a daily basis

//do this section on an end of week basis

BuyLim = c - ma(H,7) ; 
Tick = IIf(L<0.10,0.001,IIf(L<2.00,0.005,0.01)); 
BuyLimVal = round(BuyLim/Tick); 
BuyLimitPrice = BuyLimVal * Tick; 

Cond1 = C > MA(C,20);  
Cond2 =  C < EMA(H,35);
BuySetUp = Cond1 AND Cond2 ;

//back to the daily bars.

BuyLimitPrice = TimeFrameExpand(BuyLimitPrice, inWeekly);
BuySetUp = TimeFrameExpand(BuySetUp, inWeekly);

//hold the setup values for the trading week - assuming it is 5 days.  If it is less than that, i'll worry about it in the next version

BuyLimitPrice = hold(BuyLimitPrice, 5);
BuySetUp = hold(BuySetUp, 5);
Filter = 1;
AddColumn(BuySetUp, "buy setup", 1.0);

Buy = BuySetUp AND L < BuyLimitPrice;
BuyPrice = Min(Open,Ref(BuyLimitPrice,-1)); 
Sell = DayOfWeek() ==5; //Exit on Friday - this assumes last trading day is Friday.  If it is not the case, i'll deal with it later
SellPrice = Close; 

Short = Cover = False; 

I have also discovered that if an entry occurs on a Friday, it doesn't exit until next Friday. This is a mistake as in the Trades tab of the Backtester Settings i have set the sell prices to close and the delays to 0. Any ideas how i remedy this are much appreciated please.

In the code you posted, you don't need to use the Hold function. Take a look at the documentation for TimeFrameExpand using ExpandLast, which is the default expansion mode.

If you want exits to be valid on the entry day, then you can select the "Allow same bar exit" option in the Analysis Settings window, or set it with the SetOption command.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.