Hello everyone,
I have the pleasure to share with you this simple but practical, universal daily strategy (for Forex, Indices, and Stocks), optimized on the CAC from 1992 to today. I hope that this opensource contribution can bring more developments in the field of automatic trading strategies on prorealtime, and demonstrate once and for all that a strategy to work does not necessarily have to be complicated, indeed (as I see it) the simpler it is, the more likely it is to work in the future as in the past.
The strategy has 3 fundamental parameters to optimize primarily which are: Period, Mode, and invertsignal. Once these have been chosen, we move on to the optimization of the two filters: filter1 and filter2. Finally, if you want you can add, a stop loss based on the average true average.
Here is the code
//Universal XBody STrategy
// instrument: CAC40
// timeframe : Daily
// Spread: 4
// created and coded by davidelaferla
//————————————————————————-
//-------------------------------------------------------------------------
defparam cumulateorders=false
//***********************************************************************************************************
N = 1
//------------------ SYSTEM VARIABLES---------------------------------------
//CAC40 Values: -------------------------------------------- Ottimization info
period=978// Optimize best value for each Symbol, range=1-1000, with step=1
mode=1// Optimize the best trading mode , range=1-4, with step=1
invertsignal=1// 1=positive signal, -1=negative signal, range=-1-1, with step=2
//***********************************************************************************************
//------------------ SYSTEM FILTER---------------------------------------
filter1=51// to set after the variable optimization, range=1-100, with step=1
filter2=0// to set after the variable optimization, range=1-100, with step=1
//------------------ INDICATOR ---------------------------------------
body=close-open
var=(body-body[1])
sumvar=summation[period](var)
if sumvar>filter1*pipsize then
green=(sumvar)
endif
if sumvar<-filter2*pipsize then
red=(sumvar)
endif
if mode=1 then
c1=red<red[1]
c2=green>green[1]
endif
if mode=2 then
c1=red>red[1]
c2=green<green[1]
endif
if mode=3 then
c1=red<red[1]
c2=green<green[1]
endif
if mode=4 then
c1=red>red[1]
c2=green>green[1]
endif
if c1 then
signal=1*invertsignal
elsif c2 then
signal=-1*invertsignal
endif
// Conditions for entering long positions and exit short positions
IF signal>0 then
BUY n contract AT market
ENDIF
// Conditions for entering short positions and exit long positions
IF signal<0 THEN
SELLSHORT n CONTRACTs AT market
ENDIF