ProRealCode - Trading & Coding with ProRealTime™
Hello Guys having a little fortune this strategy could make money for a period, but as we know it is very dangerous. I’d like to share this code to ask you if someone could apply some intelligent money management.
Thanks Ale
name of the indicator to call :indicator “Universal 30”
name of the indicator to call indicator: “divergenze”
Strategy: DAX CFD 1€ _ 1 Minute_
// Funzione : universal 30
//-------------------------------------------------------------------------
bandedge= 15
whitenoise= (Close - Close[6])
if barindex>bandedge then
// super smoother filter
a1= Exp(-1.414 * 3.14159 / bandedge)
b1= 2*a1 * Cos(1.414*180 /bandedge)
c2= b1
c3= -a1 * a1
c1= 1 - c2 - c3
filt= c1 * (whitenoise + whitenoise[1])/2+ c2*filt[1] + c3*filt[1]
filt1 = filt
if ABS(filt1)>pk[1] then
pk = ABS(filt1)
else
pk = 0.994 * pk[1]
endif
if pk=0 then
denom = -1
else
denom = pk
endif
if denom = -1 then
result = result[1]
else
result = filt1/pk
endif
endif
RETURN result COLOURED(66,66,255) as "Universal Oscillator", 0 as "0"
// DIVERGENCES STO PRC adapted from HK-LISSE code
x = stochastic[5,3]
y = average[3](x)
if x>80 then
hi=max(hi,x)
hico=max(hico,max(high,high[1]))
endif
if x crosses under y then
sto2b=sto1b
sto1b=hi
hi=0
p3b=p1b
p2b=max(p1b,hico1)
p1b=max(highest[3](high),hico)
if p2b=p1b then
p2b=max(p3b,p4b)
endif
hico=0
hico1=0
endif
if x<y then
p4b=hico1
hico1=max(hico1,high)
endif
if p1b>p2b and sto1b<sto2b and x crosses under y and x<x[1] then
signB= -2
else
signB= 0
endif
if x<20 then
lo=min(lo,x)
lowco=min(lowco,min(low,low[1]))
endif
if x CROSSES OVER y then
sto2h=sto1h
sto1h=lo
lo=100
p3h=p1h
p2h=min(p1h,lowco1)
p1h=min(lowest[3](low),lowco)
if p2h=p1h then
p2h=min(p3h,p4h)
endif
lowco=100000
lowco1=100000
endif
if x>y then
p4h=lowco1
lowco1=min(lowco1,low)
endif
if p1h<p2h and sto1h > sto2h and x crosses over y and x>x[1] then
signH= 2
else
signH= 0
endif
////////////////////////////////////////////////
If signB CROSSES UNDER 0 then
DRAWTEXT ( "S " ,barindex,- 0.20,dialog,standard,20) coloured ( 255,0,127 )
DRAWTEXT ( "T " ,barindex,- 0.30,dialog,standard,20) coloured ( 255,0,127 )
DRAWTEXT ( "O " ,barindex,- 0.40,dialog,standard,20) coloured ( 255,0,127 )
endif
If signH CROSSES OVER 0 then
DRAWTEXT ( "O " ,barindex,0.20,dialog,standard,20) coloured ( 0,153,0 )
DRAWTEXT ( "T " ,barindex,0.30,dialog,standard,20) coloured ( 0,153,0 )
DRAWTEXT ( "S " ,barindex,0.40,dialog,standard,20) coloured ( 0,153,0 )
endif
return signH as " div STO bull ", signB as " div STO bear " , 0 as " zero "
// Variables :
// p = 5
// Overboughzone = 80
// Oversellzone = 20
// K = 3
// D = 3
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = true // Posizioni cumulate disattivate
defparam flatafter=183000
defparam flatbefore=090000
indicator3, ignored, ignored = CALL Divergenze(close)
c7 = (indicator3 > 0)
c8 = (indicator3 < 0)
// Condizioni per entrare su posizioni long
indicator1, ignored = CALL "universal 30"
c1 = (indicator1 <= -1)
c2 = (close < open)
c3 = (low < low[1])
IF c1 AND c2 AND c3 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Condizioni per entrare su posizioni short
c4 = (indicator1 >= 1)
c5 = (close > open)
c6 = (high > high[2])
IF c4 AND c5 AND c6 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
if longonmarket and c7 then
buy 1 contract at market
endif
if shortonmarket and c8 then
sellshort at market
endif
if longonmarket and (close>positionprice) then
sell at market
endif
if shortonmarket and (close<positionprice-2) then
exitshort at market
endif
Hi Ale. Looks interesting. very good test results but to make a money management we need only to look at how much you are risking. Not having looked into the code, can you predict how much you are risking?
Cheers Kasper
Hi Kasper
I’ don’t know, My first problem is that in the last six month dax doesn’t burden this strategy, but as we know this kind of strategies are a pineapple.
So the way may be to start with 2000€/3000€ and every month take profits until the break even point, then we are survived, then we are gain and every month no reinvest profit but we will use it to manage future drawdown, and so on.
If everithing go ok, then we will have a long period to better strategy.
thanks
Ale
Hey Ale,
Thanks for sharing, it looks like an interesting strategy but could you please explain in more detail how it it intended to make money?
I installed the indicators and backtested the strategy but I’m confused about the intentions with the settings for the cumulative orders since orders are added when price is going the wrong way and the exit only seem to kick in for profits but not for stop loss.
I also tried running it on the DOW for reference, it had a 94 % win rate but yestereday it would have build up a position of 12 short contracts while the price kept rising and wiping out 20 % of the account in a few hours.
FYI and comprehension of what Ale is talking about “a grid”, you can read my article about averaging down in the blog :
Averaging down
Great blog post! I’m familiar with averaging down since earlier on, I just to swing trade H4 charts increasing my position size for each entry, in demo I made a 1000 % profit in 6 months on my real account I made about 25 % a month for two months then… I got my first and so far last margin call. That was manual trading which creates a lot of psychological pressure which we can easily eliminate here.
Anyway we should be able to make major improvements for this strategy by modifying the following features of the grid code;
I started integrating the codes, the below is a long only draft but no trades in the backtest, I wouldn’t have been surprised if the grid step didn’t work but I can’t figure out why there is no first trade taken on DAX 1m for the past week since the original code takes a few trades.
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = true // Posizioni cumulate disattivate
defparam flatafter=183000
defparam flatbefore=090000
indicator3, ignored, ignored = CALL Divergenze(close)
c7 = (indicator3 > 0)
//c8 = (indicator3 < 0)
once RRreached = 0
accountbalance = 10000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
amount = 1 //lot amount to open each trade
rr = 5 //risk reward ratio (set to 0 disable this function)
sd = 0.25 //standard deviation of MA floating profit
//dynamic step grid
minSTEP = 3 //minimal step of the grid
maxSTEP = 20 //maximal step of the grid
ATRcurrentPeriod = 150 //recent volatility 'instant' period
ATRhistoPeriod = 3000 //historical volatility period
ATR = averagetruerange[ATRcurrentPeriod]
histoATR= highest[ATRhistoPeriod](ATR)
resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
resultMIN = MIN(resultMAX,maxSTEP*pipsize)
gridstep = (resultMIN)
// Condizioni per entrare su posizioni long
indicator1, ignored = CALL "universal 30"
c1 = (indicator1 <= -1)
c2 = (close < open)
c3 = (low < low[1])
IF c1 AND c2 AND c3 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// case BUY - add orders on the same trend
if longonmarket and (c7)=1 and tradeprice(1)-close>=gridstep then
BUY amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
endif
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[20](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*sd
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
//stoploss trigger when risk reward ratio is not met already
if longonmarket and RRreached=0 and (close>positionprice) then
sell at market
endif
if onmarket and RRreached=0 then
SELL AT positionprice-mindistancetoclose STOP
endif
if longonmarket and (close>positionprice) then
sell at market
endif
//stoploss trigger when risk reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
SELL AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
Hello Cfta,
I knew that if I called you, you would have done a great job.
It’s very interesting use of ATR and grid step order.
If you will have time to work on the short position, it will be veri interesting to know result. Thanks in advance!
@Casper have you some good idea of yours?
Thanks you all
PS: The name of this strategy could be:”To walk on thin ice” :-))
Hi guys. I have been puzzling with this in my head- between my family and other busy work schedule. I really like your 1 min strategy, and I also see that you in some way are using the avenging down strategy- adding position to a loosing trade. Because that’s what it is. It can be highly profitable, BUT also like CFTA I had a margin call- several times using this strategy in Manuel trading. It actually led to cancel one of my account and go into a thinking box- deciding weather or not I should trade at all.
I read the avenging down post a while ago, and I also listen to various webinars. One thing is clear. never add to a loosing trade and martin gale systems will eventually lead to ruin. It’s a mathematically fact. However can we limit it- say 3 steps within a certain pip range, or whatever we like? But I see that you are adding position according to the indicators.
So I came up with the ultimate money management for you system.. are you ready…. 😛
BOOM!!!
Cheers Kasper 😀
//=====The KISS Money management
set stop loss 100
warning I might be chicken out here:-)
Now we know the stoploss we can look at how much we are risking, and also what our Risk/Reward is. One of the thinks I’ve learned- is that these thinks are important when trading. I have added some position management code. it well know in the site.
The important thing is we know the stoploss and how many positions we have at each trade. then we know the risk. If we also know the winnings, we have the RR.
Risk[%]=numbers of positions*stoploss/equity*100
RR=winnings/risk
I have graphs it in the code. So lets try and see what we have.
Equity=10122
A random Trade ending op with 2 position we risk 1.9%. (200/10122*100=1.9)
we win 12.8 Euro
RR=12.8/(10122*0.019)
RR=0.06
Also I graphed the max-risk recorded as being 9,4% for a trade at one point
I don’t want to disappoint you on your strategy, but it is a very high risk code- even with a capital start at 10000 Euro- but it’s very profitable.. at least for now. High risk=High Gains.
but in the end it’s up to every individual to accept the risk, but at good start is knowing how much we are risking.
Best Regards Kasper
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = true // Posizioni cumulate disattivate
defparam flatafter=183000
defparam flatbefore=090000
//============================
reinvest=1
//REM Money Management
if reinvest then
Capital = 10000
Risk = 0.01//pr position
StopLoss = 100 // Could be our variable X
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
Maxpositionsize=625
Minpositionsize=1
Positionsize = MAX(Minpositionsize,MIN(Maxpositionsize,abs(round((maxrisk/StopLoss)/PointValue)*pipsize)))
else
Positionsize=1
endif
indicator3, ignored, ignored = CALL Divergenze(close)
c7 = (indicator3 > 0)
c8 = (indicator3 < 0)
// Condizioni per entrare su posizioni long
indicator1, ignored = CALL "universal 30"
c1 = (indicator1 <= -1)
c2 = (close < open)
c3 = (low < low[1])
IF c1 AND c2 AND c3 THEN
BUY Positionsize CONTRACT AT MARKET
ENDIF
// Condizioni per entrare su posizioni short
c4 = (indicator1 >= 1)
c5 = (close > open)
c6 = (high > high[1])
IF c4 AND c5 AND c6 THEN
SELLSHORT Positionsize CONTRACT AT MARKET
ENDIF
if longonmarket and c7 then
buy Positionsize contract at market
endif
if shortonmarket and c8 then
sellshort at market
endif
if longonmarket and (close>positionprice) then
sell at market
endif
if shortonmarket and (close<positionprice-2) then
exitshort at market
endif
ONCE maxriskrecorded=0
If onmarket then
maxriskrecorded=ABS((COUNTOFPOSITION*stoploss*pipsize*pointvalue/equity)*100)
if maxriskrecorded<maxriskrecorded[1]then
maxriskrecorded=maxriskrecorded[1]
else
maxriskrecorded=maxriskrecorded
endif
endif
if not onmarket then
winnings=StrategyProfit-StrategyProfit[1]
else
winnings=0
endif
riskprtrade=abs(COUNTOFPOSITION*stoploss*pipsize)
RR=winnings/riskprtrade[1]
set stop loss 100
graph abs((COUNTOFPOSITION*stoploss*pipsize*pointvalue/equity)*100) COLOURED(0,255,255) AS "MAXRISK%"
graph maxriskrecorded COLOURED(0,255,0) AS "maxrisk%recorded"//Aqua
graph RR COLOURED(255,255,0) AS "rr"//Aqua
graph winnings COLOURED(255,255,0) AS "winnings"//Aqua
Hello guys, thank you for your very appreciated attention, this strategy has no future, as all grid strategies, although I must admit it is very pretty, and it is worthy of attention and study. Research is very exciting for us traders, but we agree that to make money it takes attention, and patience, otherwise we are just gamblers. I posted here because I knew that you would have stimulated your search, and thanks to your ability we could have found some very fascinating results. The results of this strategy are temporary, but they are the dream of every trader, and dreams push humans beyond their limits. Thanks you all
Thanks ALE, It’s very hard to come to this conclusion, specially when the numbers in back test are this good. I must say I was very tempted to trade it live, but an RR=0.06 and a possible risk on 10% I think it would be vice not to. I will be looking forward for your next strategy *thumbs-up
Cheers Kasper
Thanks Kasper!
just for fun, i would like to test it in demo. When i want to launch it in autotrading, i have the following message “graph instruction can not be used in autotrading”. I’m with PRT10.3. What is the modification to do, Kasper? Thanks
Hi Winnie.. place // in front of the Graph lines- then it will work.
Graph instructions are only for backtesting
I am testing it in Demo as well. don’t be fooled. it has already made 120 Euro this week. But 3 bad trades in a row will blow your account- you will never know when it will come
Cheers Kasper
lol. Funny to test but can be dramatic 🙂 Even with a 10K account? what’s the max drawdown?
Surely better to stay on Patfinder 😉
request of money management for a Grid strategy
This topic contains 32 replies,
has 7 voices, and was last updated by Vonasi
8 years ago.
| Forum: | ProOrder support |
| Language: | English |
| Started: | 02/04/2017 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.