Hedging Strategy
Forums › ProRealTime English forum › ProOrder support › Hedging Strategy
- This topic has 16 replies, 5 voices, and was last updated 7 years ago by Maz.
-
-
11/10/2016 at 3:53 PM #16319
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
11/10/2016 at 9:00 PM #1635111/13/2016 at 11:23 AM #1643711/14/2016 at 11:00 AM #16472Hi 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.
11/14/2016 at 11:45 AM #1648011/14/2016 at 2:09 PM #16496Hi 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.
04/08/2017 at 1:22 PM #3143004/27/2017 at 6:11 PM #33720…@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…
04/27/2017 at 6:13 PM #3372204/27/2017 at 6:38 PM #3372404/28/2017 at 9:54 AM #33807Hi 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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146// 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 ParametersDEFPARAM FLATBEFORE = 010000 // UK time zoneDEFPARAM FLATAFTER = 163000 // UK time zoneDEFPARAM cumulateOrders = false// -- Position sizing --firstPositionSize = 1secondPositionSize = 2 // maybe do some dynamic magic with this ?// UK FTSE Opening hours (GMT+/-0)// Adjust for your market and time zoneonce marketOpen = 080000once marketClose = 163000// -- Variable set selection --once optimization = 1if optimization = 1 then // FTSE M30// flipDistance = 17 // 15 // originally 40// firstTradeTarget = 134 // 87// secondTradeTarget = 144 //87// maLongPeriod = 207endTime = 160000startTime = 080000//startTimeOffset = 120000 // done this way for optimizer to work//000000+startTimeOffsettradingTime = time > startTime and time < endTimeendif// -- Indicators -----// -- Low and high of actual trading day (not the 24 hour market)once startBarIndex = 0if time = marketClose thenyHigh = highest[barIndex-startBarIndex](high)yLow = lowest[barIndex-startBarIndex](low)//doneForTheDay = 0// Stop and reverse levels for long and short sideflipDistance = flipDistanceRangeMultiple * (yHigh - yLow)shortFlipLevel = yHigh-(flipDistance*pipSize)longFlipLevel = yLow +(flipDistance*pipSize)elsif time = marketOpen thenstartBarIndex = barIndexendif// resetif time = startTime thentradesPlaced = 0sellOrderLevel = undefinedbuyOrderLevel = undefinedstopTarget = undefinedstopLoss = 999999999 // offendifwithinRange = 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 tradingTimebo1 = bo1 and tradesPlaced = 0bo1 = bo1 and fLongso1 = withinRange and not onMarket and tradingTimeso1 = so1 and tradesPlaced = 0so1 = so1 and fShrtbo2 = shortOnMarket and tradingTime and tradesPlaced = 1bo2 = bo2 and not bo1 and abs(countOfPosition) = firstPositionSizeso2 = longOnMarket and tradingTime and tradesPlaced = 1so2 = so2 and not so1 and abs(countOfPosition) = firstPositionSizeif bo1 thenorderSize = firstPositionSizebuyOrderLevel = yHighstopTarget = firstTradeTargetendifif so1 thenorderSize = firstPositionSizesellOrderLevel = yLowstopTarget = firstTradeTargetendifif bo2 thenorderSize = secondPositionSizestopTarget = secondTradeTargetstopLoss = secondTradeStopLossbuyOrderLevel = longFlipLevelendifif so2 thenorderSize = secondPositionSizestopTarget = secondTradeTargetstopLoss = secondTradeStopLosssellOrderLevel = shortFlipLevelendif// -- Order placing --if bo1 or bo2 thenbuy orderSize shares at buyOrderLevel stopendifif so1 or so2 thensellShort orderSize shares at sellOrderLevel stopendifif bo1 or so1 or bo2 or so2 thenset stop pLoss stopLoss // not really used currentlyset target pProfit stopTargetendif// keep track of open tradesif onMarket thenif not onMarket[1] thentradesPlaced = 1elsif countOfPosition = secondPositionSize thentradesPlaced = 2endifendif//graph tradesPlacedI’ll see if I can take another look at this when I get the time.
All the best,
Maz
1 user thanked author for this post.
04/28/2017 at 9:59 AM #33812Oh 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.
04/28/2017 at 10:05 AM #33816Daily 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.
04/30/2017 at 6:42 PM #34059Thanks 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
1234567891011CLP=CLPCLV=CLVCSP=CSPCSV=CSV// -- Order placing --if bo1 or bo2 and Chandle[CLP](close) < CLV thenbuy orderSize shares at buyOrderLevel stopendifif so1 or so2 and Chandle[CSP](close) > CSV thensellShort orderSize shares at sellOrderLevel stopendif05/09/2017 at 10:46 AM #34913 -
AuthorPosts
Find exclusive trading pro-tools on