LeoParticipant
Veteran
Hi all,
I got an idea thanks to GraHal in another conversation and I could not go to sleep without testing.
After several attempts I got very nice code.
I do not even let it run complete but please test it wherever and at whichever time frame
LeoParticipant
Veteran
I call it Pseudo stochastic because I sue the same period for calculate the three variables that define the stochastic.
//STOCHASTIC TRADE v1.0
//Autor: LEO
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM PreLoadBars = 10000 //cargar informacion
//VARIABLES TO BE OPTIMIZED
//Ps=21 //preiod for stochastic values
//Slevel= 20 //stochastic signal
//Pactive=3 //bars after stochastic signals
//Kp=2 // Profit target to Kp times the stop loss
//Psma=200 //Period for a SimpleMoving Average
maxrisk0=20 //pips per trade to risk
n=1
maxrisk=maxrisk0+(n-1)*2
totalrisk=10*maxrisk*PIPVALUE //for stop the robot if things are going bad
spread=0.7
IF TIME < 060000 THEN //(germany time)
spread=1.7*spread
ELSIF TIME>214500 THEN //(germany time)
spread=1.7*spread
ENDIF
//Robot Working Time (Germany)
IF TIME>050000 and TIME < 220000 THEN
ontime=1
ELSE
ontime=0
ENDIF
////// RISK CONTROL IF THINGS ARE GOING WONDERFULL //////
//n = 1 + (strategyprofit / (77*pipvalue))
//n = round(n * 100)
//n = n / 100
//n = max(1,n)
//--------------------------------------------------------
//>>>>>>>>>>>>>>>>>> INDICATORS <<<<<<<<<<<<<<<<<<<<<
//--------------------------------------------------------
SMA=average[Psma](close)
TYPICALDAY=(DHIGH(1)+DLOW(1)+Dclose(1))/3
mystoch=Stochastic[Ps,Ps](close)
StochD=Average[Ps](myStoch)
//--------------------------------------------------------
//>>>>>>>>>>>>>>>>>> TRADING <<<<<<<<<<<<<<<<<<<<<
//--------------------------------------------------------
a0=myStoch crosses over StochD
a1=highest[Pactive](a0)=1
a2=lowest[Pactive+1](mystoch) < Slev
a3=close > TYPICALDAY
a4=close > SMA
If a1 and a2 and a3 and a4 then
IF NOT LongOnMarket AND ontime=1 and DayOfWeek <= 5 THEN
//entrylong=high+0.5*spread*pipsize
stoplosslong=(close-lowest[Ps](low))/pipsize+spread
stoplosslong=min(stoplosslong,maxrisk)
BUY n CONTRACTS AT market//entrylong STOP
SET STOP pLOSS stoplosslong
SET TARGET pPROFIT Kp*stoplosslong
ENDIF
ENDIF
b0=myStoch crosses under StochD
b1=highest[Pactive](b0)=1
b2=highest[Pactive+1](mystoch) > 100-Slev
b3=close < TYPICALDAY
b4=close<SMA
IF b1 and b2 and b3 and b4 then
//entryshort=low-0.5*spread*pipsize
stoplossshort= (highest[Ps](high)-close)/pipsize+spread
stoplossshort= min(stoplossshort, maxrisk)
IF NOT ShortOnMarket AND ontime=1 and DayOfWeek <= 5 THEN
SELLSHORT n CONTRACTS AT market //entryshort STOP
SET STOP pLOSS StopLossShort
SET TARGET pPROFIT Kp*StopLossShort
ENDIF
ENDIF
//---------------------------------------------------------
//>>>>>>>>>>>>>>>>>> EXIT POSITIONS <<<<<<<<<<<<<<<<<<
//---------------------------------------------------------
mySAR=SAR[0.007,0.007,0.7]
// ---> exit long
IF longonmarket then
IF close < lowest[Ps](low[1]) THEN
SELL AT MARKET
ENDIF
IF close crosses under MySAR THEN
SELL AT MARKET
ENDIF
IF b0 and close>POSITIONPRICE THEN
SELL AT MARKET
ENDIF
IF close > (POSITIONPRICE+0.5*stoplosslong*pipsize) and close>mySAR then
SET STOP pLOSS min((close-MySAR)/pipsize+2*spread, maxrisk)
ENDIF
IF TIME > 224500 and DayOfWeek=5 then
SELL AT MARKET
ENDIF
endif
// ---> exit long
IF shortonmarket then
IF close > highest[Ps](high[1]) THEN
EXITSHORT AT MARKET
ENDIF
IF close crosses over MySAR THEN
EXITSHORT AT MARKET
ENDIF
IF a0 and close < POSITIONPRICE then
EXITSHORT AT MARKET
ENDIF
IF close < (POSITIONPRICE-0.5*StopLossShort*pipsize) and close<mySAR then
SET STOP pLOSS min( (MySAR-close)/pipsize+2*spread , maxrisk)
ENDIF
IF TIME > 224500 and DayOfWeek=5 then
EXITSHORT AT MARKET
ENDIF
endif
//Quit the robot if things are going bad
Q=MAX(Q,(STRATEGYPROFIT/pipvalue/n))
R=Q-STRATEGYPROFIT/pipvalue/n
IF R > totalrisk THEN
QUIT
ENDIF
IF STRATEGYPROFIT < (-1*totalrisk) THEN
QUIT
ENDIF
@Leo
Sorry for delay, I’ve been busy doing family jobs today, but I wish I’d set it going / optimising while I was doing other stuff! 🙂
Even early results (over 90% yet to do) look good!!!
Does v1.1 supercede V1.0 as I was going to run both to see the improvement, but I may as well kill v1.0 and optimise v1.1?
Many Thanks
GraHal
Attached V1.1 on eurusd @ 5 min over 100k bars @ £1 per point SB
Just a couple of thoughts … most of the gain is made by 4 or 5 trades (out of 25 winning) and most of the losing trades don’t lose much … hence the long flattish periods.
Maybe a time condition might help?
More tomoz maybe
Cheers
GraHal
LeoParticipant
Veteran
Hi, GraHal,
v1.1 use two average for filtering.
I do not know what else to do for filter those losing trading
V1.1 on DJI @ 1Min TF over 100,000 bars.
Clearly a lot of the gain was made during that big drop and retrace early Feb, but it was both Long and Short during that time and volatile times could be here to stay for a while?
I’ve set it Live but will monitor each trade as soon as it is triggered.
Cheers
GraHal
PS variable settings can seen in the image
I do not know what else to do for filter those losing trading
I made some improvements that increase the ratio Gain / Loss and therefore the yield on DJI Indice.
I used the TF28s, if that does not suit you an optimization of variables is possible with a TF1mn or other.
cordially
Gertrade
LeoParticipant
Veteran
Gertrade your are becoming a legend in the 28 second time frame!
I test exactly your code in EUR/USD and is also profitable.
You have two set of variables, can you tell me please how is your method for optimising those variables
Thanks
You have two set of variables, can you tell me please how is your method for optimising those variables
Thanks for the legend TF28s!
For the variables I realized that the variables could be different when one is above or below the equity curve.
To save time, I do not like you optimize all the variables together, I optimize each variable individually on 20,000 units (maximum history on TF28s).
I am at your disposal if you have any other questions.
cordially
Gertrade
Hi Leo,
I just finished v1.14 for the EURUSD, I did some optimization of variables and I improved the code to increase the yield. I remain faithful to the TF28s to preserve the legend Gertrade.
below the v1.14 on TF28s for the EURUSD.
@Leo you’ve started something now! 🙂
I thought at one point a few days ago I was just about steering Gertrade off the ‘maverick’ timeframe 28 Sec … but no chance now he’s the Legend! 🙂
I see you’ve gone back to the (unrealistic) eurusd 0.7 spread though Gertrade? I thought you’d convinced yourself that spread of 2 is more realistic on eurusd?
I thought you’d convinced yourself that spread of 2 is more realistic on eurusd?
This is an oversight, I am convinced that the Spread of 0.7 is not realistic, but as Leo had treated it with a piece of code, I left like that.
I launched this v1.14 EURUSD strategy on ProOrder Demo Account, I wait to see the first results to make a comparison with the backtests.
The DJI v1.13 strategy on ProOrder Demo Account is profitable and I am fully satisfied (I’m still waiting a few days to publish results).
Hi everybody,
Already 1 week have passed and I publish you my first results of the DJI v1.13 (on CFD Wall Street Cash 2 $) on ProOrder Demo Account. It is very encouraging to see this equity curve grow. Long live this strategy !!! She seems to me robust. I will post other results of the equity curve week after week.
cordially
Gertrade
LeoParticipant
Veteran
Cool! Looks very nice indeed!