Time filter in AFL backtesting

#1
Dear experienced Amibroker programmers,

I have a very simple strategy whose rules I have written in afl and used this afl to backtest my strategy and optimise it on various products.

But currently I am trying to test this strategy in international markets which are 24 hour in nature, like dow futures , crude oil and eur/usd etc.

But it is natural that no one is capable of sitting for trading throught these hours. So I want to sit to trade from 12:30 pm IST to 10:00 pm IST.

So I want to filter my entry and exits in these time period only. example If I get a signal before 12:30 then the backtester should not register this trade and list only those trades which get triggered after 12:30. and also square off the trades at close of candle at 10:00 pm.

Can anybody here tell me what lines I must add in my afl code to achieve this?

Thanx a lot in Advance. It will be of great help to me.

Regards,
A.......X
 
#3
post afl and time u want to trade.

will try
Hi there, thanks for taking intrst in this ... the code is realy simple.
// THis is the code

Range1 = Optimize("range1",25,15,45,5);
Buy = Cross (CCI(range1), -50);
Sell =Cross (-50, CCI(range1));
Short =Cross (50, CCI(range1));
Cover = Cross (CCI(range1), 50);


=================

The time I have already written , it is between 12:30 pm to 10:00 pm.

The open position should be squared off at the close of 10:00 pm candle close. And No trade should open before 12:30 pm and after 10:00 pm.
 
Last edited:
#4
Dear experienced Amibroker programmers,

I have a very simple strategy whose rules I have written in afl and used this afl to backtest my strategy and optimise it on various products.

But currently I am trying to test this strategy in international markets which are 24 hour in nature, like dow futures , crude oil and eur/usd etc.

But it is natural that no one is capable of sitting for trading throught these hours. So I want to sit to trade from 12:30 pm IST to 10:00 pm IST.

So I want to filter my entry and exits in these time period only. example If I get a signal before 12:30 then the backtester should not register this trade and list only those trades which get triggered after 12:30. and also square off the trades at close of candle at 10:00 pm.

Can anybody here tell me what lines I must add in my afl code to achieve this?

Thanx a lot in Advance. It will be of great help to me.

Regards,
A.......X

Plz suggest Who are the brokers in india offering 24hrs trading in these scripts?
 
#5
Plz suggest Who are the brokers in india offering 24hrs trading in these scripts?

There r many, but I think if i reveal their names here, they may get in trouble... also those who r legitimate dont except to open ur account unless u r opening an account using NRI bank account status.

Another way is that u ll have to get a job as a trader with one of them ... and they operate as a bpo to avoid getting in trouble.

Regards,
A.......X
 

mcxinvest

Well-Known Member
#6
Dear experienced Amibroker programmers,

I have a very simple strategy whose rules I have written in afl and used this afl to backtest my strategy and optimise it on various products.

But currently I am trying to test this strategy in international markets which are 24 hour in nature, like dow futures , crude oil and eur/usd etc.

But it is natural that no one is capable of sitting for trading throught these hours. So I want to sit to trade from 12:30 pm IST to 10:00 pm IST.

So I want to filter my entry and exits in these time period only. example If I get a signal before 12:30 then the backtester should not register this trade and list only those trades which get triggered after 12:30. and also square off the trades at close of candle at 10:00 pm.

Can anybody here tell me what lines I must add in my afl code to achieve this?

Thanx a lot in Advance. It will be of great help to me.

Regards,
A.......X
Check if you want this....in this from parameter you can select the time frame.
hope this solves your query.


TimeRange = ParamToggle("Time","No|Yes");
Starttime = Param("Starttime",100000,100000,235500,0);
Closetime = Param("Closetime",232000,100000,235500,0);

B1 = "Buy condition"

S1 = "Sell condition"

Sh1 = "Short Condition"

Co1 = "Cover Condition"


Buy = IIf(TimeRange==False,B1,B1 AND TimeNum() > Starttime AND TimeNum() < Closetime);
Sell = IIf(TimeRange==False,S1,S1 OR TimeNum() > Closetime );
Short = IIf(Timerange==False,Sh1,Sh1 AND TimeNum() > Starttime AND TimeNum() < Closetime);
Cover = IIf(Timerange==False,Co1,Co1 OR TimeNum() > Closetime );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);
 
#7
Check if you want this....in this from parameter you can select the time frame.
hope this solves your query.


TimeRange = ParamToggle("Time","No|Yes");
Starttime = Param("Starttime",100000,100000,235500,0);
Closetime = Param("Closetime",232000,100000,235500,0);
ExitToday = (Ref(DateNum(),1) > DateNum());

B1 = "Buy condition"

S1 = "Sell condition"

Sh1 = "Short Condition"

Co1 = "Cover Condition"


Buy = IIf(TimeRange==False,B1,B1 AND TimeNum() > Starttime AND TimeNum() < Closetime);
Sell = IIf(TimeRange==False,S1,S1 OR TimeNum() > Closetime OR ExitToday);
Short = IIf(Timerange==False,Sh1,Sh1 AND TimeNum() > Starttime AND TimeNum() < Closetime);
Cover = IIf(Timerange==False,Co1,Co1 OR TimeNum() > Closetime OR ExitToday);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);
Sir thanks for taking the time out to help me, i ll check it and let u know the results. currently not having access to my laptop, will reply asap.
 

mcxinvest

Well-Known Member
#8
Sir thanks for taking the time out to help me, i ll check it and let u know the results. currently not having access to my laptop, will reply asap.
Did you checked??

If you keep the timing off from parameter windo than it will trade normal way,
if you keep it on, specify the timings and it will trade within that timings.
 
#9
Did you checked??

If you keep the timing off from parameter windo than it will trade normal way,
if you keep it on, specify the timings and it will trade within that timings.
Yes my friend it works fine... JUst as I wanted it. Thank u very much.

In the code I have a doubt...

Starttime = Param("Starttime",100000,100000,235500,0);
Closetime = Param("Closetime",232000,100000,235500,0);
In the above line what do the 2 nd, 3rd, 4th and 5th parameters stand for? I know they r the time.. but r they max and min time? and what is 0 for?
 

pkgmtnl

Well-Known Member
#10
There r many, but I think if i reveal their names here, they may get in trouble... also those who r legitimate dont except to open ur account unless u r opening an account using NRI bank account status.

Another way is that u ll have to get a job as a trader with one of them ... and they operate as a bpo to avoid getting in trouble.

Regards,
A.......X
So, any1 having NRI or having relative aborad can open such an account.
PM me if possible.
bye
 

Similar threads