Sospendere e far ripartire il TS dopo n stop consecutivi
Forums › ProRealTime forum Italiano › Supporto ProOrder › Sospendere e far ripartire il TS dopo n stop consecutivi
- This topic has 1 reply, 2 voices, and was last updated 2 days ago by
robertogozzi.
-
-
10/17/2025 at 6:38 PM #252708
Buongiorno, vorrei sapere se è possibile codificare la seguente situazione. Vorrei che il sistema (che opera nell’intraday) dopo un certo numero di stop consecutivi si fermasse e che si riavviasse solo dopo che si è verificata una nuova condizione (ossia che c’è stato un trade positivo ad esempio). Ovviamente per sapere se negli eventuali trade che il sistema avrebbe fatto (se non lo avessi stoppato) arriva un trade positivo (quindi parliamo a distanza anche di diversi giorni o settimane) il sistema dovrebbe in un certo senso continuare a fare i trade virtualmente e “riaccendersi” live quando finalmente il trade vincente arriva. In pratica replicare la situazione in cui se una sistema non funziona, lo spegni, poi ovviamente dovresti continuare a monitorarlo in paper trading, e riavviarlo poi manualmente quando hai deciso che diciamo “torna a funzionare”. Si può automatizzare qualcosa del genere? Ho visto altri esempi in cui con la funzione quit, dopo un certo numero di trade, il sistema può essere interrotto ma poi bisogna riavviarlo manualmente. Grazie
10/17/2025 at 9:06 PM #252709Si, si può fare. Quando arrivano gli stop si simulano le operazioni (che non saranno al 100% identiche al reale, a causa di slippage, volatilità del mercato, ecc…). Esempio:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586ONCE MaxLosses = 3ONCE TradingON = 1ONCE myLosses = 0ONCE SL = 0.5 //0.5%ONCE TP = 4.5 //1.5%Sma = average[20,0](close)IF TradingON THEN// variables to be used for simulationsOnMarketStatus = 0LongOnMarketStatus = 0ShortOnMarketStatus = 0// conditions to enter real tradesmyLongConditions = close CROSSES OVER Sma AND Not OnMarketmyShortConditions = close CROSSES UNDER Sma AND Not OnMarketIF myLongConditions THENBUY 1 CONTRACT AT MARKETELSIF myShortConditions THENSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP %LOSS SLSET TARGET %PROFIT TPIF StrategyProfit <> StrategyProfit[1] THENIF StrategyProfit > StrategyProfit[1] THENmyLosses = 0ELSIF StrategyProfit < StrategyProfit[1] THENmyLosses = myLosses + 1IF myLosses = MaxLosses THENTradingON = 0ENDIFENDIFENDIFELSEmyLosses = 0// --- simulation starts here after MaxLosses consecutive losses//// conditions to enter simulated tradesmyLongConditions = close CROSSES OVER Sma AND Not OnMarketStatusmyShortConditions = close CROSSES UNDER Sma AND Not OnMarketStatusLongTradeStarted = 0ShortTradeStarted = 0IF myLongConditions THEN// Long simulated tradeLongTradeStarted = 1LongOnMarketStatus = 1ShortOnMarketStatus = 0mySL = close - (close * SL / 100)myTP = close + (close * TP / 100)ELSIF myShortConditions THEN// Short simulated tradeShortTradeStarted = 1LongOnMarketStatus = 0ShortOnMarketStatus = 1mySL = close + (close * SL / 100)myTP = close - (close * TP / 100)ENDIFOnMarketStatus = LongOnMarketStatus OR ShortOnMarketStatusIF OnMarketStatus THENIF LongOnMarketStatus THEN// check Long simulated tradeIF low <= mySL THENLongOnMarketStatus = 0 //it's not a profitable trade, DO NOTHING and keep simulatingELSIF high >= myTP THENLongOnMarketStatus = 0 //it's a profitable trade, resume Real tradingTradingON = 1ENDIFELSIF ShortOnMarketStatus THEN// check Short simulated tradeIF high >= mySL THENShortOnMarketStatus = 0 //it's not a profitable trade, DO NOTHING and keep simulatingELSIF low <= myTP THENShortOnMarketStatus = 0 //it's a profitable trade, resume Real tradingTradingON = 1ENDIFENDIFOnMarketStatus = LongOnMarketStatus OR ShortOnMarketStatusENDIF// --- Simulation ends ehereENDIF//graph TradingON = 1 AS "Real Trading"//graph TradingON = 0 AS "Simulated Trading"//graph LongTradeStarted AS "LONG trade entered" coloured("Green")//graph ShortTradeStarted AS "SHORT trade entered" coloured("Red")//graph myLosses = MaxLosses AS "Stop Real Trading" coloured ("Cyan")//graph StrategyProfit > StrategyProfit[1] coloured("Green")//graph StrategyProfit < StrategyProfit[1] coloured("Red")//graph myLosses1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on