Defparam cumulateorders = False
possize = 1
StochUpperLimit = 90
StochLowerLimit = 20
StochConsolidationPeriod = 2
StochPeriods = 18
StochK = 2
StochD = 6
StochSignal = Stochastic[StochPeriods,StochK](close)
StochMain = average[StochD](StochSignal)
RSI2 = RSI[2](close)
RSIUpperLimit = 95
RSILowerLimit = 5
RSILimit = 4
once Stoch = 0
once StochCounter = 0
once RSICounter = 0
once RSICounterAdj = 0
once LastRSI = 50
If Stoch = 0 and lowest[StochConsolidationPeriod](StochSignal) < StochLowerLimit and StochSignal[1] <= StochMain[1] and StochSignal > StochMain Then
Stoch = -1
StochCounter = 0
ElsIf Stoch = 0 and highest[StochConsolidationPeriod](StochSignal) > StochUpperLimit and StochSignal[1] >= StochMain[1] and StochSignal < StochMain Then
Stoch = 1
StochCounter = 0
EndIf
StochCounter = StochCounter + 1//questo si aggiorna sempre essendo fuori da qualsisasi if lui si aggiorna sempre
If onmarket = 0 and Stoch= -1 and StochCounter > 1 and StochSignal[1] <= StochMain[1] and StochSignal > StochMain Then
Buy possize contract at market
StochCounter = 0
RSICounter = 0
RSICounterAdj = 0
LastRSI = 50
ElsIf onmarket = 0 and Stoch = 1 and StochCounter > 1 and StochSignal[1] >= StochMain[1] and StochSignal < StochMain Then
Sellshort possize contract at market
StochCounter = 0
RSICounter = 0
RSICounterAdj = 0
LastRSI = 50
EndIf
If longonmarket and RSI2[1] >= RSIUpperLimit and RSI2 < RSIUpperLimit Then
RSICounter = RSICounter + 1
If highest[8](RSI2) < LastRSI Then
RSICounterAdj = RSICounterAdj + 1
EndIf
LastRSI = highest[8](RSI2)
ElsIf shortonmarket and RSI2[1] <= RSILowerLimit and RSI2 > RSILowerLimit Then
RSICounter = RSICounter + 1
If lowest[8](RSI2) > LastRSI Then
RSICounterAdj = RSICounterAdj + 1
EndIf
LastRSI = lowest[8](RSI2)
EndIf
If longonmarket and RSI2[1] < RSIUpperLimit and RSI2 >= RSIUpperLimit and RSICounter >= RSILimit-RSICounterAdj Then
sell at market
Stoch = 0
ElsIf shortonmarket and RSI2[1] > RSILowerLimit and RSI2 <= RSILowerLimit and RSICounter >= RSILimit-RSICounterAdj Then
exitshort at market
Stoch = 0
EndIf
Questo va solo Long (ho dovuto fare un bel pò di prove per capire cosa togliere e modificare), verifica che siano operazioni aperte correttamente rispetto al codice che hai postato:
Defparam cumulateorders = False
possize = 1
StochUpperLimit = 90
StochLowerLimit = 20
StochConsolidationPeriod = 2
StochPeriods = 18
StochK = 2
StochD = 6
StochSignal = Stochastic[StochPeriods,StochK](close)
StochMain = average[StochD](StochSignal)
RSI2 = RSI[2](close)
RSIUpperLimit = 95
RSILowerLimit = 5
RSILimit = 4
once Stoch = 0
once StochCounter = 0
once RSICounter = 0
once RSICounterAdj = 0
once LastRSI = 50
If Stoch = 0 and lowest[StochConsolidationPeriod](StochSignal) < StochLowerLimit and StochSignal[1] <= StochMain[1] and StochSignal > StochMain Then
Stoch = -1
StochCounter = 0
ElsIf Stoch = 0 and highest[StochConsolidationPeriod](StochSignal) > StochUpperLimit and StochSignal[1] >= StochMain[1] and StochSignal < StochMain Then
Stoch = 1
StochCounter = 0
EndIf
StochCounter = StochCounter + 1//questo si aggiorna sempre essendo fuori da qualsisasi if lui si aggiorna sempre
If onmarket = 0 and Stoch= -1 and StochCounter > 1 and StochSignal[1] <= StochMain[1] and StochSignal > StochMain Then
Buy possize contract at market
StochCounter = 0
RSICounter = 0
RSICounterAdj = 0
LastRSI = 50
ElsIf onmarket = 0 and Stoch = 1 and StochCounter > 1 and StochSignal[1] >= StochMain[1] and StochSignal < StochMain Then
//Sellshort possize contract at market
//StochCounter = 0
//RSICounter = 0
//RSICounterAdj = 0
//LastRSI = 50
EndIf
If longonmarket and RSI2[1] >= RSIUpperLimit and RSI2 < RSIUpperLimit Then
RSICounter = RSICounter + 1
If highest[8](RSI2) < LastRSI Then
RSICounterAdj = RSICounterAdj + 1
EndIf
LastRSI = highest[8](RSI2)
ElsIf not onmarket and RSI2[1] <= RSILowerLimit and RSI2 > RSILowerLimit Then
RSICounter = RSICounter + 1
If lowest[8](RSI2) > LastRSI Then
RSICounterAdj = RSICounterAdj + 1
EndIf
LastRSI = lowest[8](RSI2)
EndIf
If longonmarket and RSI2[1] < RSIUpperLimit and RSI2 >= RSIUpperLimit and RSICounter >= RSILimit-RSICounterAdj Then
sell at market
Stoch = 0
ElsIf not onmarket and RSI2[1] > RSILowerLimit and RSI2 <= RSILowerLimit and RSICounter >= RSILimit-RSICounterAdj Then
//exitshort at market
Stoch = 0
EndIf
//Defparam cumulateorders = False
possize = 1
StochUpperLimit = 90
StochLowerLimit = 20
StochConsolidationPeriod = 2
StochPeriods = 18
StochK = 2
StochD = 6
StochSignal = Stochastic[StochPeriods,StochK](close)
StochMain = average[StochD](StochSignal)
if not LONGONMARKET THEN
Stoch =0
endif
If Stoch = 0 and lowest[StochConsolidationPeriod](StochSignal) < StochLowerLimit and StochSignal[1] <= StochMain[1] and StochSignal > StochMain Then
Stoch = -1
EndIf
a=0
// Solo condizione per acquisto
If Stoch= -1 and StochSignal[1] <= StochMain[1] and StochSignal > StochMain and lowest[StochConsolidationPeriod](StochSignal) < StochLowerLimit Then
a=1
Buy possize contract at market
EndIf
SET TARGET %PROFIT 10
SET STOP %LOSS 5
come posso resettare stoch a 0 ? ho provato come da codice a inserire la condizione "if not longonmarket " ma il sistema entra ed esce subito
Metti queste 3 righe così:
//if not LONGONMARKET THEN
Stoch =0
//endif
ovviamente le due righe commentate le puoi togliere, se preferisci.
grazie Roberto ma non risolve perche mi rimette su ogni barra stoch=0 e quindi non cambia niente , stoch dovrebbe restare impostato a -1 fin quando resto a mercato e poi tornare a 0 per poter di nuovo il set up di riga 21
c e anche un altra cosa che non capisco ,perche mi entra a quel livello li evidenziato mentre l entrata dovrebbe essere a mercato quindi all apertura della barra successiva
Nel tuo codice https://www.prorealcode.com/topic/solo-direzione-long/#post-239524 STOCH resta a -1 quando è a mercato e va a 0 quando non è a mercato.
Io ho solo cambiato queste due righe:
SET TARGET %PROFIT 1
SET STOP %LOSS 0.5
perché altrimenti faceva operazioni molto lunghe e restava SEMPRE a mercato.
Aggiungi questa riga per vedere il prezzo:
graphonprice PositionPrice
Ho notato che questo, come altri sistemi che dovrebbero entrare “a mercato” in realtà entrano ad un livello superiore della apertura della barra, cosa che pero succede solo con azioni mentre con indici usando lo stesso sistema non avviene, il dubbio è che prorealtime abbia inserito i livelli di bid e ask ed usa quelli come entrata a mercato e non più l apertura della barra e quindi dove lo spread tra bid e ask è più marcato (appunto i titoli azionari rispetto ad esempio agli indici) l entrata a mercato avvenga ad un livello diverso dalla apertura della barra.
Non so dirti niente in merito. Prova a chiederlo direttamente a ProRealTime.
dovrebbe entrare “nel mercato” in realtà entrare a un livello più alto rispetto all’apertura della barra
Ciò che vediamo come prezzo di apertura è il prezzo medio tra bid e ask.
“Acquista a lungo sul mercato” verrebbe eseguito a un prezzo (leggermente) più alto rispetto al prezzo di apertura che vediamo su una candela.
Nei miei grafici ho sempre l’indicatore “Banda bid-ask”: questo dimostra ciò che sto dicendo sopra.