Bonjour Nicolas
je reviens vers toi car je n’arrive toujours pas à résoudre mon problème de coupure.
Tous mes codes fonctionnent assez bien mais lorsque on est dans une période de range ça se complique. Ce sont des pertes à répétition.
je souhaiterais insérer dans mon code un ordre ferme et prioritaire de coupure à un montant de perte défini et pas en nombre de bougies ou en points car c’est aléatoire .
sur le forum j’ai trouvé des codes qui limite un gain ou une perte journalière mais ce n’est pas ce que je recherche
Quelque soit mon code cette fonction serait prioritaire mais n’empercherait pas l’ouverture d’un nouvel ordre .
bien cordialement
jp Saccucci
Pour le “montant de perte défini”, il doit forcément l’être sur une période, on le calcule depuis quand ? Depuis la première perte ? et on continue à le calculer tant qu’on est pas en gain ?
Ou s’agit-il de fermer simplement l’ordre en cours si il atteint x euros de perte ?
Il peut y avoir 100 façons de le faire, pourrais-tu être plus précis ? Merci ! 😀
re bonjour Nicolas
Je vais essayé de me faire comprendre en prenant un exemple
voila un code ci-joint
je souhaiterais pouvoir rajouter une fonction qui coupe l’ordre a “n” montant de perte sans stop .
Cordialement
jp
defparam cumulateorders=false
// --- Partial Close settings ---
size = 10
mincontracts = 1
trigger = 20
pointback = 5
closepercent = 20
// ------------------------------
timeframe(15 minutes,updateonclose)
st = Supertrend[3,10]
if not longonmarket and close crosses over st then
buy size contracts at market
set stop ploss 15
endif
if not shortonmarket and close crosses under st then
sellshort size contracts at market
set stop ploss 15
endif
timeframe(1 minute)
if not onmarket then
AllowPartialClose=0
endif
//## -- PARTIAL CLOSE PRICE BACK FUNCTION -- ##
//## - BUY ORDERS
if longonmarket then
//trigger for the partial closure function to start
if close-tradeprice>=trigger*pointsize then
AllowPartialClose = 1
endif
if AllowPartialClose then
//compute the maxprice reached
maxprice = max(maxprice,close)
//check to trigger a partial closure or not
if maxprice-close>=pointback*pointsize then
//close partially
sell max(mincontracts,size*(closepercent/100)) contracts at market
//reset the maxprice to the current price
maxprice = close
endif
endif
endif
//## - SELLSHORT ORDERS
if shortonmarket then
//trigger for the partial closure function to start
if tradeprice-close>=trigger*pointsize then
AllowPartialClose = 1
endif
if AllowPartialClose then
//compute the maxprice reached
minprice = min(minprice,close)
//check to trigger a partial closure or not
if close-minprice>=pointback*pointsize then
//close partially
exitshort max(mincontracts,size*(closepercent/100)) contracts at market
//reset the maxprice to the current price
minprice = close
endif
endif
endif
graph st coloured(200,100,200) as "Supertrend"
graph Close
Avec le code modifié ci-dessous la position est fermé dés que le gain flottant passe sous la barre des – “moneyclose” :
defparam cumulateorders=false
// --- Partial Close settings ---
size = 10
mincontracts = 1
trigger = 20
pointback = 5
closepercent = 20
moneyclose = 50 //seuil de perte en monnaie pour cloturer un ordre en cours
// ------------------------------
timeframe(15 minutes,updateonclose)
st = Supertrend[3,10]
if not longonmarket and close crosses over st then
buy size contracts at market
set stop ploss 15
endif
if not shortonmarket and close crosses under st then
sellshort size contracts at market
set stop ploss 15
endif
timeframe(1 minute)
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
if onmarket and floatingprofit<-moneyclose then
sell at market
exitshort at market
endif
if not onmarket then
AllowPartialClose=0
endif
//## -- PARTIAL CLOSE PRICE BACK FUNCTION -- ##
//## - BUY ORDERS
if longonmarket then
//trigger for the partial closure function to start
if close-tradeprice>=trigger*pointsize then
AllowPartialClose = 1
endif
if AllowPartialClose then
//compute the maxprice reached
maxprice = max(maxprice,close)
//check to trigger a partial closure or not
if maxprice-close>=pointback*pointsize then
//close partially
sell max(mincontracts,size*(closepercent/100)) contracts at market
//reset the maxprice to the current price
maxprice = close
endif
endif
endif
//## - SELLSHORT ORDERS
if shortonmarket then
//trigger for the partial closure function to start
if tradeprice-close>=trigger*pointsize then
AllowPartialClose = 1
endif
if AllowPartialClose then
//compute the maxprice reached
minprice = min(minprice,close)
//check to trigger a partial closure or not
if close-minprice>=pointback*pointsize then
//close partially
exitshort max(mincontracts,size*(closepercent/100)) contracts at market
//reset the maxprice to the current price
minprice = close
endif
endif
endif
graph floatingprofit
graph -moneyclose coloured(200,200,0)
//graph st coloured(200,100,200) as "Supertrend"
//graph Close