Bonsoir,
Tout d’abord un grand merci à Nicolas et à tous les participants de ce forum riche en informations.
Je souhaiterais arrêter un programme jusqu’au lendemain dès qu’un nombre de points a été réalisé (avec plusieurs opérations dans la journée). Par exemple dès que 20 points ont été atteints, sachant que chaque opération a un tp5 donc cela veut dire 4 opérations dans la journée.
Idem si X points sont touchés en S/L
Merci d’avance de votre aide.
Ce petit code snippet ci-dessous reprend le gain et la perte maximale autorisée par jour, en points:
MaxProfit = 50 //max daily profit objective in pips
MaxLoss = 40 //max daily loss in pips
//max profit/loss achieved
if day<>day[1] then
strategyprofitpoint=0 //daily reset
endif
if(strategyprofit<>strategyprofit[1]) then
pnl = strategyprofit-strategyprofit[1]
size = max(startContract,abs(countofposition[1]))
onepos = pnl/size
pointprofit = onepos/pointvalue
strategyprofitpoint = strategyprofitpoint+pointprofit
endif
allowtrading=1
if (strategyprofitpoint>=MaxProfit or strategyprofitpoint<=-MaxLoss) then
allowtrading=0
endif
La variable booléenne allowtrading autorise ou non le trading, il suffit de l’employer dans tes conditions de trading de ta stratégie.
Un grand merci Nicolas pour ta réactivité, c’est parfait !
Bonne soirée
Bonjour,
Est ce que ce code est correct pour que le trading s’arrête si on a un nombre de perte max dans la journée sur le nasdaq par exemple ?
Merci pour votre réponse.
Je l’ai adapté.
if day<>day[1] then
strategyprofitpoint=0 //daily reset
allowtrading=1 //daily reset
endif
if(strategyprofit<>strategyprofit[1]) then
pnl = strategyprofit-strategyprofit[1]
totalstrategyprofit = totalstrategyprofit+pnl
endif
if totalstrategyprofitpoint<=-MaxLoss then
SELL AT MARKET
EXITSHORT AT MARKET
allowtrading=0
ENDIF
Oui, mais la ligne 2 doit s’écrire ainsi:
totalstrategyprofitpoint=0 //daily reset