ProRealCode - Trading & Coding with ProRealTime™
Ha ragione, la media mobile che ho usato sul codice qui sopra è la ema3 invece quella che uso normalmente è la ema 13.
Può guardare l’errore del sistema (usando il codice che le posto di seguito)
su AMD il giorno 15/09 ore 15:33 entrata short, primo take con scarico di metà posizione alle 15:36 e poi sarebbe dovuto uscire a breakeven alle 15:39 invece esce con lo stoploss alle 15:48.
su AMD il giorno 09/09 entrata long 15:39 primo take ore 16:00 sarebbe dovuto uscire a breakeven alle 16:15 invece mi esce alla chiusura del sistema.
su AMD il giorno 24/08 ore15:54 entrata long, primo take ore 16:06,sarebbe dovuto uscire con stop a breakeven alle16:15 invece mi esce con lo stop loss alle 16:33.
Il problema è solo lo stop che no si sposta a breakeven dopo aver preso il primo take.
Opero con prt.
Grazie i anticipo.
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
//DEFPARAM FLATBEFORE = 153600
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
//DEFPARAM FLATAFTER = 180000
DEFPARAM FLATBEFORE = 153300
DEFPARAM FLATAFTER = 180000
IF Not OnMarket THEN
Entrata = 0
Uscita = 0
ENDIF
IF (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Entrata = TradePrice
Uscita = TradePrice + (TradePrice * 0.0025) //0.25%
IF ShortOnMarket THEN
Uscita = TradePrice - (TradePrice * 0.0025) //0.25%
ENDIF
ENDIF
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
// Condizioni per entrare su posizioni long
indicator1 = ExponentialAverage[13](close)
indicator2, ignored = CALL "max/min premarket"
c1 = (indicator1 CROSSES OVER indicator2)
indicator3, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
indicator4, ignored = CALL "max/min premarket"
c2 = (indicator3 CROSSES OVER indicator4)
IF (c1 OR c2) AND not daysForbiddenEntry and OTD AND Not LongOnMarket THEN
BUY 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata + (Entrata * 0.0025) //0.25%
ENDIF
// Condizioni per entrare su posizioni short
indicator5 = ExponentialAverage[13](close)
ignored, indicator6 = CALL "max/min premarket"
c3 = (indicator5 CROSSES UNDER indicator6)
indicator7, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
ignored, indicator8 = CALL "max/min premarket"
c4 = (indicator7 CROSSES UNDER indicator8)
IF (c3 OR c4) AND not daysForbiddenEntry and OTD AND Not ShortOnMarket THEN
SELLSHORT 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata - (Entrata * 0.0025) //0.25%
ENDIF
IF (Uscita > 0) THEN
IF LongOnMarket AND close > Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
SELL Posizioni SHARES AT Market
Uscita = 0
SET STOP BreakEven
ELSIF ShortOnMarket AND close < Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
EXITSHORT Posizioni SHARES AT Market
Uscita = 0
SET STOP BreakEven
ENDIF
ENDIF
// Stop e target
SET STOP %LOSS 1
SET TARGET %PROFIT 0
//
graphonprice Entrata coloured(0,0,255,255)
graphonprice Uscita coloured(255,0,0,255)
graphonprice PositionPrice
Credo di avere risolto il problema sostituendo la seconda uscita in pareggio con ordini pendenti, invece di usare SET STOP:
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
//DEFPARAM FLATBEFORE = 153600
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
//DEFPARAM FLATAFTER = 180000
DEFPARAM FLATBEFORE = 153300
DEFPARAM FLATAFTER = 180000
IF Not OnMarket OR (xy = 1) THEN
Entrata = 0
Uscita = 0
ENDIF
IF Not Uscita AND Uscita[1] THEN
IF LongOnMarket THEN
SELL AT StopPrice STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT StopPrice STOP
ENDIF
ENDIF
IF (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Entrata = TradePrice
Uscita = TradePrice + (TradePrice * 0.0025) //0.25%
IF ShortOnMarket THEN
Uscita = TradePrice - (TradePrice * 0.0025) //0.25%
ENDIF
ENDIF
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
// Condizioni per entrare su posizioni long
indicator1 = ExponentialAverage[13](close)
indicator2, ignored = CALL "max/min premarket"
c1 = (indicator1 CROSSES OVER indicator2)
indicator3, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
indicator4, ignored = CALL "max/min premarket"
c2 = (indicator3 CROSSES OVER indicator4)
IF (c1 OR c2) AND not daysForbiddenEntry and OTD AND Not LongOnMarket THEN
BUY 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata + (Entrata * 0.0025) //0.25%
ENDIF
// Condizioni per entrare su posizioni short
indicator5 = ExponentialAverage[13](close)
ignored, indicator6 = CALL "max/min premarket"
c3 = (indicator5 CROSSES UNDER indicator6)
indicator7, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
ignored, indicator8 = CALL "max/min premarket"
c4 = (indicator7 CROSSES UNDER indicator8)
IF (c3 OR c4) AND not daysForbiddenEntry and OTD AND Not ShortOnMarket THEN
SELLSHORT 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata - (Entrata * 0.0025) //0.25%
ENDIF
xy = 0
IF (Uscita > 0) THEN
IF LongOnMarket AND close > Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
SELL Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
SELL AT StopPrice STOP
xy = 1//Uscita = 0
ELSIF ShortOnMarket AND close < Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
EXITSHORT Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
EXITSHORT AT StopPrice STOP
xy = 1//Uscita = 0
ENDIF
ENDIF
// Stop e target
SET STOP %LOSS 1
SET TARGET %PROFIT 0
//
graphonprice Entrata coloured(0,0,255,255)
graphonprice Uscita coloured(255,0,0,255)
graphonprice PositionPrice
Ho provato a guardare come gira il programma a mercato chiuso. sembra funzionare.
Grazie mille e Complimenti!!!
Salve, ho provato a fare girare un pò il sistema e ho notato una cosa che non so se si può risolvere.
Faccio riferimento all’ultimo codice che è qua sopra,
Ho spostato il primo target da lei impostato da 0.25 (che per me è troppo stretto) a 0.5.
Le spiego: il sistema entra in posizione all’apertura della candela successiva ( e questo lo sapevo), il problema è che l’uscita a breakeven avviene sul punto dove c’è stato il segnale di ingresso e non sul punto dell’effettivo eseguito come vorrei io .
Un esempio long lo può trovare su NVDA 3 minuti il giorno 06/11, entrata ore 15:36 a 134,29, primo target a 135,78,uscita 132,93 dove è avvenuto il segnale di ingresso.
Un’altro comportamento anomalo lo trova su NVDA 3 min. il giorno 19/09 entrta alle 16:27 a 133,19, primo target a 134,06, chiusura posizione alle 17:54 a131,81
Grazie in anticipo.
Non ho nessuna operazione in quelle date, con 0.5%.
Posta il file ITF che hai usato.
NVDA il giorno 12/10 ore16:15 entrata short, primo take preso alle 16:45 uscita in perdita alle 17:21,
NVDA il giorno 07/10 ore 17:30 entrata short, non prende il take profit allo 0.5% ,
NVDA il giorno 06/10 ore15:36 entrata long, prende il profit alle 15:42 , uscita in perdita alle 16:03.
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l’orario “Flat Before” non saranno piazzati nuovi ordini o posizioni.
//DEFPARAM FLATBEFORE = 153600
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all’orario “Flat After”
//DEFPARAM FLATAFTER = 180000
DEFPARAM FLATBEFORE = 153300
DEFPARAM FLATAFTER = 180000
IF Not OnMarket OR (xy = 1) THEN
Entrata = 0
Uscita = 0
ENDIF
IF Not Uscita AND Uscita[1] THEN
IF LongOnMarket THEN
SELL AT StopPrice STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT StopPrice STOP
ENDIF
ENDIF
IF (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Entrata = TradePrice
Uscita = TradePrice + (TradePrice * 0.005) //0.5%
IF ShortOnMarket THEN
Uscita = TradePrice – (TradePrice * 0.005) //0.5%
ENDIF
ENDIF
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
OTD = (Barindex – TradeIndex(1) > IntradayBarIndex)
// Condizioni per entrare su posizioni long
indicator1 = ExponentialAverage[13](close)
indicator2, ignored = CALL “max/min premarket”
c1 = (indicator1 CROSSES OVER indicator2)
indicator3, ignored, ignored, ignored, ignored, ignored, ignored = CALL “PRC_VWAP intraday”
indicator4, ignored = CALL “max/min premarket”
c2 = (indicator3 CROSSES OVER indicator4)
IF (c1 OR c2) AND not daysForbiddenEntry and OTD AND Not LongOnMarket THEN
BUY 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata + (Entrata * 0.005) //0.5%
ENDIF
// Condizioni per entrare su posizioni short
indicator5 = ExponentialAverage[13](close)
ignored, indicator6 = CALL “max/min premarket”
c3 = (indicator5 CROSSES UNDER indicator6)
indicator7, ignored, ignored, ignored, ignored, ignored, ignored = CALL “PRC_VWAP intraday”
ignored, indicator8 = CALL “max/min premarket”
c4 = (indicator7 CROSSES UNDER indicator8)
IF (c3 OR c4) AND not daysForbiddenEntry and OTD AND Not ShortOnMarket THEN
SELLSHORT 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata – (Entrata * 0.005) //0.5%
ENDIF
xy = 0
IF (Uscita > 0) THEN
IF LongOnMarket AND close > Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
SELL Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
SELL AT StopPrice STOP
xy = 1//Uscita = 0
ELSIF ShortOnMarket AND close < Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
EXITSHORT Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
EXITSHORT AT StopPrice STOP
xy = 1//Uscita = 0
ENDIF
ENDIF
// Stop e target
SET STOP %LOSS 1
SET TARGET %PROFIT 0
//
graphonprice Entrata coloured(0,0,255,255)
graphonprice Uscita coloured(255,0,0,255)
graphonprice PositionPrice
Le riposto il codice scritto meglio.
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
//DEFPARAM FLATBEFORE = 153600
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
//DEFPARAM FLATAFTER = 180000
DEFPARAM FLATBEFORE = 153300
DEFPARAM FLATAFTER = 180000
IF Not OnMarket OR (xy = 1) THEN
Entrata = 0
Uscita = 0
ENDIF
IF Not Uscita AND Uscita[1] THEN
IF LongOnMarket THEN
SELL AT StopPrice STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT StopPrice STOP
ENDIF
ENDIF
IF (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Entrata = TradePrice
Uscita = TradePrice + (TradePrice * 0.005) //0.5%
IF ShortOnMarket THEN
Uscita = TradePrice - (TradePrice * 0.005) //0.5%
ENDIF
ENDIF
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
// Condizioni per entrare su posizioni long
indicator1 = ExponentialAverage[13](close)
indicator2, ignored = CALL "max/min premarket"
c1 = (indicator1 CROSSES OVER indicator2)
indicator3, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
indicator4, ignored = CALL "max/min premarket"
c2 = (indicator3 CROSSES OVER indicator4)
IF (c1 OR c2) AND not daysForbiddenEntry and OTD AND Not LongOnMarket THEN
BUY 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata + (Entrata * 0.005) //0.5%
ENDIF
// Condizioni per entrare su posizioni short
indicator5 = ExponentialAverage[13](close)
ignored, indicator6 = CALL "max/min premarket"
c3 = (indicator5 CROSSES UNDER indicator6)
indicator7, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
ignored, indicator8 = CALL "max/min premarket"
c4 = (indicator7 CROSSES UNDER indicator8)
IF (c3 OR c4) AND not daysForbiddenEntry and OTD AND Not ShortOnMarket THEN
SELLSHORT 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata - (Entrata * 0.005) //0.5%
ENDIF
xy = 0
IF (Uscita > 0) THEN
IF LongOnMarket AND close > Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
SELL Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
SELL AT StopPrice STOP
xy = 1//Uscita = 0
ELSIF ShortOnMarket AND close < Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
EXITSHORT Posizioni SHARES AT Market
//SET STOP PRICE Entrata//SET STOP BreakEven
StopPrice = Entrata
EXITSHORT AT StopPrice STOP
xy = 1//Uscita = 0
ENDIF
ENDIF
// Stop e target
SET STOP %LOSS 1
SET TARGET %PROFIT 0
//
graphonprice Entrata coloured(0,0,255,255)
graphonprice Uscita coloured(255,0,0,255)
graphonprice PositionPrice
Ho solo l’operazione del 6/10, ma sfalzata di una candela (a me entra 3 minuti prima, alle 15:33), però ho visto dov’era il problema e l’ho risolto.
Ecco il nuovo codice:
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
//DEFPARAM FLATBEFORE = 153600
// Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
//DEFPARAM FLATAFTER = 180000
DEFPARAM FLATBEFORE = 153300
DEFPARAM FLATAFTER = 180000
IF Not OnMarket THEN
Entrata = 0
Uscita = 0
ENDIF
IF Not Uscita AND Uscita[1] THEN
IF LongOnMarket THEN
SELL AT Entrata STOP
ELSIF ShortOnMarket THEN
EXITSHORT AT Entrata STOP
ENDIF
ENDIF
IF (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Entrata = TradePrice
Uscita = TradePrice + (TradePrice * 0.005) //0.5%
IF ShortOnMarket THEN
Uscita = TradePrice - (TradePrice * 0.005) //0.5%
ENDIF
ENDIF
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
// Condizioni per entrare su posizioni long
indicator1 = ExponentialAverage[13](close)
indicator2, ignored = CALL "max/min premarket"
c1 = (indicator1 CROSSES OVER indicator2)
indicator3, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
indicator4, ignored = CALL "max/min premarket"
c2 = (indicator3 CROSSES OVER indicator4)
IF (c1 OR c2) AND not daysForbiddenEntry and OTD AND Not LongOnMarket THEN
BUY 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata + (Entrata * 0.005) //0.5%
ENDIF
// Condizioni per entrare su posizioni short
indicator5 = ExponentialAverage[13](close)
ignored, indicator6 = CALL "max/min premarket"
c3 = (indicator5 CROSSES UNDER indicator6)
indicator7, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"
ignored, indicator8 = CALL "max/min premarket"
c4 = (indicator7 CROSSES UNDER indicator8)
IF (c3 OR c4) AND not daysForbiddenEntry and OTD AND Not ShortOnMarket THEN
SELLSHORT 30 SHARES AT MARKET
Entrata = close
Uscita = Entrata - (Entrata * 0.005) //0.5%
ENDIF
IF (Uscita > 0) THEN
IF LongOnMarket AND close > Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
SELL Posizioni SHARES AT Market
SELL AT Entrata STOP
Uscita = -1
ELSIF ShortOnMarket AND close < Uscita THEN
Posizioni = round(abs(CountOfPosition) / 2,1)
EXITSHORT Posizioni SHARES AT Market
EXITSHORT AT Entrata STOP
Uscita = -1
ENDIF
ELSIF (Uscita = - 1) THEN
IF LongOnMarket AND close > Entrata THEN
SELL AT Entrata STOP
ELSIF ShortOnMarket AND close < Entrata THEN
EXITSHORT AT Entrata STOP
ENDIF
ENDIF
// Stop e target
SET STOP %LOSS 1
SET TARGET %PROFIT 0
//
graphonprice Entrata coloured(0,0,255,255)
graphonprice Uscita coloured(255,0,0,255)
graphonprice PositionPrice
A mercato chiuso sembra funzionare, grazie mille.
Entrata long o short su sfondamento MIn/Max premercato su ritracciamento
This topic contains 38 replies,
has 2 voices, and was last updated by Enrico
3 years, 4 months ago.
| Forum: | ProOrder: Trading Automatico & Backtesting |
| Language: | Italian |
| Started: | 08/29/2022 |
| Status: | Active |
| Attachments: | 1 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.