sistema stop&reverce che non funziona
Forums › ProRealTime forum Italiano › Supporto ProOrder › sistema stop&reverce che non funziona
- This topic has 5 replies, 2 voices, and was last updated 1 year ago by KAMJKAZE.
-
-
02/10/2023 at 10:46 AM #209471
salve a tutti,
da qualche tempo sto studiando dei sistemi di stop and reverce, che alcune volte funzionano ed altre no…
questo è il caso del sistema in questione
ho provato diverse possibilità di scrittura ma non ne sono venuto a capo.
il sistema è multitimeframe:
stop and reverce123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141TIMEFRAME (4H,UPDATEONCLOSE)RSI14LONG= RSI[14](close)>=50CCILONG= CCI[20](typicalPrice)>=0MEDIA20EXPO= CLOSE CROSSES OVER ExponentialAverage[20](close)IF RSI14LONG AND CCILONG AND MEDIA20EXPO AND REVERCE=0 THENBUY 1 CONTRACT AT MARKETSTOPPE=(LOWEST[2](LOW))ENDIFTIMEFRAME (15MN,DEFAULT)IF LONGONMARKET AND REVERCE=0 THENSET TARGET %PROFIT 2SELL AT STOPPE STOPreverce=0ENDIF//trailingstop// NewTrade is true whenever a new trade is opened, be it://// - a trade when there was none previously// - a trade that has changed direction due to a Stop & Reverse (it's Long and previously was Short and viceversa)//// This will be useful to reset variables to their initial values after a trade has been opened.//NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket)//// Reset variables to their initial value when a new trade shows//IF Not OnMarket and reverce=0 OR NewTrade and reverce=0 THEN //reset to default values when a new trade has been opened (or none is OnMarket)PerCentTP = 1.0 //2.0% is TPPerCentStart = x //0.2% is the Trailing Stop trigger levelPerCentStep = y //0.2% is each subsequent stepPerCentSaved = z //0.1% is how much profit has to be saved when trailing starts and every stepMultiplier = M //1.5 is how much PerCentSaved is incremented each trailing step// 1.5 is a 50% increment, so that:// 0.1% becomes 0.15%, then// 0.15% becomes 0.225%, then// 0.225% becomes 0.3375%, etc...Distance = 6 //6 pip distance from current price (if required by the broker)MySL = 0ProfitPerCent = 0ENDIF//// The trailing stop can operate only when OnMarket//IF OnMarket AND REVERCE=0 THEN//// before the trailing stop is triggered some calculations need to be done, accordin to settings//IF MySL = 0 THENPCent = PositionPrice * PerCentTP / 100PStart = PositionPrice * PerCentStart / 100PStep = PositionPrice * PerCentStep / 100PSaved = PositionPrice * PerCentSaved / 100ENDIF//// check if Trailing Stop has to be triggered//IF MySL = 0 THENIF LongOnMarket THENIF (close - PositionPrice) >= PStart THENMySL = min(close,PositionPrice + PSaved)PSaved = PSaved * MultiplierENDIFELSIF ShortOnMarket THENIF (PositionPrice - close) >= PStart THENMySL = max(close,PositionPrice - PSaved)PSaved = PSaved * MultiplierENDIFENDIFELSE//// check if another Step has been triggered//IF LongOnMarket THENIF (close - MySL) >= PStep THENMySL = min(close,MySL + PSaved)PSaved = PSaved * MultiplierENDIFELSIF ShortOnMarket THENIF (MySL - close) >= PStep THENMySL = max(close,MySL - PSaved)PSaved = PSaved * MultiplierENDIFENDIFENDIF//// place Pending STOP orders//IF MySL > 0 and reverce=0 THENIF (MySL = close) OR (abs(MySL - close) < Distance) THEN //exit immediately in case MySL has reached// the current price or there's not enough DISTANCESELL AT MARKETEXITSHORT AT MARKETELSESELL AT MySL STOPEXITSHORT AT MySL STOPENDIFENDIFENDIF//revercesideIF NOT ONMARKET THENreverce=0ENDIFIF LONGONMARKET and POSITIONPERF<0 and CLOSE CROSSES UNDER DonchianChannelDown[10] THENSELL AT MARKETREVERCE= 1ENDIFIF longonmarket[1] AND REVERCE=1 THENSELLSHORT 1 CONTRACT AT MARKETSTOPPEREVERCE= HIGHEST[1] (HIGH)TARGETREVERCE= CLOSE-((HIGHEST[1](HIGH)- CLOSE))reverce=1ENDIFIF SHORTONMARKET and reverce=1 THENEXITSHORT AT STOPPEREVERCE STOPEXITSHORT AT TARGETREVERCE stopENDIFif shortonmarket[1] or not onmarket thenreverce=0endifGRAPHONPRICE TARGETREVERCEGRAPHONPRICE STOPPEREVERCEGRAPH REVERCEil primo ingresso è solo long, la condizione principale è sulle 4h, l’entry e il trailing stop a 15 minuti
il reverce entra in funzione nella condizione in cui il close cross under il canale di donchian a 10 periodi.
vi allego il sistema è uno screeshot del problema.
02/10/2023 at 12:43 PM #209502Le righe 123-128 toglile e scrivi queste al posto delle righe 119-120:
123SELLSHORT 1 CONTRACT AT MARKETSTOPPEREVERCE= HIGHEST[1] (HIGH)TARGETREVERCE= CLOSE-((HIGHEST[1](HIGH)- CLOSE))02/10/2023 at 12:49 PM #209503Però c’è un altro errore logico, TARGETREVERCE e STOPPEREVERCE non possono essere piazzati entrambi come ordini pendenti dello stesso tipo, se uno è STOP l’altro dovrebbe essere LIMIT.
02/10/2023 at 3:28 PM #209516ciao roberto,
intanto grazie,
alcune cose che non ho capito:
1: io per indicare il trade principale e il reverce utilizzo una variabile (reverce=0/1) , serve o non serve in questo sistema in particolare o in generale?
2: quindi posso entrare in una posizione short senza chiudere una posizione long in essere? in quel caso viene eseguita subito o alla prossima barra?
3 : le righe 130-133 io ho provato tutte le combinazioni sia con ordini pendenti stop/limit; limit/stop ecc eppure mi da backtest mi salta lo stop o il target o entrambi.
non ne cavo un ragno dal buco…
02/10/2023 at 4:42 PM #2095221. Non serve, ma se ti serve per SL e TP degli Short, lascialo:
2. quando entri Long prima chiude eventuali operazioni Short aperte, poi apre la nuova operazione Long. L’opposto per lo Short;
3. STOP si usa quando il prezzo di uscita è peggiorativo rispetto all’attuale (ad esempio SL), mentre LIMIT si usa quando è migliorativo (ad esempio TP).
Esempio di entrata SENZA Stop & Reverse:
1234567If Not OnMarket thenIf CondizioniLong thenBuy at MarketElsIf CondizioniShort thenSellShort at MarketEndifEndifEsempio di entrata CON Stop & Reverse:
12345If Not LongOnMarket and CondizioniLong thenBuy at MarketElsIf Not ShortOnMarket and CondizioniShort thenSellShort at MarketEndif02/14/2023 at 7:23 PM #209683 -
AuthorPosts
Find exclusive trading pro-tools on