// Code principal : $BT/NSD100/M20/M100/H4(TS)
//-------------------------------------------------------------------------
// Définition des paramètres du code
DEFPARAM CumulateOrders = true // Cumul des positions désactivé
timeframe(4 hours, UPDATEONCLOSE )
i=Average[20](close)
ii=Average[100](close)
mymm200=Average[200](close)
MYSUP1=Supertrend[1.5,10]
if i crosses under ii then
llbar=barindex
j=j+1
dir=1
endif
if i < ii then
llperiod=max(1,barindex-llbar)
$llbar[j]=barindex[lowestBars[llperiod]]
$ll[j]=lowest[llperiod](low)
$dir[j]=-1
LL = $ll[j]
elsif i crosses over ii THEN
$plusbas[1] = LL
endif
// Conditions pour ouvrir une position acheteuse en H4
vos=i crosses over ii and close>mymm200
if vos then
$sl[1]=$plusbas[1]
$achat[1]=close
diff= close-$sl[1]
$tp[1]=close+diff
achat=1
ELSE
achat =0
ENDIF
if $achat[1]+diff >close THEN
hausse=0
ELSE
hausse =1
ENDIF
if $achat[1]-diff<close THEN
baisse=-1
ELSE
baisse=0
ENDIF
if close<$tp[1] and close>$plusbas[1] THEN
achete=1
ELSE
achete=0
ENDIF
GRAPHONPRICE $plusbas[1]
GRAPHONPRICE $tp[1]
graph achete
timeframe(default)
if achete then
buy AT MARKET
ENDIF
set target pprofit 5