Controllo codice maxTrades x day
Forums › ProRealTime forum Italiano › Supporto ProOrder › Controllo codice maxTrades x day
- This topic has 19 replies, 5 voices, and was last updated 2 years ago by MauroPro.
-
-
05/07/2022 at 12:58 PM #192860
Ciao Roberto, ho provato un tuo codice per la determinazione del massimo numero di operazioni al giorno che mi piace come è scritto, ma, a volte, dà dei risultati differenti (e penso sbagliati) rispetto ad un codice classico che uso (ma che mi piace di meno come è scritto) per ottenere lo stesso risultato.
Il tuo nuovo codice lo ho ripreso dal seguente link [rif: 191639]: https://www.prorealcode.com/topic/help-coding-breakout-strategy/
Provando entrambi i codici su un TS di prova danno risultato differenti [ test su Nasdaq cfd – 10 minuti – 100k]. Sai quale può essere il motivo?
Ecco i codici con il TS di base:
PROVA A
123456789101112if intradayBarIndex=0 thencount=0endifif ( (not onMarket and onMarket[1] and not onMarket[2]) or (tradeIndex(1)=tradeIndex(2) and tradeIndex(1)=barIndex[1] and tradeIndex(1)>0) or (not onMarket and onMarket[1])) thencount = count+1endif//--------------------------------------------------------------if close crosses over average[50,0](close) and not onMarket and count < 3 thenbuy 1 contract at marketendifset target pProfit 100set stop pLoss 100PROVA B (tuo nuovo codice)
123456789101112131415once maxTrades = 3once tally = 0if intradayBarIndex = 0 thentally = 0endifnewTrades = (onMarket and not onMarket[1]) or (longOnMarket and shortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((not OnMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1]))if newTrades thentally = tally +1endif//--------------------------------------------------------------if close crosses over average[50,0](close) and not onMarket and tally < maxTrades thenbuy 1 contract at marketendifset target pProfit 100set stop pLoss 100Ed ecco il test:
05/07/2022 at 2:21 PM #192862Verificando le date e gli orari d’apertura, magari esportando il risultato su eXcel, in quali candele ci sono le differenze?
05/07/2022 at 8:40 PM #192867Ciao Roberto, ho trovato alcune operazioni discordanti.
1) In tutti i casi è lo snippet classico (prova A) che salta un operazione senza che sia chiaro il motivo. Ti segnalo alcune operazioni cosi puoi controllare il motivo del malfunzionamento: 21 settembre 2021 – 28 gennaio 2022 – 19 aprile 2022 (vd immagine A ed A2)
2) [Il 28 gennaio 2022 ( vd immagine B) poi c’è un operazione visibile nel probacktest ed anche nell’indicatore delle posizioni, ma non segnalata da nessuno dei due codici (e non presente quindi nel listato delle operazioni)
05/08/2022 at 10:12 AM #192880In merito alla prova A:
- il 21/9/2021 mi sembra corretto, si chiudono 3 operazioni ed il conto è 3 (una si era aperta il giorno prima)
- il 28/1/2022 stessa identica cosa, 3 chiusi ed il conto è 3
- il 19/4/2022 ancora identica cosa, 3 chiusi ed il conto è 3.
Le differenze sono dovute al fatto che il codice A fa una verifica diversa, quindi non tiene conto del fatto che un’operazione sia iniziata il giorno prima, mentre il codice B fa una verifica appena entrato a mercato, quindi se è del giorno precedente non influisce sul giorno successivo in quanto tu azzeri il conteggio con la prima barra del giorno dopo.
Per ottenere lo stesso risultato (non in senso finanziario, solo per il controllo delle operazioni fatte), aggiungi questa riga all’inizio:
1defparam flatafter = 2200001 user thanked author for this post.
05/08/2022 at 10:41 AM #192882Grazie, Roberto, penso di utilizzare il tuo codice B. Mi piace di più come è scritto e preferisco che il conteggio sia interno ad ogni giornata senza mischiare i giorni.
1 user thanked author for this post.
05/13/2022 at 8:49 AM #193140Ciao Roberto, ho provato il tuo codice sul massimo numero di operazioni aggiornato e le nuove istruzioni di Nicolas. Su questo TS molto semplice sono equivalenti.
1234567891011121314151617once maxTrades = 3 //maxNumberDailyTradesonce tally = 0if intradayBarIndex = 0 thentally = 0endifnewTrades = (onMarket and not onMarket[1]) or (longOnMarket and shortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((not OnMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1])) or ((tradeIndex(1) = tradeIndex(2)) and (barIndex = tradeIndex(1)) and (barIndex > 0) and (strategyProfit = strategyProfit[1]))if newTrades thentally = tally +1endif//--------------------------------------------------------------------------------if close crosses over average[50,0](close) and not longOnMarket and tally < maxTrades thenbuy 1 contract at marketendifset target pProfit 100set stop pLoss 1001234567891011121314once maxOrders = 3if intradayBarIndex = 0 then //reset orders countordersCount = 0endifif longTriggered then //check if an order has opened in the current barordersCount = ordersCount + 1endif//--------------------------------------------------------------------------------if close crosses over average[50,0](close) and not longOnMarket and ordersCount < maxOrders thenbuy 1 contract at marketendifset target pProfit 100set stop pLoss 1001 user thanked author for this post.
05/13/2022 at 10:54 AM #19314105/13/2022 at 11:51 AM #193150Oltre al limite degli ordini, uso la massima perdita giornaliere e l’attesa tra un trade e l’altro.
Ho assemblato questi 3 snipper in uno complessivo che chiamo: cManagemente (da aggiungere alle tue condizioni di entrata).
Se ti interessa ecco un esempio (puoi chiaramente ottimizzare i parametri.
12345678910111213141516171819202122232425262728293031323334353637383940414243//----------------------------------------------------------------maxDailyLoss = 200 //maxMonetaryDailyLossrealPosition=positionPerf*positionPrice/pointSize*pointValueonce tradeAllowed = 1if intradayBarIndex = 0 thenmyProfit=strategyProfittradeAllowed = 1endifif (strategyProfit+realPosition) <= (myProfit-maxDailyLoss) thentradeAllowed = 0endif//----------------------------------------------------------------------------------------------------------once maxTrades = 5 //maxNumberDailyTradesonce tally = 0if intradayBarIndex = 0 thentally = 0endifnewTrades = (onMarket and not onMarket[1]) or ((not onMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1])) or (longOnMarket and ShortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((tradeIndex(1) = tradeIndex(2)) and (barIndex = tradeIndex(1)) and (barIndex > 0) and (strategyProfit = strategyProfit[1]))if newTrades thentally = tally +1endif//-------------------------------------------------------------------------------------------------------once barCount = 0 //barsToWaitAfterTradewaitingBars = 10once tradeCount = 1newTrades = (onMarket and not onMarket[1]) or ((not onMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1])) or (longOnMarket and ShortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((tradeIndex(1) = tradeIndex(2)) and (barIndex = tradeIndex(1)) and (barIndex > 0) and (strategyProfit = strategyProfit[1]))if newTrades thentradeCount = 0barCount = 0endifif not longOnMarket thenbarCount = barCount + 1endifif barCount > waitingBars thentradeCount = 1endif//**********************************************************************************************cManagement = tradeAllowed and tally < maxTrades and barCount > waitingBars//***********************************************************************************************1 user thanked author for this post.
05/13/2022 at 12:12 PM #19315105/13/2022 at 9:22 PM #193167@Mauro
È possibile che questo codice genera uno per 0 errori? Ho aggiunto questa variante al mio codice … backtest völlig in ordine, ma quando si avvia il messaggio di errore viene che un indicatore mostra un valore negativo.//Max-Orders per Day
once maxOrdersL = maxiL
once maxOrdersS = maxiS
if intradayBarIndex = 0 then //reset orders count
ordersCountL = 0
ordersCountS = 0
endifif longTriggered then //check if an order has opened in the current bar
ordersCountL = ordersCountL + 1
endif
if shortTriggered then //check if an order has opened in the current bar
ordersCountS = ordersCountS + 1
endif
//05/13/2022 at 9:49 PM #193168Lo ho testato in questo TS di prova e funziona.
12345678910111213141516171819202122232425262728//S&P 500 - 15m - test: 50k//-------------------------------//Max-Orders per Dayonce maxOrdersL = maxiLonce maxOrdersS = maxiSif intradayBarIndex = 0 then //reset orders countordersCountL = 0ordersCountS = 0endifif longTriggered then //check if an order has opened in the current barordersCountL = ordersCountL + 1endifif shortTriggered then //check if an order has opened in the current barordersCountS = ordersCountS + 1endif////-------------------------------------------------------------------------if close crosses over average[50,0](close) and not onMarket and ordersCountL < maxOrdersL thenbuy 1 contract at marketendifif close crosses under average[50,0](close) and not onMarket and ordersCountS < maxOrdersS thensellShort 1 contract at marketendif//-----------------------------------------------------------------------set target pProfit 100set stop pLoss 5005/13/2022 at 9:53 PM #19317005/17/2022 at 4:33 PM #19334205/20/2022 at 9:53 AM #193482Ciao, mauro
Torno da voi perché sto cercando di integrare il vostro codice qui allegato se non sbaglio
Dalla linea 32 del mio algo, ma senza la condizione di media 50, non succede nulla cambiando i miei take profit e stop che sono 11 e 34 e un’operazione al giorno.
Se puoi, puoi farmi una copia di come la inseriresti nel mio codice. Grazie.
Mi dispiace, sono ancora nelle prime fasi di creazione del codice.
nasdaq 30 sec avec rsi123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141// Définition des paramètres du codeDEFPARAM CumulateOrders = False // Cumul des positions désactivé// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"DEFPARAM FLATAFTER = 173000// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiéenoEntryBeforeTime = 153000timeEnterBefore = time >= noEntryBeforeTime// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 173000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position acheteuseindicator1 = RSI[14](close)c1 = (indicator1 CROSSES OVER 30)IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETENDIF// Conditions pour ouvrir une position en vente à découvertindicator2 = RSI[14](close)c2 = (indicator2 CROSSES UNDER 70)IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETENDIFonce maxOrders = 1if intradayBarIndex = 0 then //reset orders countordersCount = 0endifif longTriggered then //check if an order has opened in the current barordersCount = ordersCount + 1endif// Stops et objectifsSET STOP pTRAILING 31SET TARGET pPROFIT 11IF Not OnMarket THEN//// when NOT OnMarket reset values to default values//TrailStart = 5 //30 Start trailing profits from this pointBasePerCent = 0.000 //20.0% Profit percentage to keep when setting BerakEvenStepSize = 10 //10 Pip chunks to increase PercentagePerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkBarNumber = 10 //10 Add further % so that trades don't keep running too longBarPerCent = 0.100 //10% Add this additional percentage every BarNumber barsRoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviourPriceDistance = 7 * pipsize //7 minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0ProfitPerCent = BasePerCent //reset to desired default valueTradeBar = BarIndexELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG positions//// compute the value of the Percentage of profits, if any, to lock in for LONG trades//x1 = (close - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - x1) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profitENDIFELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN //SHORT positions//// compute the value of the Percentage of profits, if any, to lock in for SHORT trades//x2 = (tradeprice - close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN // go ahead only if N+ pipsDiff2 = abs(TrailStart - x2) //difference from current profit and TrailStartChunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profitENDIFENDIFIF y1 THEN //Place pending STOP order when y1 > 0 (LONG positions)SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - SellPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSE////sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//SELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y2 > 0 (SHORT positions)ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - ExitPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSE////ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//EXITSHORT AT MarketENDIFENDIF05/20/2022 at 11:54 AM #193495Devi inserire l’istruzione anche nelle condizioni di acquisto e vendita.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149// Définition des paramètres du codeDEFPARAM CumulateOrders = False // Cumul des positions désactivé// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"DEFPARAM FLATAFTER = 173000// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiéenoEntryBeforeTime = 153000timeEnterBefore = time >= noEntryBeforeTime// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 173000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position acheteuseindicator1 = RSI[14](close)c1 = (indicator1 CROSSES OVER 30)IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry and ordersCountL < maxOrdersL THENBUY 1 CONTRACT AT MARKETENDIF// Conditions pour ouvrir une position en vente à découvertindicator2 = RSI[14](close)c2 = (indicator2 CROSSES UNDER 70)IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry and ordersCountS < maxOrdersS THENSELLSHORT 1 CONTRACT AT MARKETENDIF//---------------------------------------------------------------------------------------------------------------//Max-Orders per Dayonce maxOrdersL = 1 //longonce maxOrdersS = 1 //shortif intradayBarIndex = 0 then //reset orders countordersCountL = 0ordersCountS = 0endifif longTriggered then //check if an order has opened in the current barordersCountL = ordersCountL + 1endifif shortTriggered then //check if an order has opened in the current barordersCountS = ordersCountS + 1endif//------------------------------------------------------------------------------------------------------------------------// Stops et objectifsSET STOP pTRAILING 31SET TARGET pPROFIT 11IF Not OnMarket THEN//// when NOT OnMarket reset values to default values//TrailStart = 5 //30 Start trailing profits from this pointBasePerCent = 0.000 //20.0% Profit percentage to keep when setting BerakEvenStepSize = 10 //10 Pip chunks to increase PercentagePerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkBarNumber = 10 //10 Add further % so that trades don't keep running too longBarPerCent = 0.100 //10% Add this additional percentage every BarNumber barsRoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviourPriceDistance = 7 * pipsize //7 minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0ProfitPerCent = BasePerCent //reset to desired default valueTradeBar = BarIndexELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG positions//// compute the value of the Percentage of profits, if any, to lock in for LONG trades//x1 = (close - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - x1) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profitENDIFELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN //SHORT positions//// compute the value of the Percentage of profits, if any, to lock in for SHORT trades//x2 = (tradeprice - close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN // go ahead only if N+ pipsDiff2 = abs(TrailStart - x2) //difference from current profit and TrailStartChunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profitENDIFENDIFIF y1 THEN //Place pending STOP order when y1 > 0 (LONG positions)SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - SellPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSE////sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//SELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y2 > 0 (SHORT positions)ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - ExitPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSE////ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//EXITSHORT AT MarketENDIFENDIF1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on