voici le code que donne cahtgpt. Qu’en pensez vous?
// Algo James Bond adapté pour ProRealTime / ProBuilder
volatilityThreshold = 0.5 // valeur par défaut en points ; si ATR < => faible volatilité
// Targets en points pour faible/forte volatilité
tp_low_vol_points = 4 // 4 points = 20 ticks si tickSize = 0.25
tp_high_vol_points = 15 // 15 points = 75 ticks si tickSize = 0.25
// Reverse: lot multiplier et placement
reverseLotMultiplier = 2
reverseEntryOffsetTicks = 1 // entrée reverse 1 tick au dessus/ dessous
// Setup 2 offset
setup2_offset_ticks = 2
// VWAP filter: si price > vwap => n’autorise que les BUY STOP jusqu’à VWAP + 4*stdev
vwapStdPeriod = 20
vwapStdMultiplierMax = 4
// Heures de trading (format HHMM) – 2 plages configurables
tradeStart1 = 0900
tradeEnd1 = 1100
tradeStart2 = 1400
tradeEnd2 = 1800
// Taille de la position par défaut
baseQty = 1
// ———- Indicateurs ———-
// Parabolic SAR
sar = SAR(sar_acceleration, sar_step, sar_max)
// VWAP
vwap = VWAP
// Écart type autour du VWAP (sur vwapStdPeriod bougies)
vwap_dev = StdDev(close – vwap, vwapStdPeriod)
// ATR pour mesurer la volatilité (en points)
atr = AverageTrueRange(atrLength)
// Détection de la plage horaire autorisée
isInSession = ( (time >= tradeStart1 and time <= tradeEnd1) or (time >= tradeStart2 and time <= tradeEnd2) )
// Conversion ticks <-> price
ticksToPrice(nTicks) = nTicks * tickSize
// Helper: calcul target en points selon volatilité
isLowVol = atr < volatilityThreshold
if isLowVol then
tp_points = tp_low_vol_points
else
tp_points = tp_high_vol_points
endif
// ———- Rèles d’entrées ———-
// Interprétation des SAR :
// – “SAR haussier” -> SAR est en-dessous du cours (SAR < low) => tendance haussière
// – “SAR baissier” -> SAR est au-dessus du cours (SAR > high) => tendance baissière
// Bougie actuelle et précédente
bull_candle = close > open
bear_candle = close < open
prev_sar = sar[1]
prev_close = close[1]
// Condition flip SAR (précédente était baissier et maintenant haussier, etc.)
prev_sar_bear = prev_sar > high[1]
prev_sar_bull = prev_sar < low[1]
current_sar_bull = sar < low
current_sar_bear = sar > high
// ———- Orders logic (set pending orders when conditions met) ———-
// NOTE: ProRealTime syntax for creating pending orders peut varier; ci-dessous implémentation logique
// 1) Setup principal : bougie haussière, SAR haussier cassé à la baisse => SELL STOP sous le plus bas
if isInSession and bull_candle and current_sar_bear and current_sar_bull[1] = true then
// Condition interprétée comme : la bougie est haussière mais SAR a été cassé vers le bas
sellStopPrice = low – ticksToPrice(1) // placer 1 tick sous le plus bas
// Placer Sell Stop
// Vérifier si instrument au-dessus de VWAP -> si oui, n’autoriser que buy stops (on ignore sell stops)
if close > vwap then
// on ne regarde que les buy stops, donc ne pas placer sell stop
else
// Placer sell stop
SELL_STOP baseQty CONTRACTS AT sellStopPrice
// Placer TP et SL: TP = sellStopPrice – tp_points ; SL = reverse condition dynamic
SET TARGET (ticksToPrice(tp_points / tickSize)) // placeholder : adapter selon syntaxe
endif
endif
// 1b) inverse : bougie baissière, SAR baissier cassé à la hausse => BUY STOP au-dessus du plus haut
if isInSession and bear_candle and current_sar_bull and current_sar_bear[1] = true then
buyStopPrice = high + ticksToPrice(1)
// VWAP filter: si price > vwap on autorise buy stops uniquement si buyStopPrice <= vwap + 4*stdev
if close > vwap then
if buyStopPrice <= vwap + vwapStdMultiplierMax * vwap_dev then
if buyStopPrice <= vwap + vwapStdMultiplierMax * vwap_dev then
BUY_STOP baseQty CONTRACTS AT buyStopPrice
SET TARGET (ticksToPrice(tp_points / tickSize))
else
// au-dessus de 4*std dev -> ne pas placer
endif
else
BUY_STOP baseQty CONTRACTS AT buyStopPrice
SET TARGET (ticksToPrice(tp_points / tickSize))
endif
endif
// 2) Setup secondaire : premier chandelier haussier et SAR haussier (flip depuis bearish) => BUYTOP 2 ticks au-dessus du high
// “première bougie” est ici interprétée comme bougie de signal immédiate où prev_sar_bear = true and current_sar_bull = true
if isInSession and bull_candle and current_sar_bull and prev_sar_bear then
buyTopPrice = high + ticksToPrice(setup2_offset_ticks)
if close > vwap then
if buyTopPrice <= vwap + vwapStdMultiplierMax * vwap_dev then
BUY_STOP baseQty CONTRACTS AT buyTopPrice
SET TARGET (ticksToPrice(tp_points / tickSize))
endif
else
BUY_STOP baseQty CONTRACTS AT buyTopPrice
SET TARGET (ticksToPrice(tp_points / tickSize))
endif
endif
// Symétrique : première bougie baissière et SAR baissier => SELLSTOP 2 ticks sous low
if isInSession and bear_candle and current_sar_bear and prev_sar_bull then
sellTopPrice = low – ticksToPrice(setup2_offset_ticks)
if close > vwap then
// si cours au-dessus du VWAP, on n’exécute que buy stops -> donc ignorer
else
SELL_STOP baseQty CONTRACTS AT sellTopPrice
SET TARGET (ticksToPrice(tp_points / tickSize))
endif
endif
// ———- Gestion des Stop Loss et Reverse ———-
// Si le cours va à l’inverse du signal après entrée, prendre un reverse :
// – Ouvrir position inverse avec double lots, entrée 1 tick au-dessus du plus haut de la bougie signal (pour SELL->reverse BUY)
// – Target profit = 50% amplitude bougie précédente + 1 tick
// Exemple de détection d’un trade en perte (simplifié) :
// (Cela devra être adapté selon la gestion des positions réelles dans ProRealTime)
/* PSEUDO-CODE:
if positionOpen and positionIsLosing then
// calcul reverse
reverseEntryPrice = if (positionType = “BUY”) then lowSignalCandle – ticksToPrice(reverseEntryOffsetTicks) else highSignalCandle + ticksToPrice(reverseEntryOffsetTicks)
reverseQty = baseQty * reverseLotMultiplier
// ouvrir la position reverse
if positionType = “BUY” then
SELL reverseQty CONTRACTS AT reverseEntryPrice
else
BUY reverseQty CONTRACTS AT reverseEntryPrice
endif
// target reverse = 0.5 * amplitude bougie precedente + 1 tick
prev_amp = abs(high[1] – low[1])
reverseTP = 0.5 * prev_amp + ticksToPrice(1)
SET TARGET reverseTP
endif
*/
// ———- Notes finales ———-
// – La syntaxe exacte des commandes d’ordre (BUY_STOP / SELL_STOP / SET TARGET / SET STOP) varie selon la version
// ProRealTime/ProBuilder. Adaptez la section “Placer sell/buy stop” à la syntaxe correcte :
// Exemples possibles :
// BUY 1 CONTRACT AT market
// BUY 1 CONTRACT LIMIT price
// BUY 1 CONTRACT STOP price
// SET TARGET points
// SET STOP points
// – Tester sur données historiques en UT choisie (paramètre UT) et vérifier conversions tickSize
// – Ajuster volatilityThreshold, tickSize selon instrument (par ex NQ tick réel = 0.25)
// – Sécuriser la gestion des ordres (une seule entrée active à la fois, cancel pending orders après expiration, etc.)
// Si vous voulez, je peux :
// 1) adapter ce code à la syntaxe exacte de votre version ProRealTime (si vous me dites la version),
// 2) transformer les sections pseudocode en commandes valides et testées,
// 3) fournir un script prêt à backtester avec paramètres exportables.
// FIN