Hi,
This is my first post on this forum, in fact I have only registered today on this website. I have been playing around with a strategy manually on Pro Real time so wondering if someone could help code this in Pro Order. It is as below:
(1) Runs everyday between midnight and 16:00 hrs
(2) At midnight, place one long pending order 1 pip above yesterday’s high and one short pending order 1 pip below yesterday’s low.
(3) If long order triggers, cancel the existing pending short order and place a new pending short order twice the size at 40 pips below yesterday’s high.
(4) If short order triggers, cancel the existing pending long order and place a new long order twice the size at 40 pips above yesterday’s low.
(5) At 16:00 hrs cancel all the pending orders and close all the active positions.
Thanks
Sorry, forgot to mention, the Stop Loss and Take Profit is 40 pips for the above strategy.
Have you got some good results so far with this manual trading strategy? What is the instrument traded with it?
Hi Nicholas, I have been manually testing this with GBP pairs especially GBP/AUD. Unfortunately getting up at midnight to place orders and then manually maintaining them until 4pm would a nightmare. Hence would like to code and back-test this. Please let me know if this is feasible.
So you only want to have one trade per day with this strategy? Do you need stoploss and/or takeprofit for orders?
Hi Nicolas, the idea is to take one trade per day however if it doesn’t hit the target leave the one in the opposite direction active to hopefully make profit. The stop loss and take profit is 40 pips. The strategy can be summarized as below:
1) Runs everyday between midnight and 16:00 hrs
(2) At midnight, place one long pending order 1 pip above yesterday’s high and one short pending order 1 pip below yesterday’s low
(3) If long order triggers, cancel the existing pending short order and place a new pending short order twice the size at 40 pips below yesterday’s high.
(4) If long order hits the target then cancel the existing pending short order.
(5) If short order triggers, cancel the existing pending long order and place a new long order twice the size at 40 pips above yesterday’s low.
(6) If short order hits the target then cancel the existing pending long order.
(&) At 16:00 hrs cancel all the pending orders and close all the active positions.
Thanks in advance.
Helo I wanted to ask about your startegy how effective has it been and how many trades do you take in a day
MazParticipant
Veteran
…@learner and what would be the target? Why 40 pips, where did that number come from and on what instrument? Would you not want a dynamic SR (stop and reverse) distance to chance with market conditions? I’d guess you’d want dynamic targets also? Was this based on some kind of previous study or was it something you thought up?
On the surface it sounds a bit rigid to work in the long run but I have a snag there might be something in it if some suitable filters are applied. I’ll have a little look…
MazParticipant
Veteran
Oh excuse me, I see you mentioned GBP pairs. I have a snag about the FTSE also. Shall we have a look then…
oh thanks Maz, that is a post I did not reply quickly enough, so I forgot it!
MazParticipant
Veteran
Hi all,
So I took the premise above and created a little something. The general idea is that if the break of yesterday’s daily high/low (whichever comes first) fails, then a stop and reverse x points away at double the position size is likely to make up for it.
I tested this out on FTSE. On its own the idea doesn’t work. But once you put in a trend filter (in this case long term MA), it starts to become promising. Below is just a quick version I threw together – a skeleton if you like, which gets the orders in the right places according to the rules above – so not finished work by any means.
There are probably some cleaver filters which could be fitting here (ADX, FDI, volume, oscillators, seasonality, etc etc) – so I invite anyone to take a look, have a play around and contribute; as well as test it out on different instruments / asset classes.
// FTSE M30
// Notes
// Things to try for the next versions
// -- Seasonailty
// -- Day of week biasing
// -- Day of month biasing
// -- Correlated market biasing (in house platform)
// -- ATR based stops and limits
// -- ATR based or range based (or both based) flip distances
// -- Trailing and donchian stops
// -- momentum and trend filters
// -- System Parameters
DEFPARAM FLATBEFORE = 010000 // UK time zone
DEFPARAM FLATAFTER = 163000 // UK time zone
DEFPARAM cumulateOrders = false
// -- Position sizing --
firstPositionSize = 1
secondPositionSize = 2 // maybe do some dynamic magic with this ?
// UK FTSE Opening hours (GMT+/-0)
// Adjust for your market and time zone
once marketOpen = 080000
once marketClose = 163000
// -- Variable set selection --
once optimization = 1
if optimization = 1 then // FTSE M30
// flipDistance = 17 // 15 // originally 40
// firstTradeTarget = 134 // 87
// secondTradeTarget = 144 //87
// maLongPeriod = 207
endTime = 160000
startTime = 080000
//startTimeOffset = 120000 // done this way for optimizer to work
//000000+startTimeOffset
tradingTime = time > startTime and time < endTime
endif
// -- Indicators -----
// -- Low and high of actual trading day (not the 24 hour market)
once startBarIndex = 0
if time = marketClose then
yHigh = highest[barIndex-startBarIndex](high)
yLow = lowest[barIndex-startBarIndex](low)
//doneForTheDay = 0
// Stop and reverse levels for long and short side
flipDistance = flipDistanceRangeMultiple * (yHigh - yLow)
shortFlipLevel = yHigh-(flipDistance*pipSize)
longFlipLevel = yLow +(flipDistance*pipSize)
elsif time = marketOpen then
startBarIndex = barIndex
endif
// reset
if time = startTime then
tradesPlaced = 0
sellOrderLevel = undefined
buyOrderLevel = undefined
stopTarget = undefined
stopLoss = 999999999 // off
endif
withinRange = close < yHigh and close > yLow
// -- Common indicators -----
maLong = average[maLongPeriod, 1](Close)
// -- Filters -----
// only long if...
fLong = maLong > maLong[1]
// only short if...
fShrt = maLong < maLong[1]
bo1 = withinRange and not onMarket and tradingTime
bo1 = bo1 and tradesPlaced = 0
bo1 = bo1 and fLong
so1 = withinRange and not onMarket and tradingTime
so1 = so1 and tradesPlaced = 0
so1 = so1 and fShrt
bo2 = shortOnMarket and tradingTime and tradesPlaced = 1
bo2 = bo2 and not bo1 and abs(countOfPosition) = firstPositionSize
so2 = longOnMarket and tradingTime and tradesPlaced = 1
so2 = so2 and not so1 and abs(countOfPosition) = firstPositionSize
if bo1 then
orderSize = firstPositionSize
buyOrderLevel = yHigh
stopTarget = firstTradeTarget
endif
if so1 then
orderSize = firstPositionSize
sellOrderLevel = yLow
stopTarget = firstTradeTarget
endif
if bo2 then
orderSize = secondPositionSize
stopTarget = secondTradeTarget
stopLoss = secondTradeStopLoss
buyOrderLevel = longFlipLevel
endif
if so2 then
orderSize = secondPositionSize
stopTarget = secondTradeTarget
stopLoss = secondTradeStopLoss
sellOrderLevel = shortFlipLevel
endif
// -- Order placing --
if bo1 or bo2 then
buy orderSize shares at buyOrderLevel stop
endif
if so1 or so2 then
sellShort orderSize shares at sellOrderLevel stop
endif
if bo1 or so1 or bo2 or so2 then
set stop pLoss stopLoss // not really used currently
set target pProfit stopTarget
endif
// keep track of open trades
if onMarket then
if not onMarket[1] then
tradesPlaced = 1
elsif countOfPosition = secondPositionSize then
tradesPlaced = 2
endif
endif
//graph tradesPlaced
I’ll see if I can take another look at this when I get the time.
All the best,
Maz
MazParticipant
Veteran
Oh and I forgot to mention be careful if you are not in the GMT time zone – be sure to adjust the times in the code. Also the variables inside “if optimization = 1” section are commented out because I was using the optimizer. Un-comment if you want it to work. ITF attached.
MazParticipant
Veteran
Daily high and low
And again another thing I forgot to mention:
Instead of using 24-hour dHigh and dLow for the initial day break levels, I am using the high and low from the cash market’s opening hours. So on FTSE 0800 – 1630 GMT highest high and lowest low. Obviously play around with this on different instruments. Could be interesting to see how metals and FX behave.
Attached is an indicator for debugging. “distance” is for the stop and reverse line relative to highs and lows.
Thanks Maz … pleasure to work with your code!
I can’t claim to have read / understood :), but I managed to squeeze some more profit and a better curve?
Below is the main change followed by re-optimise of main variables. Attached are results and .itf file.
GraHal
CLP=CLP
CLV=CLV
CSP=CSP
CSV=CSV
// -- Order placing --
if bo1 or bo2 and Chandle[CLP](close) < CLV then
buy orderSize shares at buyOrderLevel stop
endif
if so1 or so2 and Chandle[CSP](close) > CSV then
sellShort orderSize shares at sellOrderLevel stop
endif
MazParticipant
Veteran
@GraHal good idea, good work. I’ll also look further into it 🙂