BardParticipant
Master
Is this feasable:
https://www.youtube.com/watch?v=DJz4E7VyeSw @41 mins and 30 seconds Joseph Nemeth introduces his “Zone Recovery” Trading Algorithm. The idea is you never take a loss because the algo Martingales it’s trade size to always stay ahead in the number of positive ticks for the trade – pls see the image below. Nemeth states he backtested the system using a 200 pip Zone and on 10 Lots and with 20 moves back and forth through the Recovery Zone the most it cost him was 3,600 pips drawdown (from 124 mins), tha tsound like a lot…
At around 125 mins he states that — in relation to how many times the algo has crossed up and down through the Zone Recovery area — “the market can stay there all it wants (ranging market) it won’t be there (long)… the most I’ve seen it was 6 (not sure if he means 3 longs and 3 shorts or 6 pairs of long/shorts through the Recovery Zone) in the last 36 months.”
Zone Recovery Hedging:
1st Long
Enter £1.00/tick long at 1.2950 with profit target of 1.3100 (150 ticks).
1st Short
If market falls to 1.2900 enter short at £1.40 tick to target 1.2750.
Zone Recovery between:
1.2950 and 1.2900
2nd Long
Enter £1.00/tick long at 1.2950 with profit target of 1.3100 (150 ticks).
2nd Short
If market falls to 1.2900 enter short at £1.40/tick to target 1.2750.
3rd Long
If market fails to hit 1.2750 enter £1.90/tick long at 1.2950 with profit target of 1.3100 (150 ticks).
3rd Short
If market fails to hit 1.3100 and falls to 1.2900 enter short at £2.50/tick to target 1.2750.
I was wondering what the code would look like for that and jotted out a outline here:
Everything written in parentheses () is were I came unstuck in proreal language coding or am unsure if the outline is stated in the correct terms.
What do you think? Too good to be true? Hit a long term ranging market and run out of margin!?
Cheers
Bard
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter non holidays days
IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) THEN
TradingDay = 0
ELSE
TradingDay = 1
ENDIF
//——————————————————————————————————//
// Conditions to enter FIRST LONG POSITION
IF TradingDay =1 THEN
BUY 1.00 PERPOINT AT MARKET
ENDIF
//set profit target of FIRST LONG POSITION at +150 points
SET TARGET PROFIT 150
// Conditions to enter FIRST SHORT HEDGE
If OnMarket and Tradeprice - Close = -50 ticks (not sure this is right way to express
this but entry needs to be after market crosses under 50 ticks from the first long entry
point) then SELLSHORT 1.40 PERPOINT AT MARKET
ENDIF
//set profit target of FIRST SHORT positions at 150 points
SET TARGET PROFIT 150 (minus -150?)
//——————————————————————————————————//
// Conditions to enter SECOND LONG POSITION
IF TradingDay =1 and OnMarket (and Tradeprice crosses over first long entry price) THEN
BUY 1.00 PERPOINT AT MARKET
ENDIF
//set profit target of FIRST LONG POSITION at +150 points
SET TARGET PROFIT +150
// Conditions to enter SECOND SHORT HEDGE
If OnMarket and Tradeprice - Close = -50 (see comment on first short entry) then
SELLSHORT 1.40 PERPOINT AT MARKET
ENDIF
//set profit target of SECOND SHORT positions at 150 points
SET TARGET PROFIT 150
//——————————————————————————————————//
// Conditions to enter THIRD LONG POSITION
IF TradingDay =1 and OnMarket (and Tradeprice crosses over first long entry price) THEN
BUY 1.90 PERPOINT AT MARKET
ENDIF
//set profit target of THIRD LONG POSITION at +150 points
SET TARGET PROFIT 150
// Conditions to enter THIRD SHORT HEDGE
If Tradeprice - Close = -50 (see comment on first short entry) then SELLSHORT 2.50 PERPOINT AT MARKET
ENDIF
//set profit target of THIRD SHORT positions at 150 points
SET TARGET PROFIT 150
Coded that many times before. It’s also called sure fire hedging. It works ok, like any other martingale if you have infinite money and time 😉
Coded that many times before.
Not in ProRealCode I’m guessing unless you coded separate long and short strategies as it is not possible to be long and short at the same time in a strategy?
Right, as the strategy needs to control both buy and sell orders at the same time. This technique was very popular back in 2010 and before.
I came across a lot of articles recently that deal with it…
BardParticipant
Master
Hi @Nicolas,
If you had a wide Zone Recovery Area (200 or 300 ticks for example) then you could be tied up in position hedges for possibly weeks until a break out occurred. My intention though was to a use R Squared strength in an attempt to avoid those flat periods and take no more than 3 longs and 3 shorts as per the code above – as you say time is finite and tying up capital for weeks wasn’t my goal!
I understand that there would need to be two systems but am not sure how to code it. I have put together the basics below of what I thought it might look like (but it would need separating).
My question is how to code the two systems so that it knows how many trades are active at any one time and therefore it knows when to take the individual 3 long trades and 3 shorts. It will also need to know if a long trade or a short trade has been taken first because of the different position sizes needed depending on whether the first trade is long or short trade.
I’m using a variation of count of positions, although I never got that idea executed with this code below, despite spending hours on it: https://www.prorealcode.com/topic/increase-number-of-position-based-on-30-tic-moves/
I’ve see lots of different examples on PRC and attempted to incorporate those code ideas into this code. The bulk of the idea was written by Maz here: https://www.prorealcode.com/topic/hedging-strategy/
I’m trying to figure out how the two systems would be coded: A long system with a first long trade size of 1 perpoint and last short trade of 2.5 perpoint and code to monitor the long entries and short entries and then another system that is the short system who’s first trade will be 1 perpoint short (instead of 1.4) and who’s last trade will be a long trade at 2.5 perpoint. I was curious to see if this could be an effective strategy?
Cheers
Bard
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter on non holidays days
IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) THEN
TradingDay = 0
ELSE
TradingDay = 1
ENDIF
period=3
stdev=STD[period](close)
//Profit Objective
LongTradeTarget = open + 150
ShortTradeTarget = open + 150
// Position Sizing when Long is First Trade
FirstLongPositionSize = 1.0
SecondLongPositionSize = 1.0
ThirdLongPositionSize = 1.9
FirstShortPositionSize = 1.4
SecondShortPositionSize = 1.4
ThirdShortPositionSize = 2.5
// Position Sizing when Short is First Trade for Second System
//FirstShortPositionSize = 1.0
//SecondShortPositionSize = 1.0
//ThirdShortPositionSize = 1.9
//FirstLongPositionSize = 1.4
//SecondLongPositionSize = 1.4
//ThirdLongPositionSize = 2.5
// Zone Recovery Area Depth
ZRA = 50
if (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) < (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) then
ZRABUY=1
ENDIF
// Conditions to enter long and short positions
RSqr = R2[30](close)
c1 = (RSqr >= 0.3)
if (stdev[0]+stdev[1]+stdev[2]+stdev[3]+stdev[4]) > (stdev[1]+stdev[2]+stdev[3]+stdev[4]+stdev[5]) then
ZRASELL=1
ENDIF
Long1 = TradingDay = 1 and not onMarket
Long1 = Long1 and TradesPlaced = 0
Long1 = Long1 and ZRABUY=1 and c1
Short1 = TradingDay = 1 and not onMarket
Short1 = Short1 and TradesPlaced = 0
Short1 = Short1 and ZRASELL=1 and c1
Long2 = longOnMarket and shortOnMarket and TradingDay = 1 and TradesPlaced = 2 // Not sure how to express the fact that a long and a short trade are active in the market
Long2 = Long2 and not Long1 and abs(countOfPosition) = SecondLongPositionSize
Short2 = shortOnMarket and longOnMarket and TradingDay = 1 and TradesPlaced = 3
Short2 = Short2 and not Short1 and abs(countOfPosition) = SecondShortPositionSize
Long3 = longOnMarket and shortOnMarket and TradingDay = 1 and TradesPlaced = 4
Long3 = Long3 and not Long1 and not Long2 and abs(countOfPosition) = ThirdLongPositionSize
Short3 = shortOnMarket and longOnMarket and TradingDay = 1 and TradesPlaced = 5
Short3 = Short3 and not Short1 and not Short2 and abs(countOfPosition) = ThirdShortPositionSize
if Long1 then
OrderSize = FirstLongPositionSize
BuyOrderLevel = Open // Or is it Tradeprice(1)-ZRA? I wasn't sure how to express this level after the StDev and R Squared have triggered a trade.
StopTarget = LongTradeTarget
endif
if Short1 then
OrderSize = FirstShortPositionSize // Currently 1.4 but the "FirstShortPositionSize" has to be 1 perpoint if it's the first trade.
SellOrderLevel = Open-ZRA
StopTarget = ShortTradeTarget
endif
if Long2 then
OrderSize = SecondLongPositionSize
StopTarget = LongTradeTarget
BuyOrderLevel = Open
endif
if Short2 then
OrderSize = SecondShortPositionSize
StopTarget = ShortTradeTarget
SellOrderLevel = Open-ZRA
endif
if Long3 then
OrderSize = ThirdLongPositionSize
StopTarget = LongTradeTarget
BuyOrderLevel = Open
endif
if Short3 then
OrderSize = ThirdShortPositionSize
StopTarget = ShortTradeTarget
SellOrderLevel = Open-ZRA
endif
// Order Placing
if Long1 or Long2 or Long3 then
buy orderSize perpoint at BuyOrderLevel stop
endif
if Short1 or Short2 or Short2 then
sellShort orderSize perpoint at SellOrderLevel stop
endif
if Long1 or Short1 or Long2 or Short2 or Long3 or Short3 then
set Target pProfit StopTarget
endif
// Keep Track of Open Trades
if onMarket then
if not onMarket[1] then
TradesPlaced = 1
elsif countOfPosition = FirstShortPositionSize then
TradesPlaced = 2
elsif countOfPosition = SecondLongPositionSize then
TradesPlaced = 3
elsif countOfPosition = SecondShortPositionSize then
TradesPlaced = 4
elsif countOfPosition = ThirdLongPositionSize then
TradesPlaced = 5
elsif countOfPosition = ThirdLongPositionSize then
TradesPlaced = 6
endif
endif
When I tried a different entry using Heiken Ashi is red flagged the code: IF XClose >= XOpen THEN ZRABUY=1 endif and also IF XClose <= XOpen THEN ZRASELL=1 endif, although it’s no different code layout wise style to using stdev[0] > stdev[1] etc as an entry?
// Zone Recovery Area Depth
ZRA = 50
IF XClose >= XOpen THEN ZRABUY=1
IF PreviousStatus <> 1 THEN
PreviousStatus = 1
ENDIF
ELSE
IF PreviousStatus <> -1 THEN
PreviousStatus = -1
ENDIF
ENDIF
IF XClose >= XOpen THEN ZRABUY=1
endif
IF XClose <= XOpen THEN ZRASELL=1
endif
// Conditions to enter long and short positions
RSqr = R2[30](close)
c1 = (RSqr >= 0.3)
I don’t recommenced to use 2 strategies to simulate hedging as a desync might happen between the 2 systems and the result could be catastrophic. The main problem is that even if we simulate fake opposite order in both strategy, it doesn’t give you the information that the order was validated by the broker or not and effectively been put on market.
BardParticipant
Master
Right, thanks Nicolas. Curious to know, why does IG allow Force Open (hedging) but PRT doesn’t?
ProBacktest was not designed in the first place to do that. Hedging is not a “normal” or “logic” situation in trading/investment, not a natural way, that’s why I think it was not considered, back at the beginning of the 2000’s when ProBacktest was created.