Breakout from first hour's high or low (intraday setup)
Author: Defendi
Creation Date: 11/2/2012 8:04 AM
profile picture

Defendi

#1
Sorry for the mistakes, I'm using Google Translator.
I need to test the following setup for intraday positions in futures markets:
Mark the maximum and the minimum of the first hour
Buy the breakup of one tick of the maximum, if EMA 9 is ascending or sell the minimum of disruption if EMA 9 is descending
Exit with 500 points gain or 300, stop loss, or 16:45 at the price that is
Could help me. I can not do using Wizard
thank you very much
profile picture

Eugene

#2
Here you go!

CODE:
Please log in to see this code.
profile picture

Defendi

#3
That's amazing. Thanks a lot for your support.
The setup is really profitable. I hope that you friends enjoy it.
profile picture

Defendi

#4
Sorry. Looking calmly saw an error. The purchase or sale should be made only 1 cent above the maxima or minima of the first hour, ie, at least in the second hour of trading, and stop the gain could be 1% and 0.5% stop loss?
grateful
profile picture

Eugene

#5
I noticed a pesky typo:
CODE:
Please log in to see this code.

Should be
CODE:
Please log in to see this code.

Code above corrected.
profile picture

Eugene

#6
QUOTE:
The purchase or sale should be made only 1 cent above the maxima or minima of the first hour,

The code indeed buys one 1 tick above/below the high/low. What you thought is an error, was not. You're running it on 60-minute bars, and an entry valid on the last bar was executed on first bar of the next day. Well, it's easy to filter out these entries -- see below.
QUOTE:
and stop the gain could be 1% and 0.5% stop loss?

Sure, exposed % stop/target via "Strategy Parameters".

Here's code containing these two changes:
CODE:
Please log in to see this code.
profile picture

Defendi

#7
Perfect. Thanks a lot.
profile picture

Defendi

#8
Sorry abuse their patience ... but I do not know programming! ... Change the position for Single position a day, it would be very difficult?
profile picture

Cone

#9
It's a simple edit... I'll add this statement:
CODE:
Please log in to see this code.


And move Position p = LastActivePosition; outside the exit logic.

Wait 1 minute and you can recopy the strategy above.
profile picture

streak

#10
I'm not much experienced at this but it seems the ma period could go askew from the bar period; throwing results?
profile picture

Eugene

#11
Not sure what do you mean, but this should be enough to stabilize the unstable EMA:
CODE:
Please log in to see this code.
profile picture

Defendi

#12
Eugene.... I'm sorry for my ignorance .. I tried but it is giving error ... could put the full code? grateful
profile picture

Eugene

#13
The code above is complete. Cone has already edited it for you. Just copy and paste it once again.
profile picture

Defendi

#14
Sorry again. Not speaking English is very limited and very difficult. Had not understood that the code had already been moved. I tested here and may not have expressed myself right, the idea is to trade a single day with a single position. As it is a single open position but there are days when it is 3-4 trades in a single day. It would be possible to make a single trade on? Muto appreciate the patience and willingness of friends, the only thing I can offer in return is a setup quite profitable, so I already know why it uses a good time here in Brazil, Hugs
profile picture

Cone

#15
Once you copy and paste the code, make sure that you hit the Compile button. Alternatively, the Run the Strategy button compiles and then runs it.

We're sure the code will give you only one trade per day.
profile picture

Defendi

#16

You were right. It's perfect. I tested here in over 200 shares in a time of 60 minutes and graphic setup proved quite profitable, pity not be possible to do so by the Wizard to be able to test variations of EMA and stop the stop loss and gain, but I think it is now much more easy to change the script, I'll try. Thankful again, without your help I would never have achieved
profile picture

streak

#17
Seems concept primarily for 60 min bars. However the code maintains a 9 period avg while accommodating differing bar periods. This avg could change from advancing to declining pending the bar period, throwing results, could it not?
profile picture

sktrades

#18
I'm trying to backtest this code for e-minis. The intraday data series begins at 12:00 AM (during overnight trading). So the code uses the 12AM - 1AM trading hour to set the High60 & Low60 values for the day. How can I change the code so that the High60 & Low60 values are set during 9:30AM - 10:30 AM.
profile picture

Eugene

#19
Use GetTime(bar) when setting the first hour's range instead of this line that determines a day's first bar:
CODE:
Please log in to see this code.

You might also want to tweak the last hour:
CODE:
Please log in to see this code.
profile picture

sktrades

#20
I believe I also will need to change the 'int num' setting to shift it to the bar number representing 10:30am. Does that make sense?
profile picture

Eugene

#21
No.
profile picture

sktrades

#22
But if I don't change 'num' won't the following code set High60 & Low60 at 1AM instead of 10:30AM?

CODE:
Please log in to see this code.
profile picture

Eugene

#23
You're right, that's not enough. On second thought, the correct way is to NOT change the code at all (or you end up changing a good deal of it).

What you need is to specify the market's open time using the Market Manager tool.
profile picture

Cone

#24
The MM isn't going to help unless sktrades wants to filter the data. I think the idea is to use the 24-hour Globex data, but set the breakout range using specified times. sk, is this correct?
profile picture

sktrades

#25
Yes. I'd like to tie the High60 & Low60 for e-minis to the stock market opening hour.

I made the following change to num to align to 1st hour :

int num = 60*9/n + 30/n + (60 / n ) - 1 ; // shift for 9 1/2 hours overnight trading.

This seems to work ok now. Thanks.
profile picture

rmpwealth

#26
This strategy is intigueing.

1. Which of the above codes is the "final" final code that corresponds to the original strategy?

2. In the 4:12pm code, is the Exit stop criteria (i.e. -- +1% or -0.5%) in "addition to" the original criteria, or is it "instead of" the original criteria?

3. If I want to use this strategy for a single Symbol during a standard trading day, which of the above codes should be used (i.e. -- which is the most comprehensive and flexible without having to change other parameters or use other Tools)? What input settings should I use?

Thanks.

profile picture

Eugene

#27
1. Uploaded on the website, hence accessible through Wealth-Lab's "Open Strategy" dialog (Ctrl-O), will appear under "Breakouts".

2. Since by that time, topic starter had changed his requirements from a point-based criteria to percentages, it's "instead of".

3. The one that you have understood, thoroughly backtested, double checked that the code works as expected, and optimized to find the input settings that would work for you!
profile picture

rmpwealth

#28
I downloaded the strategy and ran it for SPY, but the results seem odd.

My settings were: Scale = 1-min; DataRange = 1-Yr; PosSize = RawProfitFixedDollar = $10,000; MarginFactor = 1.5:1.

My results were: The Backtest Performance Report indicates 308 trades (159 Long; 149 Short). If the strategy can only trade one time per day, which is what the Entry Rules state, then this is more trades than there are trading days in one year (plus, I would presume that the Entry Trade Rules would not be "True" EVERY day, but maybe so). Average Bars Held = 195, which is a little over 3-hours per trade, which I guess is plausible. Do these results seem right to you? If not, are my input settings not appropriate for this code?

profile picture

Eugene

#29
QUOTE:
If the strategy can only trade one time per day, which is what the Entry Rules state,

Where did you find it in the Strategy's code?
Where does the Strategy Description block indicate it?

No need to answer, my questions were rhetorical. The original uploaded Strategy can trade several times a day.

One final note. Originally, the strategy was designed to trade 60-min bars. With 1-minute bars, sometimes it can delay its exit on the last bar to the first bar of the next session. I guess it has to do with how the last bar is timestamped (e.g. 16:01). Should you experience something like this, adjust the close time (to e.g. 1559) on this line:
CODE:
Please log in to see this code.
profile picture

rmpwealth

#30
Entry rules

1.Buy at breakout of first hour's high plus one tick, if 9-period moving average is rising
2.Short at breakdown of first hour's low minus one tick, if 9-period moving average is declining
3.Take one position only during a trading session

I guess I interpeted #3 to mean that the rules would allow only one trade per day.
profile picture

Eugene

#31
Thanks for the heads-up and sorry for the confusion. That was my mistake when documenting it. Of course the code does not contain such rule. Description has been fixed. You can always apply the "Max Entries Per Day" PosSizer.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).