// FOREX BREAKOUT
// 15 MIN
// One order per day, from 09:00h. The system shuts-down at 14:00h
// Everyday Channel formation from 0800 to 0900 (Highest-Lowest)
DEFPARAM CUMULATEORDERS = false
// OPERATIONAL TIME
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 140000
Operationaltime = TIME > 090000 AND TIME < 140000
// ONE TRADE PER DAY. It resets the variable each new day
IF INTRADAYBARINDEX = 0 THEN
alreadytraded = 0
ENDIF
// RANGE between 0800h to 0900h
IF TIME=090000 THEN
resistance = Highest[4](high)
support = Lowest[4](low)
ENDIF
// LONG Positions-Opening
IF Operationaltime AND alreadytraded = 0 THEN
BUY 1 CONTRACT AT resistance STOP
alreadytraded = 1
ENDIF
// SHORT Positions-Opening
IF Operationaltime AND alreadytraded = 0 THEN
SELLSHORT 1 CONTRACT AT support STOP
alreadytraded = 1
ENDIF
// STOP & PROFIT
SET STOP LOSS 8*pipsize
SET TARGET PROFIT 8*pipsize
Hi everyone,
I am sending attached a very simple breakout strategy that I have been on and off for a week. I have one problem with the coding.
Every time the price breakouts the highest or lowest from the 4 previous candles, I would like to buy exactly at the point where the price breaks the ceiling of floor, not at the beginning of next candle. I have removed MARKET from the equation and created an STOP order, but still not working.
I am attaching a pdf drawing of an example of what I am intending to do, for a better understanding.
Thanks to everyone,
Juan
You can’t!
Strategies, at least until the Multitimeframe feature is provided, are only executed at each new candle, not in the middle or elsewere.
You may try to switch to 1 minute TF and adjust computations so that it “looks like” (not exactly, especially if you want to deal with Moving Averages) being executed in a 15min TF.
Examnple with your code (15 1-minute bars for each 15-minute bar):
// RANGE between 0800h to 0900h
IF TIME=090000 THEN
resistance = Highest[60](high) //4 * 15
support = Lowest[60](low) //4 * 15
ENDIF
Hope you can manage to run your strategy as expected.
Hi Roberto,
Thanks for your answer!!! It seems a good idea to convert the one 15′ candle into 15/one minute candles, so the breakout moment can be pinpoint with more precision than before.
Nevertheless, I thought that putting a limit or stop order at an specific point would spark the order in the middle of the candle. I have struggling with this for a week.
Thanks so much for your help!!!
Juan
EricParticipant
Master
you can also use intradaybarindex to count the bars
(indicator)
x = bars from start of the day
y = range (4 if you want 1 hour of 15-min bars)
IF IntradayBarIndex = x THEN
Hi = HIGHEST[y](HIGH)
ENDIF
RETURN Hi
and then use stoporder
but i wonder if the 1 trade per day will work with stoporders?
Thanks Eric. Yes the “1 trade per day” should work if the variable is incremented like the way Juan did in his first post. But the STOP order will only be set during 1 bar (stop orders expire each new bar). To count pending orders, there is no other way I’m afraid.
Hi Eric,
Thanks for your contribution. I will study your option. Right not, I am applying what Roberto said and it seems a good idea since I can’t buy right at the break-out at the same candle. So, I am breaking the 15′ candle in 15 small ones.
I thought that placing an stop order at that point will work (BUY 1 CONTRACT AT resistance STOP), but it doesn’t work.
Thanks,
Juan
I have the same problem as Juan. In the Assisted ProBacktest Creation window, there is a drop-down box under the ‘Buy’ section at the bottom with one item in it – ‘next bar open’.
Presumably, since this is a drop-down box, it would be expected that there would be a range of options there (eg ‘on next tick’ and/or ‘x pips higher’). Is that correct? Presumably, Roberto, that’s what you meant when you referred to the Multitimeframe feature being provided? When will this upgrade be available, does anyone know?
Also, Roberto, you referred to converting a 15-minute candle into 15 one-minute candles, but I don’t understand your code (I’m a complete beginner). How do I make that conversion?
To switch from a 15-min TF to a 1-min TF all you have to do is multiply bar references by 15 (there are 15 1-minute bars in a single 15-min bar).
This is pretty simple in the above case (the example with HIGHEST/LOWEST), but it is not as easy if you are within minute 20 bar (say 102000) and want to know the closing price of the previous 15-minute candle, because if you write
close[15]
you get the closing price at 10:05:00 which is NOT the closing price of the previous 15-minute bar (that was at 10:15:00), just the closing price 15 bars ago.
As you can see there are cases in which you can find a solution using such conversions/adjustments, but in many other cases you can’t make it work as expected.
The final solution is….. we all have to wait for the MultiTimeFrame feature in a (hopefully near) future release of ProOrder!
triggerdown=lowest[4](low)
triggerdup=highest[4](high)
buy 1 contract at triggerup stop
sellshort 1 contract at triggerdown stop
The only way to buy “in the middle of a candle” are stop-orders.