ProRealCode - Trading & Coding with ProRealTime™
Buongiorno.
Premetto che sono un novizio ed è la prima volta che scrivo su questo forum, e sicuramente la cosa chi chiedo avrà una soluzione semplicissima, praticamente la porzione di codice sotto entra a mercato in una direzione e poi quando ordine si becca lo stop, allora parte l’ordine pendente. Quando faccio partire il programma non mi entra più a mercato e non mi inserisce il pendente, cortesemente mi potreste aiutare a risolvere il problema?
Vi ringrazio tutti anticipatamente.
StopEntrataShortSTD = (high + SpreadEntrata) - close
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrataShortSTD)
IF NOT SHORTONMARKET THEN
EntrataPendenteLongSTD = close + max(StopMinimo, StopEntrataShortSTD) + 1
StopPendenteLongSTD = EntrataPendenteLongSTD - (low - SpreadPendente - MarginePendente)
BUY LotNumber CONTRACT AT EntrataPendenteLongSTD STOP
SET STOP pLOSS StopPendenteLongSTD
ENDIF
A parte altre considerazioni per le quali occorre riprodurre la situazione e serve il codice, lo strumento tradato ed il TF usato, alle linee 1 e 6 devi convertire la differenza di prezzo in pips MOLTIPLICANDO quel risultato * PIPSIZE.
In alternativa puoi lasciare tutto così, però devi usare LOSS, non pLOSS, perché quella “p” sta per PIPS e non una semplice differenza di prezzo.
Se l’hai testato sul Dax, Nikkei o altri strumenti simili può funzionare ugualmente, su molti altri e sul Forex, hai risultati completamente errati sullo SL.
Roberto, se posso darti del tu, grazie mille, adesso provo e vedo come va. I risultati comunque usando il comando GRAPH, me li da corretti come mi servono.
Grazie mille.
Scusa Roberto un aiuto sul codice sotto, non riesco a capire come mai mi apre
Grazie mille.
IF BarraNormale = 1 THEN
IF BarraVerde = 1 THEN
SONOQUI = 1
StopEntrataShortSTD = ((high + SpreadEntrata) - close) * pipsize
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrataShortSTD)
IF NOT ONMARKET THEN
PASSO = 1
EntrataPendenteLongSTD = close + max(StopMinimo, StopEntrataShortSTD) + 1
StopPendenteLongSTD = (EntrataPendenteLongSTD - (low - SpreadPendente - MarginePendente)) * pipsize
BUY LotNumber CONTRACT AT EntrataPendenteLongSTD STOP
SET STOP pLOSS StopPendenteLongSTD
ENDIF
ELSIF BarraVerde = 0 THEN
SONOQUI = 2
StopEntrataLongSTD = (close - (low - SpreadEntrata)) * pipsize
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrataLongSTD)
IF NOT ONMARKET THEN
PASSO = 2
EntrataPendenteShortSTD = close - max (StopMinimo,StopEntratalongSTD) - 1
StopPendenteShortSTD = ((high + SpreadPendente + MarginePendente) - EntrataPendenteShortSTD) * pipsize
SELLSHORT LotNumber CONTRACT AT EntrataPendenteShortSTD STOP
SET STOP pLOSS StopPendenteShortSTD
ENDIF
ENDIF
ELSE
IF PinBarLong = 1 THEN
SONOQUI = 3
StopEntrataShortPIN = ((high + SpreadEntrata) - close) * pipsize
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrataShortPIN)
IF NOT ONMARKET THEN
PASSO = 3
EntrataPendenteLongPIN = close + max(Stopminimo, StopEntrataShortPIN) + 1
StopPendenteLongPIN = (EntrataPendenteLongPIN - (low - SpreadPendente - MarginePendente)) * pipsize
BUY LotNumber CONTRACT AT EntrataPendenteLongPIN STOP
SET STOP pLOSS StopPendenteLongPIN
ENDIF
ELSIF PinBarLong = 0 THEN
SONOQUI = 4
StopEntrataLongPIN = (close - (low - SpreadEntrata)) * pipsize
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrataLongPIN)
IF NOT ONMARKET THEN
PASSO = 4
EntrataPendenteShortPIN = close - max(StopMinimo, StopEntrataLongPIN) - 1
StopPendenteShortPIN = ((high + SpreadPendente + MarginePendente) - EntrataPendenteShortPIN) * pipsize
SELLSHORT LotNUmber CONTRACT AT EntrataPendenteShortPIN STOP
SET STOP pLOSS StopPendenteShortPIN
ENDIF
ENDIF
ENDIF
Scusami Roberto, sotto mi sono incasinato cl modificare il messaggio. Il problema non sta tanto nei valori che con GRAPH mi tornano corretti, ma sta nel fatto che adesso mi entra a mercato con lo stop del pendente (StopPendente), mentre nell’ordine pendente non mi indica lo stop. Non rieco a capire dove sta l’errore, sotto ti riporto tutto il codice.
IF BarraNormale = 1 THEN
IF BarraVerde = 1 THEN
SONOQUI = 1
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
//IF NOT ONMARKET THEN
PASSO = 1
EntrataPendente = close + max(StopMinimo, StopEntrata) + 1
StopPendente = (EntrataPendente - (low - SpreadPendente - MarginePendente))
BUY LotNumber CONTRACT AT EntrataPendente STOP
SET STOP pLOSS StopPendente * pipsize
//ENDIF
ELSIF BarraVerde = 0 THEN
SONOQUI = 2
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
//IF NOT ONMARKET THEN
PASSO = 2
EntrataPendente = close - max (StopMinimo,StopEntrata) - 1
StopPendente = ((high + SpreadPendente + MarginePendente) - EntrataPendente)
SELLSHORT LotNumber CONTRACT AT EntrataPendente STOP
SET STOP pLOSS StopPendente * pipsize
//ENDIF
ENDIF
ELSE
IF PinBarLong = 1 THEN
SONOQUI = 3
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
//IF NOT ONMARKET THEN
PASSO = 3
EntrataPendente = close + max(Stopminimo, StopEntrata) + 1
StopPendente = (EntrataPendente - (low - SpreadPendente - MarginePendente))
BUY LotNumber CONTRACT AT EntrataPendente STOP
SET STOP pLOSS StopPendente * pipsize
//ENDIF
ELSIF PinBarLong = 0 THEN
SONOQUI = 4
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
//IF NOT ONMARKET THEN
PASSO = 4
EntrataPendente = close - max(StopMinimo, StopEntrata) - 1
StopPendente = ((high + SpreadPendente + MarginePendente) - EntrataPendente)
SELLSHORT LotNUmber CONTRACT AT EntrataPendente STOP
SET STOP pLOSS StopPendente * pipsize
//ENDIF
ENDIF
ENDIF
Grazie mille.
Perché non può esserci più di uno SL unico per tutta la strategia, Long o Short, a mercato o pendente che sia.
Ogni volta che trova SET STOP pLOSS (o simili) questo SOSTITUISCE i precedenti ordini di STOP, anche per le posizioni già aperte.
Nel tuo caso, alla riga 5 entrerà con lo SL della riga 12, perché viene dopo quello della riga 6 (e così per gli altri).
Grazie mille Roberto. Quindi se ho capito bene, non posso entrare a mercato con uno SL ed inserire un ordine che entra in una posizione con uno SL diverso dal primo, giusto?
Nemmeno se attivo le righe di IF che ho commentato?
Grazie ancora Roberto.
Puoi farlo, ma sappi che ProOrder prende per buono sempre l’ultimo ordine di STOP eseguito, che sia all’interno di IF…ENDIF o meno.
Non è un errore che viene segnalato, puoi metterne quanti ne vuoi di SET STOP LOSS, anche perché a volte capita di variarli secondo la propria strategia, quindi DEVE consentirli, solo che prende per buono sempre l’ultimo che viene eseguito.
Se uno STOP LOSS successivo è all’interno di IF…ENDIF con certe condizioni che non si verificano, allora non lo esegue, ovviamente, ma al momento in cui le condizioni si verificano e quella riga viene eseguita, ogni precedente STOP LOSS è sostituito dal nuovo.
Quindi se sono già a mercato, mi modifica anche lo stop di quella posizione?
Grazie mille e porta pazienza per le mie domande.
Buongiorno Roberto.
Sotto il codice che ho scritto per entrare a mercato. Lanciato ieri sera mi ha saltato le barre dell 4 delle 6 e delle 8, ma non riesco a capire il perchè, se cortesemente mi dai una dritta.
Grazie mille.
Mauro Rossetto.
//Definisco il tipo barra
IF (close > (high + low) / 2) AND NOT AltaVolatilita THEN
TipoBarra = 1
ELSIF (close < (high + low) /2) AND NOT AltaVolatilita THEN
TipoBarra = 2
ELSIF (close > (high + low) / 2) AND AltaVolatilita THEN
TipoBarra = 3
ELSIF (close > (high + low) / 2) AND AltaVolatilita AND (high - close) > StopMassimo THEN
TipoBarra = 4
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) < StopMassimo THEN
TipoBArra = 5
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) > StopMassimo THEN
TipoBarra = 6
ENDIF
//ENDIF
// Chiude tutte le posizioni alla chiusura della barra
IF (BarIndex - TradeIndex) >= 1 THEN
SELL AT MARKET //exit LONG trades, if any
EXITSHORT AT MARKET //exit SHORT trades, if any
ENDIF
//Credo dica il profitto è dato dal capitale + il ricavato dal programma
MyProfit = Capitale + StrategyProfit
//Credo centri qualche cosa con l'aumento della size al cambio del mese
IF Month <> Month[1] THEN
LotNumber = max(MinLots, (MyProfit / Capitale))
ENDIF
IF TipoBarra = 1 AND TradingDay THEN
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 2 AND TradingDay THEN
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 3 AND TradingDay THEN
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
IF StopEntrata >= 210 THEN
StopEntrata = StopMassimo + 10
ENDIF
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 5 AND TradingDay THEN
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ENDIF
Devo eseguirlo, dimmi su che strumento e su quale timeframe lo fai girare.
È completo il codice?
Japan 225 Cash($1) barre orarie.
Sotto il codice completo.
Grazie mille.
DEFPARAM CumulateOrders = False
DEFPARAM PreLoadBars = 10000
////////////////////////////////////////////////////////////////////////////////////////
ONCE Capitale = 4690
ONCE LotNumber = 1
ONCE MinLots = 1
ONCE SpreadEntrata = 10 * pipsize
//ONCE SpreadPendente = 10 * pipsize
//ONCE MargineEntrata = 1 * pipsize
//ONCE MarginePendente = 1 * pipsize
ONCE StopMinimo = 40 * pipsize
ONCE StopMassimo = 200 * pipsize
ONCE LimiteMaxBarra = 450 * pipsize
TradingDay = OpenDayOfWeek >= 0 AND OpenDayOfWeek <= 5 //trade only Mon. to Fri.
AltaVolatilita = range > LimiteMaxBarra
//Definisco il tipo barra
IF (close > (high + low) / 2) AND NOT AltaVolatilita THEN
TipoBarra = 1
ELSIF (close < (high + low) /2) AND NOT AltaVolatilita THEN
TipoBarra = 2
ELSIF (close > (high + low) / 2) AND AltaVolatilita THEN
TipoBarra = 3
ELSIF (close > (high + low) / 2) AND AltaVolatilita AND (high - close) > StopMassimo THEN
TipoBarra = 4
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) < StopMassimo THEN
TipoBArra = 5
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) > StopMassimo THEN
TipoBarra = 6
ENDIF
//ENDIF
// Chiude tutte le posizioni alla chiusura della barra
IF (BarIndex - TradeIndex) >= 1 THEN
SELL AT MARKET //exit LONG trades, if any
EXITSHORT AT MARKET //exit SHORT trades, if any
ENDIF
//Credo dica il profitto è dato dal capitale + il ricavato dal programma
MyProfit = Capitale + StrategyProfit
//Credo centri qualche cosa con l'aumento della size al cambio del mese
IF Month <> Month[1] THEN
LotNumber = max(MinLots, (MyProfit / Capitale))
ENDIF
IF TipoBarra = 1 AND TradingDay THEN
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 2 AND TradingDay THEN
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 3 AND TradingDay THEN
StopEntrata = ((high + SpreadEntrata) - close)
SELLSHORT LotNumber CONTRACT AT MARKET
IF StopEntrata >= 210 THEN
StopEntrata = StopMassimo + 10
ENDIF
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ELSIF TipoBarra = 5 AND TradingDay THEN
StopEntrata = (close - (low - SpreadEntrata))
BUY LotNumber CONTRACT AT MARKET
SET STOP pLOSS max (StopMinimo,StopEntrata) * pipsize
ENDIF
GRAPH max (StopMinimo,StopEntrata) * pipsize
GRAPH (high - close)
GRAPH TipoBarra
GRAPH (close - low)
A me le ha aperte regolarmente, alle 4, alle 6 e alle 8, ecc…
Prova ad inserire un capitale maggiore (metti 1 milione), non vorrei fosse insufficiente.
Roberto, ma nel caso di capitale insufficiente, non dovrebbe dirmi con il triangolo giallo ordine rifiutato dalla piattaforma per mancanza di fondi?
Se vado su IG, vedo che la posizione si apre e si chiude subito dopo, come se appena aperta qualche cosa all’interno del programma la facesse chiudere subito, o che non prenda lo stop loss e si prende quello minimo da piattaforma.Roberto un altra domanda, il programma quando viene eseguito in una candela oraria? Ed in una candela giornaliera?
Io all’inizio chiudo tutte le posizioni e poi ne apro di nuovo in base alla barra appena chiusa. Forse è qui che il programma sbaglia.
Grazie mille ancora del tuo aiuto.
Buongiorno Roberto.
Ieri ho risolto una cosa adesso me ne manca un altra, sto facendo confusione con i pendenti di tipo STOP e LIMIT. Ti copio il codice, puoi dare una occhiata se ti balza all’occhio qualche errore?
Grazie mille.
DEFPARAM CumulateOrders = False
DEFPARAM PreLoadBars = 10000
////////////////////////////////////////////////////////////////////////////////////////
ONCE Capitale = 4690
ONCE LotNumber = 1
ONCE MinLots = 1
ONCE SpreadEntrata = 10 * pipsize
ONCE SpreadPendente = 10 * pipsize
//ONCE MargineEntrata = 1 * pipsize
ONCE MarginePendente = 1 * pipsize
ONCE StopMinimo = 40 * pipsize
ONCE StopMassimo = 200 * pipsize
ONCE LimiteMaxBarra = 450 * pipsize
TradingDay = OpenDayOfWeek >= 0 AND OpenDayOfWeek <= 5 //trade only Mon. to Fri.
//Testo se la barra è di alta volatilità
AltaVolatilita = range > LimiteMaxBarra
//Definisco il tipo barra
IF (close > (high + low) / 2) AND NOT AltaVolatilita THEN
TipoBarra = 1
ELSIF (close < (high + low) /2) AND NOT AltaVolatilita THEN
TipoBarra = 2
ELSIF (close > (high + low) / 2) AND AltaVolatilita THEN
TipoBarra = 3
ELSIF (close > (high + low) / 2) AND AltaVolatilita AND (high - close) > StopMassimo THEN
TipoBarra = 4
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) < StopMassimo THEN
TipoBArra = 5
ELSIF (close < (high + low) /2) AND AltaVolatilita AND (close - low) > StopMassimo THEN
TipoBarra = 6
ENDIF
// Chiude tutte le posizioni alla chiusura della barra
IF (BarIndex - TradeIndex) >=0 THEN
//IF ONMARKET THEN
SELL AT MARKET //exit LONG trades, if any
EXITSHORT AT MARKET //exit SHORT trades, if any
ENDIF
//Credo dica il profitto è dato dal capitale + il ricavato dal programma
MyProfit = Capitale + StrategyProfit
//Credo centri qualche cosa con l'aumento della size al cambio del mese
IF Month <> Month[1] THEN
LotNumber = max(MinLots, (MyProfit / Capitale))
ENDIF
IF TipoBarra = 1 AND TradingDay THEN
StopEntrata = ((high + SpreadEntrata) - close)
EntrataPendente = close + max(StopMinimo, StopEntrata) + 1
StopPendente = (EntrataPendente - (low - SpreadPendente - MarginePendente))
//STOP CORRETTO
BUY LotNumber CONTRACT AT EntrataPendente * pipsize STOP
SET STOP pTRAILING StopPendente * pipsize
ELSIF TipoBarra = 2 AND TradingDay THEN
StopEntrata = (close - (low - SpreadEntrata))
EntrataPendente = close - max (StopMinimo,StopEntrata) - 1
StopPendente = ((high + SpreadPendente + MarginePendente) - EntrataPendente)
//STOP CORRETTO
SELLSHORT LotNumber CONTRACT AT EntrataPendente * pipsize STOP
SET STOP pTRAILING StopPendente * pipsize
ELSIF Tipobarra = 4 AND TradingDay THEN
IF OpenDayOfWeek = 1 THEN
EntrataPendente = high[2] + SpreadEntrata - StopMAssimo
ELSE
EntrataPendente = high + SpreadEntrata - StopMAssimo
ENDIF
//SELLSHORT LotNumber CONTRACT AT EntrataPendente * pipsize STOP
SELLSHORT LotNumber CONTRACT AT EntrataPendente * pipsize LIMIT
SET STOP pTRAILING StopMassimo
ELSIF TipoBarra = 6 AND TradingDay THEN
EntrataPendente = low - SpreadEntrata + StopMAssimo
SELLSHORT LotNumber CONTRACT AT EntrataPendente * pipsize STOP
SET STOP pTRAILING StopMassimo
ENDIF
GRAPH max (StopMinimo,StopEntrata) * pipsize
GRAPH EntrataPendente
GRAPH StopPendente * pipsize
GRAPH Tipobarra
Non mi inserisce l'ordine pendente
This topic contains 79 replies,
has 2 voices, and was last updated by
robertogozzi
5 years, 4 months ago.
| Forum: | ProOrder: Trading Automatico & Backtesting |
| Language: | Italian |
| Started: | 04/01/2020 |
| Status: | Active |
| Attachments: | 6 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.