I have spent time looking for a breakout strategy on the website but I could not find exactly what I have in my mind.
Could someone help me programming an “open range breakout” automated strategy? I would really appreciate any help. It would be based on a custom range indicator that I have made with the great help of Nicolas (cf. code of the indicator below). So it should not take too long to write the code I guess!
Rules are as follows:
Time frame 1H
The indicator already defines the parameters for:
– the range = the highest and lowest point of a timeperiod (for example low and high from 5 am to 8 am) +/-5 pips (for example). So the top of the range is high + 5 pips, the bottom of the range is low – 5 pips
– the profit targets = 50% of the range size, 100% of the range and 150% of the range
Trades are initiated at the end of the timeperiod range (start at 8 am in this example) and no trade should be taken after 10 pm. Positions are closed at midgnight.
From 8 am, if the price moves above the top of the range, a buy order is set. If the price moves below the bottom of the range, then a sell order is set. 2 positions cannot be set at the same time. If the first position is a winner, then no further position should be initiated for the day. However, if the first position fails, then another order can be set (if the price reverses its direction for instance), with the limit of 2 orders in total per day.
=> Is there a way to make proorder trigger the buy/sell order just when the price hits the top/bottom of the range, and not after the close of the candle ? I understand that proorder must wait for the close of a candle in which the condition is met in order to set the order. Can this be bypassed? Since the timeframe is 1 hour, it would be too long to wait for a close of the candle!
Stop loss is either at the bottom of the range (for long position) or the top of the range (for short), as described previously (high or low +/- 5 pips). If the total size of the opening range is more than 50 pips, then no position is initiated for the day.
3 contracts per position: take profit is in 3 steps as follows:
– when the price reaches the first target (50% of the range size), 1 contract is sold,
– when the price reaches the second target (100% of the range size), 1 other contract is sold and stop loss is moved to breakeven
– then the third contract is sold if the price reaches the third target (150% of the range)
=> I am not sure if it is possible to partially close a position. If not, then the take profit is equal to the range size (target 2).
Thanks in advance to those who will answer me. The coding of this strategy will also allow me to backtest different parameters.
open range box with targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
oncehh=undefined
oncell=undefined
oncehh1=undefined
oncell1=undefined
oncehh2=undefined
oncell2=undefined
oncehh3=undefined
oncell3=undefined
starttime=050000
endtime=080000
ifintradaybarindex=0then
hh=0
ll=0
alreadydrawn=0
endif
iftime=starttimethen
startbar=barindex
endif
iftime=endtimethen
endbar=barindex
endif
iftime>=starttimeandtime<=endtimethen
ifhigh+5*pipsize>hhthen
hh=high+5*pipsize
endif
iflow-5*pipsize<llorll=0then
ll=low-5*pipsize
endif
lerange=(hh-ll)/2
else
hh=hh
ll=ll
hh1=hh+lerange
ll1=ll-lerange
hh2=hh+2*lerange
ll2=ll-2*lerange
hh3=hh+3*lerange
ll3=ll-3*lerange
endif
iftime>endtimeandalreadydrawn=0then
drawrectangle(startbar,hh,endbar,ll)
alreadydrawn=1
endif
returnhhas"Maxi période de cotation",llas"Mini période de cotation",hh1as"Maxi1",ll1as"Mini1",hh2as"Maxi2",ll2as"Mini2",hh3as"Maxi3",ll3as"Mini3"
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue