Bonjour,
j’utilise pour entrer en position le même indicateur que je regarde en 1h et en 5min.
Pour sortir, j’aimerai me baser uniquement sur l’indicateur 1h : par exemple, si je suis long, j’aimerai sortir uniquement si KAMAUP1h n’est plus vérifié.
Comment programmer cela en sachant (je le rappelle) que je suis en multiframe 1H et 5 min.
merci.
Mon programme est le suivant :
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
Timeframe (1 hour)
//////////////////////////////////////////////////////////////KAMA 150
xClose1h = (Open+High+Low+Close)/4
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(xclose1h-xclose1h[Period1h])
Den1h = summation[Period1h](abs(xclose1h-xclose1h[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h - Slowest1h)+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
///////////////////////////////////////////////////////////////////: Distance Cours KAMA
DistanceKAMA1h = (xclose1h- kama1h)
for i1h=0 to 49
$montab1h[i1h]=distanceKAMA1h[i1h]
Next
arraysort($montab1h,ascend)
moy3plusBas1h = ($montab1h[0] + $montab1h[1] + $montab1h[2]) / 3
moy3plusHauts1h = ($montab1h[49] + $montab1h[48] + $montab1h[47]) / 3
KAMAUP1h = (DistanceKAMA1h > Moy3plushauts1h)
KAMADn1h = (DistanceKAMA1h < Moy3plusbas1h)
Timeframe (5 minutes)
//////////////////////////////////////////////////////////////KAMA 150
xClose5min = (Open+High+Low+Close)/4
Period5min = 150
FastPeriod5min = 2
SlowPeriod5min = 50
Fastest5min = 2 / (FastPeriod5min + 1)
Slowest5min = 2 / (SlowPeriod5min + 1)
if barindex < Period5min+1 then
Kama5min=close
else
Num5min = abs(xclose5min-xclose5min[Period5min])
Den5min = summation[Period5min](abs(xclose5min-xclose5min[1]))
ER5min = Num5min / Den5min
Alpha5min = SQUARE(ER5min *(Fastest5min - Slowest5min)+ Slowest5min)
KAMA5min = (Alpha5min * Close) + ((1 -Alpha5min)* Kama5min[1])
endif
///////////////////////////////////////////////////////////////////: Distance Cours KAMA
DistanceKAMA5min = (xclose5min- kama5min)
for i5min=0 to 49
$montab5min[i5min]=distanceKAMA5min[i5min]
Next
arraysort($montab5min,ascend)
moy3plusBas5min = ($montab5min[0] + $montab5min[1] + $montab5min[2]) / 3
moy3plusHauts5min = ($montab5min[49] + $montab5min[48] + $montab5min[47]) / 3
KAMAUP5min = (DistanceKAMA5min > Moy3plushauts5min)
KAMADn5min = (DistanceKAMA5min < Moy3plusbas5min)
/////////////////////////////////////////////////////////////////////////////////////
if KAMAUP1h and KAMAUP5min then
buy 1 contract at market
endif
if KAMADN1h and KAMADN5min then
sellshort 1 contract at market
endif
Pour sortir d’une position d’achat, dans le bloc timeframe(5 minutes), tu peux ajouter à la fin:
if longonmarket then
if KAMAUP1h = 0 then
sell at market
endf
endif
Pour mémoire, il est toutefois possible que cela intervienne plusieurs fois dans une bougie, puisque tu utilise les données du timeframe 1 heure toutes les 5 minutes, et non une donnée clôturée (pas de “updateonclose”).
Merci.
Je pensai qu’il était absolument nécessaire de lier l’indicateur de sortie 1h avec un indicateur 5 min (qui est la plus petite unité de mon multiframe).
Et merci pour l’updateonclose).
Bonjour,
je vous fais un retour sur la demande de code ci-dessus : donc voilà le code ci-dessous intégrant la réponse à ma demande.
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
Timeframe (1 hour, updateonclose)
//////////////////////////////////////////////////////////////KAMA 150
xClose1h = (Open+High+Low+Close)/4
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(xclose1h-xclose1h[Period1h])
Den1h = summation[Period1h](abs(xclose1h-xclose1h[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h - Slowest1h)+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
///////////////////////////////////////////////////////////////////: Distance Cours KAMA
DistanceKAMA1h = (xclose1h- kama1h)
for i1h=0 to 49
$montab1h[i1h]=distanceKAMA1h[i1h]
Next
arraysort($montab1h,ascend)
moy3plusBas1h = ($montab1h[0] + $montab1h[1] + $montab1h[2]) / 3
moy3plusHauts1h = ($montab1h[49] + $montab1h[48] + $montab1h[47]) / 3
KAMAUP1h = (DistanceKAMA1h > Moy3plushauts1h)
KAMADn1h = (DistanceKAMA1h < Moy3plusbas1h)
Timeframe (5 minutes, updateonclose)
//////////////////////////////////////////////////////////////KAMA 150
xClose5min = (Open+High+Low+Close)/4
Period5min = 150
FastPeriod5min = 2
SlowPeriod5min = 50
Fastest5min = 2 / (FastPeriod5min + 1)
Slowest5min = 2 / (SlowPeriod5min + 1)
if barindex < Period5min+1 then
Kama5min=close
else
Num5min = abs(xclose5min-xclose5min[Period5min])
Den5min = summation[Period5min](abs(xclose5min-xclose5min[1]))
ER5min = Num5min / Den5min
Alpha5min = SQUARE(ER5min *(Fastest5min - Slowest5min)+ Slowest5min)
KAMA5min = (Alpha5min * Close) + ((1 -Alpha5min)* Kama5min[1])
endif
///////////////////////////////////////////////////////////////////: Distance Cours KAMA
DistanceKAMA5min = (xclose5min- kama5min)
for i5min=0 to 49
$montab5min[i5min]=distanceKAMA5min[i5min]
Next
arraysort($montab5min,ascend)
moy3plusBas5min = ($montab5min[0] + $montab5min[1] + $montab5min[2]) / 3
moy3plusHauts5min = ($montab5min[49] + $montab5min[48] + $montab5min[47]) / 3
KAMAUP5min = (DistanceKAMA5min > Moy3plushauts5min)
KAMADn5min = (DistanceKAMA5min < Moy3plusbas5min)
/////////////////////////////////////////////////////////////////////////////////////
if KAMAUP1h and KAMAUP5min then
buy 1 contract at market
endif
if KAMADN1h and KAMADN5min then
sellshort 1 contract at market
endif
if longonmarket then
if KAMAUP1h = 0 then
sell at market
endif
endif
if shortonmarket then
if KAMADN1h = 0 then
exitshort at market
endif
endif
comme vous pouvez le voir sur la pièce jointe, alors que graphiquement la condition de sortie sur une position longue prise le 30 avril n’est pas remplie, deux sorites sont effectuées à 15 h et à 19H.
vous pourriez voir pourquoi ? Merci.
Es tu certain que dans la version que tu as testée, tu avais bien:
Timeframe (1 hour, updateonclose)
avec UPDATEONCLOSE ?
Sinon, il faudrait faire des GRAPH des variables nécessaires aux entrées sorties, pour comprendre pourquoi le code a agit ainsi, soit:
GRAPH KAMAUP1h
GRAPH KAMAUP5min
GRAPH KAMAUP1h
GRAPH KAMADN5min