

However, the ResetCondition can be any valid EasyLanguage code which evaluate to true/false. In the example below you can see the ResetCondition is set to reset the counter upon a new date. If ( Barssinceentry(0) >= Random(5) + 2 ) then Begin If ( RSI( Close, 3 ) 90 ) Then sellshort next bar at open Here is an example strategy using the Limit Trades Function. The second parameter is the maximum number of trades you wish your strategy to take. I provided several ideas within this article. This is the condition on which to reset your trade counter. The first parameter is your reset condition. OKtoTrade = _CE_Limit_Trades( ResetCondition, MaxTrades ) An example of calling this function is below. The function is called, _CE_Limit_Trades. In the downloads section of this article below, you’ll find a function that I created which can be used in your code. You can easily take the code snippets contained within this article and add them to your strategy. With this code you can now limit the number of trades on an intra-day strategy. If ( DayofWeek(Date) = 1 ) and ( Time = 830 ) then TradesCounter = 0 Limit Trades Function Central – the regular session open within the U.S. In our example we want to reset our counter on a Monday morning at 8:30 a.m. The meaning of this value is straightforward with zero being Sunday and Friday being five. This returns an integer value zero through six. We can do this by using TradeStation’s built-in Reserved Word called, DayOfWeek. Regular Session on Monday will allow us to track the number of trades throughout the entire week.

Clearing-out or zeroing our counter at the start of the U.S. How would you code that? Well, we simply look for a a particular day of the week to reset our counter. Maybe you wish to limit the number of trades in a given week. If ( time = ResetTime ) then TradesCounter = 0 You can create an input called ResetTime which will allow you to easily change the time when the counter is reset. In the above line, the counter will be reset at 2:00 a.m. If ( time = 200 ) then TradesCounter = 0 Central when the regular session for the Euro currency futures opens? Well, this can be accomplished by entering the appropriate time when to reset the counter. Keep in mind, this code we’re writing is for intra-day trading! Thus, when the previous bar has a different date than the current bar we must have entered a new day.īut what if we want to reset our counter at a different time? For example, if we wish to reset our counter at the close of the U.S. The above line of code will set our counter to zero when the date on the previous bar is different than the current bar. If TradesCounter date then TradesCounter = 0 Let’s say we don’t want more than 15 trades, then we can code something like this… Now we can test our counter to see if we’re at our limit. When a new position is taken, we increase our counter. If this happens, a new position was taken.

The second check is looking for a position changed from the previous bar.

Put another way, something changed! Again, the first check assures we have a position, either long or short. The second test then checks that on the previous bar the market position status is not the same as the current status. In the above code we see the first test is to check that we’re not currently flat. If ( MP 0 ) and (MP MP ) then TradesCounter = TradesCounter+ 1 Thus, we simply look for a switch between these states. It will have a value of -1 if your strategy is short, and it will have a value of 1 if your strategy is long. MP will have a value of 0 if your strategy is flat. This is done by checking the status of the TradeStation’s built-in reserved word MP. How do we know when a trade has opened? One way to do this is to monitor the market position state of your strategy. This can be done by incrementing a variable every time your strategy opens a trade. We simply wish to track each new position. What if you wish to limit the number of trades over a given week? Nope, can’t do it with EnteriesToday. This works fine in many cases, but what if you wish to limit the number of trades in the overnight session? EnteriesToday assumes the regular session and will reset the trade counter when the day changes – right in the middle of your trading. The code I’m going to write will be a more flexible method than the built-in TradeStation reserved word, EnteriesToday. Once it reaches that number, you wish the strategy to not open any more trades until the next trading day. For example, you may want your day trading strategy to only take a maximum of 20 trades per day. Most often this is done to limit the number of trades a strategy will open in a single day. In this article I’m going to demonstrate an EasyLanguage technique to limit the number of trades your trading system will take within a given period.
