Hi everyone!
This strategy buy or sell if price breaks max or min night range with an “spread” difference (optimized by variable “s”), and then is stopped at SAR crosses.
It has money-management included, system will calculate risk before setting up orders and join with the contracts updated with “STRATEGYPROFIT” var.
I’m thinking to trade it real mode and maybe you could help me to improve it, is my really first one you know…
Best wishes!
REM Cumulate orders
DEFPARAM CumulateOrders=true
REM Operative time
DEFPARAM FlatBefore = 090000
DEFPARAM FlatAfter = 212900
REM Indicadores
parabolic = SAR[0.02,0.02,0.2]
REM Variables
maximo = Highest[4](high)
minimo = Lowest[4](low)
ultimotrade = BARINDEX-TRADEINDEX
REM Condiciones
C1 = PARABOLIC>HIGH
C2 = PARABOLIC<LOW
C3 = uLtimotrade>1
if time=080000 then
maximoN=dhigh(0)
minimoN=dlow(0)
endif
REM CONFIGURACION DE ESTRATEGIA
REM GESTION MONETARIA
REM Cálculo de contratos a operar
capitalinicial = c //Capital
riesgo = r // riesgo por operación
spread = s
equity = capitalinicial+strategyprofit
maxriesgo = round(equity*riesgo)
pipstop = abs(round(maximo-minimo))
myLOT = abs(round(((maxriesgo/pipstop)/PointValue)*pipsize))
if mylot<1 then
mylot=1
else
myLOT = abs(round(((maxriesgo/pipstop)/PointValue)*pipsize))
endif
REM PRIMERA COMPRA
IF TIME>=090000 AND TIME<=094500 AND NOT ONMARKET AND C3 THEN
REM ENTRAR AL MERCADO DENTRO DEL RANGO
IF CLOSE<maximoN and CLOSE>minimoN and c1 then
sellshort myLOT contract at minimoN-spread*pipsize stop
buy myLOT contract at parabolic+spread*pipsize limit
ENDIF
IF CLOSE<maximoN and CLOSE>minimoN and c2 AND C3 then
sellshort myLOT contract at parabolic-spread*pipsize stop
buy myLOT contract at maximoN+spread*pipsize limit
ENDIF
REM ENTRAR AL MERCADO POR ENCIMA DEL RANGO
IF CLOSE>maximoN and c2 AND C3 then
buy myLOT contract at market
endif
REM ENTRAR AL MERCADO POR DEBAJO DEL RANGO
IF CLOSE<minimoN and c1 AND C3 then
sellshort myLOT contract at MARKET
endif
ENDIF
rem si estoy largo
if longonmarket and c1 AND C3 then
breakeven = minimo
SELLSHORT AT minimo STOP
endif
if longonmarket and c2 AND C3 then
breakeven = parabolic
sellSHORT at breakeven-spread*pipsize stop
endif
rem si estoy corto
if shortonmarket and c1 AND C3 then
breakeven = parabolic
BUY at breakeven+spread*pipsize stop
endif
if shortonmarket and c2 AND C3 then
breakeven = maximo
BUY at breakeven+spread*pipsize stop
endif
No confusing closes at bar 0. +info
You must be logged in to post a comment.
Hi Adolfo, big thank you for your code, but I am a bit confused.
Spread is the difference between Buy Price and Sell Price and is what the Market-Maker (for example IG) makes on the round trip of selling me an instrument and then buying it back again.
You say above that Variable 'S' / Spread is the distance you want to wide orders ... please could you explain / expand on what you mean?
Or anybody else who might understand this ... please could you enlighten me?
Many Thanks
GraHal
Ups! Sorry. Variable "S" is to set an specific Spread if needed. Could be "0", or the distance you want to wide orders.
Hi, fisrtly thanks for your interest on it. :)
Variable "c" is to set your initial capital (i.e. 1000€)
"r" is to set the maximum risk percentage we want (i.e 0,03)
and "s" is the maximum stop loss distance in pips.
Hope it helps you!
Adolfo
Ups, how can edit posted code? Can I?
This strategy at 08:00h GMT+1 sets a max/min range at highs and lows (dhigh,dlow). At 09:00h set stop orders at dhigh/dlow stop +/- Spread ( variable to set how many points away the limit we set the orders), if price is still into the range. At this step orders are placed and waiting to be executed.
If price already breaks those limits, the inmediatly join the market with "AT MARKET" orders. After that, a cross over or under "SAR" (parabolic SAR indicator price) will stop positions.
PIPSTOP = distance between recent highs and lows (last hour), in order to set an emergency STOP pLOSS.
Also included money management, you can set your initial capital and your desired % of risk in variables "capital" and "riesgo".
Already now i'm very excited while working with the next version of this system, with a "JACKPOT" profit objective! I want to ear your questions, thanks!
Adolfo
Yes! I will, after dinner :)
Hi gutta11!
Should be more because our timezones are different? System is tested at GMT+1.
I don't know why you get this results, maybe we will find some help from our bests pro's!
Adolfo.
Hi Doctrading!
Then you would like to see this:
REM INDICATOR
mySAR = SAR[0.02,0.02,0.2]
REM CONDITIONS
c1 = mySAR >= High
c2 = mySAR <= Low
IF Not OnMarket THEN
IF c1 THEN
BUY 1 CONTRACT AT mySAR STOP
ENDIF
IF c2 THEN
SELLSHORT 1 CONTRACT AT mySAR STOP
ENDIF
ENDIF
IF LongOnMarket THEN
mySTOP = mySAR
IF Close >= TradePrice(1) THEN
mySTOP = mySAR
SELLSHORT AT mySTOP STOP
ELSE
SELLSHORT AT mySTOP STOP
ENDIF
ENDIF
IF ShortOnMarket THEN
mySTOP = mySAR
IF Close <= TradePrice(1) THEN
mySTOP = mySAR
EXITSHORT AT mySTOP STOP
ELSE
EXITSHORT AT mySTOP STOP
ENDIF
ENDIF
Very funny results on DAX last year :)
Hello,
Nice code, I was just looking to make a similar code on Parabolic SAR !
Hello, I'm glad to see it published!
505 Trades, also added a screenshoot with detailed report
http://www.prorealcode.com/wp-content/uploads/2015/07/Informe-detallado-1-Breakout-djia-15m.png
Hi, For me there is a mistake here L32 maxriesgo = round(equity*riesgo) => round(equity*(riesgo/100)