STARTING FROM SCRATCH IN BACKTESTING

Questions and discussion of Trading Blox and other platforms for non Trading Blox customers. Trading Blox customers should use the Trading Blox Support forum.
Post Reply
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

STARTING FROM SCRATCH IN BACKTESTING

Post by BARLI » Fri Sep 30, 2005 9:46 pm

hi all,

i been trading discretionary, but recently got some ideas i'd love to test using TRADING BLOX BUILDER 2.0.6

i am totally confused on how am i writting a script and making the blox. i tried doing it but the results didnt come up... can anyone help me do that?
i just wanna catch the basics of the programming the system using software.
for instance:

i want to buy (enter) a commodity(stock) on monday and sell (exit) on wednesday. no stops.

how am i programming this simple example into a trading blox builder, what am i to do with blocks:parameters, indicators?

thanks in advance

TrendMonkey
Roundtable Knight
Roundtable Knight
Posts: 154
Joined: Fri Apr 22, 2005 9:14 pm
Location: Vancouver, Canada

Post by TrendMonkey » Sat Oct 01, 2005 9:16 am

I just started experimenting with it so I am nowhere near qualified to respond, but I'll give it a shot anyway.

For such an incredibly simple system I dont believe you need ANY parameters or indicators.

Parameters would be required if you wanted to test different permutations of days - eg. Mon/Wed, Tue/Thur and so on. If you are content to fix (hardcode) it as M/W, you dont need parameters.

Similarly indicators are for calculated data such as a moving average. If you are just going off days of week, you dont need to manipulate the price data a all.

Now, I can't see how you can easily, or even with difficulty code a rule based on day of week. There is a day of month function that you could apply to tesst.currentdate but I don't see one for day of week.

Perhaps someone from TTS will answer this?

Tim Arnold
Site Admin
Site Admin
Posts: 8521
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Post by Tim Arnold » Sat Oct 01, 2005 6:48 pm

Agreed that dayOfWeek would be a good property to have.

In the mean time, the following formula will give you the day of the week:

dayOfWeek = toJulian( test.currentDate ) mod 7

Where dayOfWeek = 0 on Sunday, and dayOfWeek = 6 on Saturday.

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Sat Oct 01, 2005 7:55 pm

Tim and TrendMonkey thanks for your support, and i dont have difficulties writting a script, since it said:"script looks good" when i wrote it, i just dont think i was putting the blocks in the right place, can anyone show how to do that for the above example?

Tim Arnold
Site Admin
Site Admin
Posts: 8521
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Post by Tim Arnold » Sun Oct 02, 2005 8:48 am

Sure thing:

1) Create a new block called "DayOfWeek Entry Exit". Make in an "Entry and Exit" type block.

2) Select the Entry Orders script area and put the following code in:

Code: Select all

VARIABLES: dayOfWeek TYPE: integer 

' Get the day of the week as a number
dayOfWeek = toJulian( test.currentdate ) mod 7 

' Go Long on Monday 
IF dayOfWeek = 1 THEN 
	broker.EnterLongOnOpen 
ENDIF 

3) Select the Exit Orders script area and put the following code in:

Code: Select all

VARIABLES: dayOfWeek TYPE: integer 

' Get the day of the week as a number
dayOfWeek = toJulian( test.currentdate ) mod 7 

' Exit position on Wednesday
IF dayOfWeek = 3 THEN
	broker.ExitAllUnitsOnOpen
ENDIF
4) Create a new System called "DayOfWeek System" and drag this block in. You can also drag in the Basic Money Manager at this time, so you can select the size of the position.

5) Select the system and run a test.

Hope that helps. I've attached the block in case that is helpful. You can right click on the attachment, and save in your "Blox" folder. you can then review the block, and add to the system as in step 4.
Attachments
DayOfWeek Entry Exit.tbx
(1.89 KiB) Downloaded 717 times

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Sun Oct 02, 2005 8:26 pm

Tim, thank you so much for the assistance!

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Sun Oct 02, 2005 10:08 pm

got another question...
how am i adding a reverse function to this simple system? for instance:

go long on monday exit on wednesday and then go short on wednesday(after position is exited) and go short exit on monday ( and do it all over.. again)

Tim Arnold
Site Admin
Site Admin
Posts: 8521
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Post by Tim Arnold » Tue Oct 04, 2005 9:18 am

Hi,
The simple way is to replace the broker.ExitAllUnitsOnOpen with broker.EnterShortOnOpen. An Entry order will automatically exit the existing position if there is one.

This will cause multiple units to be put on in the case of holidays, so I wrote a smarter version that I have attached. It checks to see if you are long or short, so it only puts on one unit.

Best,

Tim
Attachments
DayOfWeek Entry Exit.tbx
(1.96 KiB) Downloaded 584 times

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Tue Oct 04, 2005 8:44 pm

Tim, thanks a lot for your assitance , it helps me a lot! i just came out with a system that has Maximum Total Equity Drawdown % =0.00% !
i am look at the chart of the trades and its exactly what i was thinking of and what i pragrammed. auto debugger helped me do that. i am still analyzing the Summary Results that TBB be just gave me and i'll place the entire results list in a little while.

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Tue Oct 04, 2005 9:48 pm

Tim, instrument.close means close of today right?
and broker.EnterLongOnOpen means to place the order today at the open right?
how am i writting a script to place the order for tomorrow at the open?

thanks in advance!

Tim Arnold
Site Admin
Site Admin
Posts: 8521
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Post by Tim Arnold » Tue Oct 04, 2005 9:54 pm

Best bet is to review the Outer Loop document. It's in the manual, and I've attached it here as well.

The way TBB processes a trading day is to set the test date equal to today, set the instrument date equal to yesterday, and generate orders. Then it sets the instrument date equal to today to see if any of the orders got filled.

So in the entry script, instrument.close is yesterday's close. And when you say broker.enterLongOnOpen, it is for today. So on any given trading day the only data you have access to is yesterday's data. Not until all orders are placed will TBB move ahead to today.

So notice that in the After Instrument Day script you test date is equal to instrument date and you have access to all of today's properties.

It's just a way of looking at things. It's easier if you get into the TBB mindset rather than always thinking of placing orders for tomorrow. You are placing them for today (the test today) but using yesterday's data.

Hope that helps!
Attachments
outerloop.doc
(32 KiB) Downloaded 769 times

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Tue Oct 04, 2005 10:55 pm

Tim wrote:So in the entry script, instrument.close is yesterday's close. And when you say broker.enterLongOnOpen, it is for today. So on any given trading day the only data you have access to is yesterday's data. Not until all orders are placed will TBB move ahead to today.
Tim, thanks a lot for explaining that... so now i understand that if i am doing the test i have to think in terms:" its morning (EST), i sit and test the markets before they open today and generate orders that will be placed after the markets will open".
i got confused about how to write script for the day's close "before yesterday", meaning if instrument.close is the yesterday's close how am i writting in a script language of TBB a close that was before instrument.close

BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI » Fri Oct 07, 2005 3:51 pm

hello traders,
so i've been working on the code of my mechanical system and i backtested it and got some interesting results. i dont know how to attach a file right from the TBB so i just printed out the summary test results and scanned them. Tim , do you think it's a realisitc results? 0.1% drawdown and 100% winning months. 32.72 MAR? :roll: i called it TT system (working name)
Attachments
0 drawdown system.rar
TT system
(310.97 KiB) Downloaded 739 times

si
Senior Member
Senior Member
Posts: 48
Joined: Sun May 30, 2004 4:39 pm
Location: Austin, USA

Post by si » Sat Oct 15, 2005 3:38 pm

BARLI wrote:0.1% drawdown and 100% winning months. 32.72 MAR?
:?:

Tim Arnold
Site Admin
Site Admin
Posts: 8521
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Post by Tim Arnold » Sat Oct 15, 2005 5:40 pm

Not clear from the picture how many trades there are. But it looks like you are getting 3% interest per year. Try changing the Earned Interest Rate Global Parameter to zero and see what you get.

Post Reply