defparam cumulateorders = false
n=2
soglia = 0.02
timestart = 90000
timeend = 180000
profitti = 275
perdite = 350
timeok = time>=timestart and time<=timeend
c = (sin(atan((close-open[n])/open[n]*100/n)))
if c crosses over soglia and timeok then
buy 1 contract at market
endif
if c crosses under -soglia and timeok then
sellshort 1 contract at market
endif
set target pprofit profitti
set stop ploss perdite
Thanks again Francesco, any WFA to share for this one?
Ok but the optimized variables in your first post are the ones found for a 100% IS optimization? Better to know and explain in the post because people will ask a lot of questions 🙂
Hello Francesco,
Thank you again for another contribution. It is really appreciated.
I have a question, do you optimise all of the data or do you use in-sample and out-of-sample?
Best regards
The first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
defparam cumulateorders = false
n=2
soglia = 0.02
timestart = 90000
timeend = 180000
profitti = 275
perdite = 350
timeok = time>=timestart and time<=timeend
c = (sin(atan((close–open[n])/open[n]*100/n)))
if c crosses over soglia and timeok then
buy 1 contract at market
endif
if c crosses under –soglia and timeok then
sellshort 1 contract at market
endif
set target pprofit profitti
set stop ploss perdite
|
is optimized over the whole set of data.
the second post shows walk forward 75/25
Hope this answer your question
Regards
Ciao, i had very different result with 200k bars, but anyway i changed something in the code.
i have 2 questions
in this function
c = (sin(atan((close–open[n])/open[n]*100/n)))
i never seen the command SIN AND ATAN what are they? and how you found them? i the function search of PRT they aren’t presents. Thank you.
This is my version of your code, hoping could help.
defparam cumulateorders = false
//1/TRAILING STOP//////////////////////////////////////////////////////
once trailinstop= 1 //1 on - 0 off
trailingstart = 100 //trailing will start @trailinstart points profit
trailingstep = 60 //trailing step to move the "stoploss"
///2 BREAKEAVEN///////////
once breakeaven = 1 //1 on - 0 off
startBreakeven = 50 //how much pips/points in gain to activate the breakeven function?
PointsToKeep = 30 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
n=2
soglia = 0.01
sogliashort=-0.06
timestart = 90000
timeend = 180000
profitti = 165
entratalong=0
entratashort=0
timeok = time>=timestart and time<=timeend
c = ((sin(atan((close-open[n])/open[n]*100/n)))*100)+close
c2 = (sin(atan((close-open[n])/open[n]*100/n)))
graphonprice c
if c>close and c2 > soglia and timeok then
entratalong=high+1*pipsize
sl = (entratalong - low) / pipsize
buy 1 contract at entratalong stop//market
entratalong=0
set target pprofit profitti
set stop ploss sl+10
endif
if c<close and c2<sogliashort and timeok then
entratashort=low-1*pipsize
sl = (high - entratashort) * pipsize
sellshort 1 contract at entratashort stop
entratashort=0
set target pprofit profitti
set stop ploss sl+10
endif
///1///////////////////////////////////////////////
//reset the breakevenLevel when no trade are on market
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
//2////////////////////////////
//test if the price have moved favourably of "startBreakeven" points already
if breakeaven>0 then
IF onmarket AND close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
endif
//************************************************************************
//trailing stop function
if trailinstop>0 then
//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)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*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)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
endif
[attachment file=”89168″]
[attachment file=”89169″]
Ciao Francesco, I have added a trailing stop to your code which seems to help but I’m unclear about the WFE. See the screen shots below, does this look over-optimized?
This is my version:
defparam cumulateorders = false
n=2
soglia = 0.02
timestart = 90000
timeend = 180000
profitti = 280
perdite = 340
timeok = time>=timestart and time<=timeend
c = (sin(atan((close-open[n])/open[n]*100/n)))
if c crosses over soglia and timeok then
buy 1 contract at market
endif
if c crosses under -soglia and timeok then
sellshort 1 contract at market
endif
set target pprofit profitti
set stop ploss perdite
//trailing stop function
trailingstart = 57 //trailing will start @trailinstart points profit
trailingstep = 1 //trailing step to move the "stoploss"
//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)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*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)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF