How to test a strategy on 5-years of 5 minute data?

ts1

Newbie
Messages
2
Likes
0
Hi Everybody,
I have started using TradeStation, written some strategies and here are some problems I have encountered:
1. How can I load more 5-min data, e.g. 5 years for better testing/optimization?
2. MarketPosition is always 0 when I do history testing. Is there any way to know which position is currently open?
3. How to draw some lines on a chart from strategy (as opposed to indicator)? When I add Plot1 it says this word is not allowed in a strategy.

Thanks in advance.
 
Last edited:
Hi Everybody,
I have started using TradeStation, written some strategies and here are some problems I have encountered:
1. How can I load more 5-min data, e.g. 5 years for better testing/optimization?
2. MarketPosition is always 0 when I do history testing. Is there any way to know which position is currently open?
3. How to draw some lines on a chart from strategy (as opposed to indicator)? When I add Plot1 it says this word is not allowed in a strategy.

Thanks in advance.
1. Click on the price plot to highlight it and then right click. From the Format symbol that pops up look under the "range" section on the settings tab and change the "First date" and "Last Date" to cover the range you want. You might then find a PD symbol appear on the plot (pending data) whilst it collects the 5 years worth

2. Use Currentshares - this is the number of shares currently open in the position (absolute value). If you multiply this by MarketPosition you get a negative number for short positions and a positive number for long positions. Look in the Easylanguage dictionary for the category "Strategy Position" to see other EL functions relating to positions within strategies as opposed to real-life positions.

3. Just put the code for what you want to plot into a new indicator and apply that indicator to the same price line as the strategy. You can have several strategies and indicators on the same price plot. If some of the lines you want to plot use similar logic to the strategy then you can copy code from the strategy to the indicator.

Charlton
 
Charlton, thank you.

1. Tried this to retrieve 1 min data for five years, waited, then scrolled left to the beginning - first bar is still from 2010, not 2005. No PD symbol detected.

2. Yes, but Currentshares is positive or zero, so it does not give information about last open position. I cannot multiply since MarketPosition is zero.

3. I see. I just wanted to keep both strategy and some graphics output in one place.
 
Charlton, thank you.

1. Tried this to retrieve 1 min data for five years, waited, then scrolled left to the beginning - first bar is still from 2010, not 2005. No PD symbol detected.
.

I assume that you are using Tradestation as the data provider. If you are then you can definitely get 5 years of data following my previous instructions (see the first and second attachments). In that case you would need to go back to the TS helpdesk to describe the problem. If they are not your data provider then you might not have 5 years worth of data available.

2. Yes, but Currentshares is positive or zero, so it does not give information about last open position. I cannot multiply since MarketPosition is zero.
.
Currentshares shows currentshares in the strategy at each point in time. Take a look at the 3rd attachment. This shows a dummy strategy applied to the 5 min chart, where you can see various trades set at specific times of the day.

On 29th Jan you can see from both the chart and the print log that at 11am the open position was 0. At 12am there was a short and the open position became -110. At 1300 this was covered and the open position became 0. At 1400 a buy took place and the open position became 100. You can also see how the market position changes between values of 0, 1 and -1. All of this is based on running the strategy on back data and purely based on the trades/positions arising from that strategy.

The code for that dummy strategy (purely to illustrate the point about currentshares and marketposition) is posted below:

Vars:
open_pos(0);

Condition1 = TIME = 1400 ;
Condition2 = TIME = 1100;
Condition3 = TIME = 1200;
condition4 = TIME = 1300;

if Condition1 then begin
Buy ( "Buy" ) 100 shares next bar at market;
open_pos = currentshares*marketposition;
print(eldatetostring(date), " ", time, " current shares ", currentshares, " Market position: ", marketposition, " Open position :", open_pos );
end;

if condition2 then begin
sell("Sell") 50 shares next bar at market;
open_pos = currentshares*marketposition;
print(eldatetostring(date), " ", time, " current shares ", currentshares, " Market position: ", marketposition, " Open position :", open_pos );
end;

if condition3 then begin
sell short("Short") 110 shares next bar at market;
open_pos = currentshares*marketposition;
print(eldatetostring(date), " ", time, " current shares ", currentshares, " Market position: ", marketposition, " Open position :", open_pos );
end;

if condition4 then begin
buytocover("Cover") 110 shares next bar at market;
open_pos = currentshares*marketposition;
print(eldatetostring(date), " ", time, " current shares ", currentshares, " Market position: ", marketposition, " Open position :", open_pos );
end;


There is further complexity that could be introduced using globalvariables or ADE, but I don't really want to go into that at present because it is more advanced stuff and would only muddy the waters, but hopefully you can see that it is perfectly possible to run a strategy that reports (or uses in its calculations) supposed position size and direction.

Charlton
 

Attachments

  • T2W01.png
    T2W01.png
    48.5 KB · Views: 328
  • t2w02.png
    t2w02.png
    32.5 KB · Views: 391
  • t2w3.png
    t2w3.png
    55.1 KB · Views: 404
Top