Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Has anyone figured out any EL code that can keep track of day trades, so that a strategy will only execute a trade if there have been less than 3 trades in previous 5 business days?
Can you help answer these questions from other members on NexusFi?
I was fairly sure this was included in Kevin D's great Entries and Exits book... I am sure I've seen it somewhere online too but I can't now find it either on my bookshelf or online!
>I think if I just set the timeframe to "5 days back
D'you mean in the chart? That would make it impossible to properly backtest, walk forward, monte carlo and lightly optimise though, unless I've misunderstood.
I just compiled this;
if (totaltrades[0] + totaltrades[1] + totaltrades[2] + totaltrades[3] + totaltrades[4]) <=3 then begin
// insert entry here
end;
based on KJ's structure but using a function included in the EasyLanguage bible I mentioned.
Of course, code that compiles doesn't necessarily do what you want it to, but it's a start!
What you have would only work if you are on daily candles, because if you were on intraday, the previous totaltrades[1] bar would be the previous bar, not the previous day. For my use case, this code would just be for live trading, and the backtesting would be done on the strategy without this code included. I can't think of any reason why it would fundamentally change a strategy for better or worse---it would just reduce the number of trades.
Good spot! You're right... though if you wanted to use the same code, you could have data1 as the bar size of your choice and data2 as daily bars, then reference data2 in the code I wrote.
Or this may be better?
if (totaltrades[currentdate] + totaltrades[currentdate-1] + totaltrades[currentdate-2] + totaltrades[currentdate-3] + totaltrades[currentdate-4]) <=3 then begin
// insert entry here
end;
I think it's best to backtest, walk forward, etc with the same code you trade, whenever possible.
Ah yes, putting daily bars on data2 would be a good way to do that, thanks for the insight! I don't think totaltrades[currentrade] would work because currentdate returns values like "200901"
EDIT: I just remembered, when you have multiple data series on a chart, but a shorter timeframe on one of the data series, the historical reference brackets [1] counts based on shorter timeframe.
For example, say you have 1 minute bars on data1, and 5 minute bars on data2. To make the bars line up, tradestation just puts blank spaces between the 5 minute bars, and each of those blank spaces holds the price values of whatever the last 5min bar was. So if you wanted to reference the close price on data2 one (5min) bar ago, you would actually do close[5], and for two 5 min bars ago, you could do close[10], and so on.
So in the case of daily bars on data2, and perhaps 1 minute chart on data1, to reference the close price of 1 day ago, you would need close[390] (based on a 6.5 hour trading session)