ProRealCode - Trading & Coding with ProRealTime™
Bonjour a tous,
Je suis en train de backtester une stratégie et j’obtiens un comportement bizarre sur le France 40 concernant les stop.
Donc dans ma stratégie je BUY ou SELLSHORT x contrats une fois mon signal obtenu.
Je place un target et un stop loss de la manière suivante (exemple en shortmarket) :
IF shortonmarket and TradeShortSSB then
SET STOP pLOSS STOPSSB
SET TARGET pPROFIT TargetShortSSB
ELSIF shortonmarket and TradeShortSSA then
SET STOP pLOSS STOPSSA
SET TARGET pPROFIT TargetShortSSA
ELSIF shortonmarket and TradeShortKIJUN then
SET STOP pLOSS STOPKIJUN
SET TARGET pPROFIT TargetShortKIJUN
ELSIF shortonmarket and TradeShortTENKAN then
SET STOP pLOSS 14//STOPTENKAN
SET TARGET pPROFIT TargetShortTENKAN
ENDIF
C’est une stratégie ICHIMOKU comme vous pourrez le voir, je n’ai pas le même TP et SL selon que ce soit un trade lié à la SSA, SSB, TENKAN ou KIJUN.
Tout est OK dans cette stratégie, les SL sont bien placés, sauf à un endroit précis du France 40 (trade du 15 Aout 2019 voir ci-joint), où j’ai un comportement que je n’explique pas.
A la base dans mon code, le STOPTENKAN était optimisé sur 16, et pour ce trade précis je ne comprenais pas pourquoi j’avais une énorme perte, j’ai donc modifié a la main le SL et essayé de comprendre et il se trouve qu’il semble exister un “cliquet” entre 13 et 14 points : voir les screenshots ci-joint pour un SL de 13 points c’est OK, et quand il passe à 14 tout d’un coup je sors des jours plus tard avec 72 points de perte ! (en fait le cliquet est vers 13.9 points)
J’avais la même perte avec mon STOP optimisé de 16 points, ca ne semble donc pas être une histoire de multiple du stop (puisque j’ai bien 72 points avec SL = 14 ou 16)
Je précise que j’ai ce comportement uniquement ici, partout ailleurs sur le backtest (de 2019 à aujourd’hui) mon SL est bien placé
Est ce que vous avez une idée d’où peut venir ce genre de comportement ? Un problème dans le code ou dans les datas historisées qui ferait bugger l’ensemble ici ?
Merci d’avance pour votre aide, j’ai cherché pas mal de temps mais là j’avoue sécher un peu …
Si besoin bien sûr je vous joindrais le code pour mieux comprendre (mais il faudra que je fasse un peu de tri avant !)
Il est possible que l’une de tes conditions TradeShortXXX soit à l’origine de la modification du stoploss. Si tu ne testes pas si tu es déjà au marché avant de la tester (sans le code complet, c’est une hypothèse).
Merci pour la réponse rapide.
J’ai essayé de mettre des “If not on market” dans mes conditions si c’est de cela dont tu parles, mais j’ai le même comportement.
Je te joins le code, que j’ai volontairement simplifié … Même si cela reste une belle usine à gaz ! (merci de noter que certaines variables ne sont pas définies, c’est normal c’est pour l’exemple)
Merci pour ton indulgence, je débute ! 😀
//////////////////////////////////////////////////////////////////////
//// PARAMETRES GENERAUX
//////////////////////////////////////////////////////////////////////
DEFPARAM CumulateOrders = False
//DEFPARAM FLATBEFORE = 084500
//DEFPARAM FLATAFTER = 220000
//////////////////////////////////////////////////////////////////////
//// GENERIC CODE
//////////////////////////////////////////////////////////////////////
// Variables a optimiser
STOPBase = 16
TARGETBase = 3
TradeSSBAllowed = 1
TradeSSAAllowed = 1
TradeKIJUNAllowed = 0
TradeTENKANAllowed = 1
// Variables à modifier a la main
TradeLongAllowed = 1
TradeShortAllowed = 1
TradeH4Allowed = 0
TradeDailyAllowed = 1
TradeWeeklyAllowed = 1
STOPSSBMultiplier = a // pour l'exemple
TARGETSSBMultiplier = b // pour l'exemple
STOPSSB = StopBase * STOPSSBMultiplier
TargetLongSSB = (ABS(tradeprice-TARGETlong)*TARGETBase*TARGETSSBMultiplier)
TargetShortSSB = (ABS(tradeprice-TARGETshort)*TARGETBase*TARGETSSBMultiplier)
STOPSSAMultiplier = c // pour l'exemple
TARGETSSAMultiplier = d // pour l'exemple
STOPSSA = StopBase * STOPSSAMultiplier
TargetLongSSA = (ABS(tradeprice-TARGETlong)*TARGETBase*TARGETSSAMultiplier)
TargetShortSSA = (ABS(tradeprice-TARGETshort)*TARGETBase*TARGETSSAMultiplier)
STOPKIJUNMultiplier = e // pour l'exemple
TARGETKIJUNMultiplier = f // pour l'exemple
STOPKIJUN = StopBase * STOPKIJUNMultiplier
TargetLongKIJUN = (ABS(tradeprice-TARGETlong)*TARGETBase*TARGETKIJUNMultiplier)
TargetShortKIJUN = (ABS(tradeprice-TARGETshort)*TARGETBase*TARGETKIJUNMultiplier)
STOPTENKANMultiplier = g // pour l'exemple
TARGETTENKANMultiplier = h // pour l'exemple
STOPTENKAN = StopBase * STOPTENKANMultiplier
TargetLongTENKAN = (ABS(tradeprice-TARGETlong)*TARGETBase*TARGETTENKANMultiplier)
TargetShortTENKAN = (ABS(tradeprice-TARGETshort)*TARGETBase*TARGETTENKANMultiplier)
//*******MONEY MANAGEMENT*********
// pour l'exemple
nSSB = 1
nSSA = 1
nKIJUN = 1
nTENKAN = 1
//////////////////////////////////////////////////////////////////////
//// INDICATOR
//////////////////////////////////////////////////////////////////////
//A
timeframe(default)
SignalUp = CALL FonctionSignalUp
SignalDown = CALL FonctionSignalDown
//B
timeframe(4hours)
SignalSSAh4 = CALL FonctionSignalSSA
SignalSSBh4 = CALL FonctionSignalSSB
SignalKIJUNh4 = CALL FonctionSignalKIJUN
SignalTENKANh4 = CALL FonctionSignalTENKAN
timeframe(daily)
SignalSSAdaily = CALL FonctionSignalSSA
SignalSSBdaily = CALL FonctionSignalSSB
SignalKIJUNdaily = CALL FonctionSignalKIJUN
SignalTENKANdaily = CALL FonctionSignalTENKAN
timeframe(weekly)
SignalSSAweekly = CALL FonctionSignalSSA
SignalSSBweekly = CALL FonctionSignalSSB
SignalKIJUNweekly = CALL FonctionSignalKIJUN
SignalTENKANweekly = CALL FonctionSignalTENKAN
timeframe(default)
IF TradeSSAAllowed then
SignalSSA = SignalSSAh4 or SignalSSADaily or SignalSSAWeekly
ENDIF
IF TradeSSBAllowed then
SignalSSB = SignalSSBh4 or SignalSSBDaily or SignalSSBWeekly
ENDIF
IF TradeKIJUNAllowed then
SignalKIJUN = SignalKIJUNh4 or SignalKIJUNDaily or SignalKIJUNWeekly
ENDIF
IF TradeTENKANAllowed then
SignalTENKAN = SignalTENKANh4 or SignalTENKANDaily or SignalTENKANWeekly
ENDIF
timeframe(4hours)
SSAH4Up = TradeH4Allowed and SignalUp and SignalSSA
SSAH4Down = TradeH4Allowed and SignalDown and SignalSSA
SSBH4Up = TradeH4Allowed and SignalUp and SignalSSB
SSBH4Down = TradeH4Allowed and SignalDown and SignalSSB
KIJUNH4Up = TradeH4Allowed and SignalUp and SignalKIJUN
KIJUNH4Down = TradeH4Allowed and SignalDown and SignalKIJUN
TENKANH4Up = TradeH4Allowed and SignalUp and SignalTENKAN
TENKANH4Down = TradeH4Allowed and SignalDown and SignalTENKAN
timeframe(daily)
SSADAILYUp = TradeDAILYAllowed and SignalUp and SignalSSA
SSADAILYDown = TradeDAILYAllowed and SignalDown and SignalSSA
SSBDAILYUp = TradeDAILYAllowed and SignalUp and SignalSSB
SSBDAILYDown = TradeDAILYAllowed and SignalDown and SignalSSB
KIJUNDAILYUp = TradeDAILYAllowed and SignalUp and SignalKIJUN
KIJUNDAILYDown = TradeDAILYAllowed and SignalDown and SignalKIJUN
TENKANDAILYUp = TradeDAILYAllowed and SignalUp and SignalTENKAN
TENKANDAILYDown = TradeDAILYAllowed and SignalDown and SignalTENKAN
timeframe(weekly)
SSAWEEKLYUp = TradeWEEKLYAllowed and SignalUp and SignalSSA
SSAWEEKLYDown = TradeWEEKLYAllowed and SignalDown and SignalSSA
SSBWEEKLYUp = TradeWEEKLYAllowed and SignalUp and SignalSSB
SSBWEEKLYDown = TradeWEEKLYAllowed and SignalDown and SignalSSB
KIJUNWEEKLYUp = TradeWEEKLYAllowed and SignalUp and SignalKIJUN
KIJUNWEEKLYDown = TradeWEEKLYAllowed and SignalDown and SignalKIJUN
TENKANWEEKLYUp = TradeWEEKLYAllowed and SignalUp and SignalTENKAN
TENKANWEEKLYDown = TradeWEEKLYAllowed and SignalDown and SignalTENKAN
timeframe(default)
//////////////////////////////////////////////////////////////////////
//// STRATEGIE DE TRADING
//////////////////////////////////////////////////////////////////////
//*******BUY CONDITIONS*******
// Trades SSB
If not ONMARKET then
If TradelongAllowed then
if SSBH4Up then
buy nSSB shares at xh4 LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 1
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
if SSBDailyUp then
buy nSSB shares at xdaily LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 1
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
If SSBWeeklyUp then
buy nSSB shares at xweekly LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 1
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
// Trades SSA
If TradelongAllowed then
if SSAH4Up then
buy nSSA shares at xh4 LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 1
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
if SSADailyUp then
buy nSSA shares at xdaily LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 1
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
If SSAWeeklyUp then
buy nSSA shares at xweekly LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 1
TradelongKIJUN = 0
TradelongTENKAN = 0
endif
ENDIF
// Trades KIJUN
If TradelongAllowed then
if KIJUNH4Up then
buy nKIJUN shares at xh4 LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 1
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
if KIJUNDailyUp then
buy nKIJUN shares at xdaily LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 1
TradelongTENKAN = 0
endif
ENDIF
If TradelongAllowed then
If KIJUNWeeklyUp then
buy nKIJUN shares at xweekly LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 1
TradelongTENKAN = 0
endif
ENDIF
// Trades TENKAN
If TradelongAllowed then
if TENKANH4Up then
buy nTENKAN shares at xh4 LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 1
endif
ENDIF
If TradelongAllowed then
if TENKANDailyUp then
buy nTENKAN shares at xdaily LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 1
endif
ENDIF
If TradelongAllowed then
If TENKANWeeklyUp then
buy nTENKAN shares at xweekly LIMIT // pour l'exemple
TARGETlong = y // pour l'exemple
TradelongSSB = 0
TradelongSSA = 0
TradelongKIJUN = 0
TradelongTENKAN = 1
endif
ENDIF
ENDIF
//*******CLOSE BUY POSITION CONDITIONS*******
IF longonmarket and TradeLongSSB then
SET STOP pLOSS STOPSSB
SET TARGET pPROFIT TargetLongSSB
ELSIF longonmarket and TradeLongSSA then
SET STOP pLOSS STOPSSA
SET TARGET pPROFIT TargetLongSSA
ELSIF longonmarket and TradeLongKIJUN then
SET STOP pLOSS STOPKIJUN
SET TARGET pPROFIT TargetLongKIJUN
ELSIF longonmarket and TradeLongTENKAN then
SET STOP pLOSS STOPTENKAN
SET TARGET pPROFIT TargetLongTENKAN
ENDIF
//*******SELL CONDITIONS *******
// Trades SSB
If not ONMARKET then
If TradeShortAllowed then
If TradeH4Allowed then
if SSBH4Down then
SELLSHORT nSSB shares at xh4 LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 1
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
If TradeShortAllowed then
If TradeDailyAllowed then
if SSBDailyDown then
SELLSHORT nSSB shares at xdaily LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 1
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
if TradeShortAllowed then
if TradeWeeklyAllowed then
If SSBWeeklyDown then
SELLSHORT nSSB shares at xweekly LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 1
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
// Trades SSA
If TradeShortAllowed then
If TradeH4Allowed then
if SSAH4Down then
SELLSHORT nSSA shares at xh4 LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 1
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
If TradeShortAllowed then
If TradeDailyAllowed then
if SSADailyDown then
SELLSHORT nSSA shares at xdaily LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 1
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
if TradeShortAllowed then
if TradeWeeklyAllowed then
If SSAWeeklyDown then
SELLSHORT nSSA shares at xweekly LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 1
TradeshortKIJUN = 0
TradeshortTENKAN = 0
endif
endif
ENDIF
// Trades KIJUN
If TradeShortAllowed then
If TradeH4Allowed then
if KIJUNH4Down then
SELLSHORT nKIJUN shares at xh4 LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 1
TradeshortTENKAN = 0
endif
endif
ENDIF
If TradeShortAllowed then
If TradeDailyAllowed then
if KIJUNDailyDown then
SELLSHORT nKIJUN shares at xdaily LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 1
TradeshortTENKAN = 0
endif
endif
ENDIF
if TradeShortAllowed then
if TradeWeeklyAllowed then
If KIJUNWeeklyDown then
SELLSHORT nKIJUN shares at xweekly LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 1
TradeshortTENKAN = 0
endif
endif
ENDIF
// Trades TENKAN
If TradeShortAllowed then
If TradeH4Allowed then
if TENKANH4Down then
SELLSHORT nTENKAN shares at xh4 LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 1
endif
endif
ENDIF
If TradeShortAllowed then
If TradeDailyAllowed then
if TENKANDailyDown then
SELLSHORT nTENKAN shares at xdaily LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 1
endif
endif
ENDIF
if TradeShortAllowed then
if TradeWeeklyAllowed then
If TENKANWeeklyDown then
SELLSHORT nTENKAN shares at xweekly LIMIT // pour l'exemple
TARGETshort = y // pour l'exemple
TradeshortSSB = 0
TradeshortSSA = 0
TradeshortKIJUN = 0
TradeshortTENKAN = 1
endif
endif
ENDIF
ENDIF
//*******CLOSE SELL POSITION CONDITIONS *******
IF shortonmarket and TradeShortSSB then
SET STOP pLOSS STOPSSB
SET TARGET pPROFIT TargetShortSSB
ELSIF shortonmarket and TradeShortSSA then
SET STOP pLOSS STOPSSA
SET TARGET pPROFIT TargetShortSSA
ELSIF shortonmarket and TradeShortKIJUN then
SET STOP pLOSS STOPKIJUN
SET TARGET pPROFIT TargetShortKIJUN
ELSIF shortonmarket and TradeShortTENKAN then
SET STOP pLOSS STOPTENKAN
SET TARGET pPROFIT TargetShortTENKAN
ENDIF
Par exemple, c’est à la ligne 35 que tu définis “TradeLongSSB” et à chaque bougie ! donc si tu es déjà au marché, à chaque fois que ta ligne 318 est lu tu modifieras ton target avec cette nouvelle valeur…
Tu dois donc trouver le moyen de définir une seule fois la valeur que tu veux donner.
(je me rends compte que j’ai utilisé un exemple avec un target, mais c’est pareil avec la définition de tes variables des valeurs de stoploss bien entendu).
Je vois le truk … Ce qui m’étonne c’est que je n’ai ce comportement qu’ici, peut être y a-t-il une conjonction de choses qui font qu’ici ça se passe comme ça et pas ailleurs.
Et là où je ne comprends pas non plus c’est que si je mets une valeur fixe du stop (cf. mon premier post) ça me le fait : est ce que si le programme lit la ligne, il re déplace son stop à chaque fois (de 13 ou 14 points pour reprendre mon exemple)?
Existe il un moyen de voir via instruction GRAPH ou autre le stop que le systeme met ?
Re,
J’ai pas mal bossé dessus encore cet après midi mais rien de neuf…
J’arrive quand même à avoir le comportement ci-joint (voir screenshot) : sur la bougie où je sortais avec 72 points le backtest me génère un trade à 00:00 sur la même bougie, à 5250 alors que le cours est plus dans les 5320 et ne touche jamais ce niveau… Donc impossible ?!
Je ne sais pas si ce genre de choses peuvent arriver, dans le stockage des données …
algo va sur quel TF
Probleme de stop a un moment precis d’un backtest
This topic contains 6 replies,
has 3 voices, and was last updated by fifi743
3 years, 4 months ago.
| Forum: | ProOrder : Trading Automatique & Backtests |
| Language: | French |
| Started: | 10/13/2022 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.