Bonjour,
je cherche à créer un algorithme de trading qui permettrait de payer un cluster de supports de type moyenne mobile d’UT différentes (par exemple Weekly et Monthly).
Ci-attaché, un exemple de trade que je souhaiterais prendre : le Prix touche la M7 UT mois, et en parallèle est proche de la M20 UT Hebdomadaire.
//efparam drawonlastbaronly=true
//DEFPARAM CalculateOnLastBars = 5300
DEFPARAM PreLoadBars = 50000
DEFPARAM CumulateOrders = False
Voffset = pipsize
variable1 = 0.5
TIMEFRAME(WEEKLY)
typicalprixW = (high+low+close)/3
//SMA 7/20/50/200
M7W = average[7]
uw= BollingerUp[20](typicalprixW)
lw= Bollingerdown[20](typicalprixW)
MW = average[20](typicalprixW)
//M7W = average[7]
lookM7W=0
if M7W < close and M7W>M7W[1] and low>M7W then
lookM7W=1
endif
lookuw=0
if (uw) < close and (uw)>(uw)[1] and low>(uw) then
lookuw=1
endif
looklw=0
if (lw) < close and (lw)>(lw)[1] and low>(lw) then
looklw=1
endif
lookMW=0
if (MW) < close and MW>MW[1] and low>MW then
lookMW=1
endif
lookpw=0
PW = call "ATS_SAR"
if PW < close and (pw>pw[1] or (pw<pw[1] and High[1]>pw[1])) and low > pw then
lookpw=1
endif
signal1W=0
if lookpw=1 and ((close-pw) < variable1) then
signal1W=1
endif
signal2W=0
if lookM7W=1 and ((close-M7W) < variable1) then
signal2W=1
endif
signal3W=0
if lookuw=1 and ((close-UW) < variable1) then
signal3W=1
endif
signal4W=0
if looklw=1 and ((close-LW) < variable1) then
signal4W=1
endif
signal5W=0
if lookMW=1 and ((close-MW) < variable1) then
signal5W=1
endif
SIGNALW = (signal1W+signal2W+signal3W+signal4W+signal5W)
timeframe(monthly)
//SMA 7/20/50/200
typicalprixM = (high+low+close)/3
//SMA 7/20/50/200
M7M = average[7]
UM= BollingerUp[20](typicalprixM)
LM= Bollingerdown[20](typicalprixM)
MM = average[20](typicalprixM)
lookm7M=0
if M7M < close and M7M>M7M[1] and low>M7M then
lookm7M=1
endif
lookUM=0
if (UM) < close and (UM)>(UM)[1] and low>(UM) then
lookUM=1
endif
lookLM=0
if (LM) < close and (LM)>(LM)[1] and low>(LM) then
lookLM=1
endif
lookMM=0
if (MM) < close and MM>MM[1] and low>MM then
lookMM=1
endif
lookpM=0
PM = call "ATS_SAR"
if PM < close and (pM>pM[1] or (pM<pM[1] and High[1]>pM[1])) and low > pM then
lookpM=1
endif
signal1M=0
if lookpM=1 and ((close-pm) < variable1) then
signal1M=1
endif
signal2m=0
if lookM7m=1 and ((close-M7m) < variable1) then
signal2M=1
endif
signal3M=0
if lookuM=1 and ((close-UM) < variable1) then
signal3M=1
endif
signal4M=0
if looklM=1 and ((close-LM) < variable1) then
signal4M=1
endif
signal5M=0
if lookMM=1 and ((close-MM) < variable1) then
signal5M=1
endif
SIGNALM = (signal1M+signal2M+signal3M+signal4M+signal5M)
timeframe (default)
SIGNAL = (SIGNALW + SIGNALM)
if SIGNAL >= 2 THEN
BUY 1 CONTRACTS AT MARKET
SET STOP pLOSS 100
SET TARGET pPROFIT 100
ENDIF
Le STOP serait sous les deux moyennes mobiles, l’entrée sur le premier des deux supports, et le TP fixe, par exemple.
J’ai essayé de créer un code simple, mais cela ne reproduit absolument pas l’objectif recherché.
Pourriez vous m’aider à débugger mon code?
Merci.
Bonjour,
Sans pouvoir vraiment le tester à cause du call d’un autre programme, et donc en neutralisant les 2 call pour voir ce que donnent au moins les autres conditions, la variable1=0.5 ne déclenche aucun signal, ni 1 ni 1.5, il faut une variable1=2 (ou en tout cas quelque part entre 1.5 et 2 si on veut tester plus finement que de 0.5 en 0.5) avant que ce trade du creux de mai ne soit détecté, via un signal mensuel qui se débloque via la composante signal2m (signal3m,4m,5m restant à 0 même à variable1=2)