A Simple Break Out Algorithm Demonstrating Time Optimization

What is Better:  30, 60, or 120 Minute Break-Out on ES.D

Here is a simple tutorial you can use as a foundation to build a potentially profitable day trading system.  Here we wait N minutes after the open and then buy the high of the day or short the low of the day and apply a protective stop and profit objective.  The time increment can be optimized to see what time frame is best to use.  You can also optimize the stop loss and profit objective – this system gets out at the end of the day.  This system can be applied to any .D data stream in TradeStation or Multicharts.

Logic Description

  1. get open time
  2. get close time
  3. get N time increment
    1. 15 – first 15 minute of day
    2. 30 – first 30 minute of day
    3. 60 – first hour of day
  4. get High and Low of day
  5. place stop orders at high and low of day – no entries late in day
  6. calculate buy and short entries – only allow one each*
  7. apply stop loss
  8. apply profit objective
  9. get out at end of day if not exits have occurred

Optimization Results [From 15 to 120 by 5 minutes] on @ES.D 5 Minute Chart – Over Last Two Years

Optimization of Time: Look How the # Trades Decrease as the Time Increment Increases

Simple Orbo EasyLanguage

I threw this together rather quickly in a response to a reader’s question.  Let me know if you see a bug or two.  Remember once you gather your stops you must allow the order to be issued on every subsequent bar of the trading day.  The trading day is defined to be the time between timeIncrement and endTradeMinB4Close.  Notice how I used the EL function calcTime to calculate time using either a +positive or -negative input.  I want to sample the high/low of the day at timeIncrement and want to trade up until endTradeMinB4Close time.  I use the HighD and LowD functions to extract the high and low of the day up to that point.  Since I am using a tight stop relative to today’s volatility you will see more than 1 buy or 1 short occurring.  This happens when entry/exit occurs on the same bar and MP is not updated accordingly.  Somewhere  hidden in this tome of a blog you will see a solution for this.  If you don’t want to search I will repost it tomorrow.


//Optimizing Time to determine a simple break out
//Only works on .D data streams
Inputs: timeIncrement(15),endTradeMinB4Close(-15),stopLoss$(500),profTarg$(1000);

vars: firstBarTime(0),lastBarTime(0),buyStop(0),shortStop(0),
calcStopTime(0),quitTradeTime(0),buysToday(0),shortsToday(0),mp(0);

firstBarTime = sessionStartTime(0,1);
lastBarTime = sessionEndTime(0,1);

calcStopTime = calcTime(firstBarTime,timeIncrement);
quitTradeTime = calcTime(lastBarTime,endTradeMinB4Close);



If time = calcStopTime then
begin
buyStop = HighD(0);
shortStop = LowD(0);
buysToday = 0;
shortsToday = 0;
End;

if time >= calcStopTime and time < quitTradeTime then
begin
if buysToday = 0 then Buy next bar at buyStop stop;
if shortsToday = 0 then Sell short next bar at shortStop stop;
end;

mp = marketPosition;

If mp = 1 then buysToday = 1;
If mp = -1 then shortsToday = 1;

SetStopLoss(stopLoss$);
setProfitTarget(profTarg$);
setExitOnClose;
Orbo EasyLanguage Code

 

 

 


Discover more from George Pruitt

Subscribe to get the latest posts sent to your email.

2 thoughts on “A Simple Break Out Algorithm Demonstrating Time Optimization”

    1. Hi Matt,

      Good question. In TradeStation a .D extension to the symbol name such as @ES.D represents the pit session time – in Eastern Time it would be 9:30 to 4:15. TradeStation has several symbols you can add the .D to. However, you can also create your own custom session which will replicate the same time period covering the .D. This code can be applied to any session as I am using sessStartTime and sessEndTime but it really is designed to day trading purposes.
      Thanks for the question — George

Leave a Reply