I tried this :
if close[val]>0 and close[val]<close[val[1]] and close[val[1]]>0 and close[val[1]]>close[val[2]] then
IF LONGONMARKET THEN
SELL 1 SHARES AT MARKET
SELLSHORT 1 SHARES AT MARKET
ELSE
SELLSHORT 1 SHARES AT MARKET
ENDIF
ENDIF
if close[val]<0 and close[val]>close[val[1]] and close[val[1]]<0 and close[val[1]]<close[val[2]]then
IF SHORTONMARKET THEN
EXITSHORT 1 SHARES AT MARKET
BUY 1 SHARES AT MARKET
ELSE
BUY 1 SHARES AT MARKET
ENDIF
ENDIF
but still doesn’t work…
How about below, also try including volume also?
if Close > average[200](close) AND close[val]<0 and close[val]>close[val[1]] and close[val[1]]<0 and close[val[1
Ok, I finally made it work my way, then I added your code (+5% win ratio), then I added volume, it didn’t change much, same thing for volatility.
I’ve got good %win ratio but awful win/loss ratio, any idea how to improve this ?
What about adding a momentum indicator, e.g. Chande Momentum Index or similar; RSI maybe??
OK, eventually I filtered it with supertrend extended (see attached), looks better now, I’ll try to push it.
Here’s the code :
a = 89 (sl)
b = 28 (tp)
c = 20
d = 1
// Trend Surfer DAX Modified
DEFPARAM CumulateOrders = False
// code-Parameter
DEFPARAM FlatBefore = 080500
DEFPARAM FlatAfter = 180000
// DAX trading window
ONCE BuyTimeMorning = 080500
//ONCE SellTimeMorning = 110000
//ONCE BuyTimeAfternoon = 130000
ONCE SellTimeAfternoon = 173000
// trading parameter
ONCE sl = a
ONCE tp = b
ONCE lengthKC=20
// position management during trading window
IF (Time >= BuyTimeMorning AND Time <= SellTimeAfternoon) THEN
value = (Highest[lengthKC](high)+Lowest[lengthKC](low)+average[lengthKC](close))/3
val = linearregression[lengthKC](close-value)
indicator1, ignored = CALL "PRC_SuperTrend Extended"[2.236, 66, 1, 10]
ignored, indicator2 = CALL "PRC_SuperTrend Extended"[2.236, 66, 1, 10]
c1 = (indicator1 < indicator2)
c2 = (indicator1 > indicator2)
if val>0 and val[1]>0 and val[2]>0 and val<val[1] and val[1]>val[2] and c2 then
IF LONGONMARKET THEN
SELL 1 SHARES AT MARKET
SELLSHORT 1 SHARES AT MARKET
ELSE
SELLSHORT 1 SHARES AT MARKET
ENDIF
ENDIF
if val<0 and val[1]<0 and val[2]<0 and val>val[1] and val[1]<val[2] and c1 then
IF SHORTONMARKET THEN
EXITSHORT 1 SHARES AT MARKET
BUY 1 SHARES AT MARKET
ELSE
BUY 1 SHARES AT MARKET
ENDIF
ENDIF
StopdistanceBreakeven = c
NormalStop = sl
nb = barindex - tradeindex
minprice = lowest[nb + 1](Low)
maxprice = highest[nb + 1](High)
If longonmarket then
If maxprice >= positionprice + StopdistanceBreakeven then
sell at (positionprice + 1 ) stop
else
sell at positionprice - NormalStop stop
endif
endif
If shortonmarket then
If minprice <= positionprice - StopdistanceBreakeven then
exitshort at (positionprice - 1) stop
else
exitshort at positionprice + NormalStop stop
endif
endif
// stop and profit
//SET STOP pLOSS sl
SET TARGET pPROFIT tp
ENDIF
chears !
i just saw that i tested it on 10 000 bars, its still good thow, but not so good…
Again, it doesn’t do what I want, which also means it can be even more profitable.
See picture attached, any suggestions are welcome.
I cooked another one that seems to work : ut 2min, trades on TDI overbought/oversold.
Neutral trades are in fact winners of 1 pip (spread + 1)
Here is an other one, much more profitable, based on moving avegerage 50 and 500 (optimized) crossing.
Sometimes, the simpler, the better. I can’t go back further 3 months thow…
Even better if we make it swinng trading.
Hi again !
I’m trying to make some tweaks on the last code I posted, but I need help…
I took nicolas’ trailing code here https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
I’m keeping the break even part, but I want the trailing step to be the last high or low (if we go short or long) of “n” or “m” periods (n and m being different for long or short and to be optimized).
here’s what I changed, but it doesn’t seem to work :
trailingstart = 39
clow = tradeprice - (lowest[m](low))
chigh= (highest[n](high))-tradeprice
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+clow*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=clow*pipsize THEN
newSL = newSL+clow*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-chigh*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=chigh*pipsize THEN
newSL = newSL-chigh*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
GRAPH newSL as "trailing"
It is defined to 39, I missed it when I copied/pasted the code, I edited the post to correct that, sorry
Aha I thought my eyes were deceiving me so I nipped in and deleted my comment re the Trailingstart! 🙂 🙂
Have you use GRAPH to see what the value of tradeprice – (lowest[m](low)) is? Because if it is > Trailing start then it wouldn’t work anyway??
ok I am going to look closer, I ‘ll report back when I shall find the error.
Meanwhile, I added pyramiding code I founded in nicolas’ advanced training videos,
I tweaked it so that position size increases also after a win (and not just deacreases after a loss).
Win/loss ratio jumped from 4,73 to 5,71.
here’s the code to put at the begining :
taille=1
for i = 1 to 2 do
if positionperf(i)<0 then
taille=taille-1
else
if taille<5 then
taille=taille+1
endif
endif
next
Please could you put your latest full code on here and then I can see if I can offer any improvements, but doubt I will as you are doing great on your own … your code has done me well today!
Thank You
GraHal