Salve, ho visto questo post https://www.prorealcode.com/prorealtime-trading-strategies/kama-sma-trading-system-dax-mtf/ dove si parlava dell’indicatore KAMA associato alla media semplice come segnale di buy/sell su doppio timeframe 1min 1h. Io ho provato ad eliminare il doppio timeframe lasciando solo l’orario che è anche quello dove arrivano i segnali di entrata il problema è che con l’impostazione KAMA 2, 2, 30 l’indicatore dopo poche candele non funziona più!
Tra l’altro io avevo già questo indicatore ed effettivamente utilizzando il settaggio 2, 2, 30 anche l’indicatore fuori dal prorder smette di funzionare dopo x candele! La cosa strana è che sul sistema doppio timeframe “pare” invece funzioni bene e non si blocca come è possibile!?
Inserisco qui il pezzo di codice kama che su unico timeframe non funziona e non funziona neanche come indicatore impostando il settaggio 2, 2, 30
Period = 2 //2 (standard 10)
FastPeriod = 2 //standard
SlowPeriod = 30 //standard
//
Fastest = 2 / (FastPeriod + 1)
Slowest = 2 / (SlowPeriod + 1)
if barindex >= (Period + 1) then
Num = abs(close-close[Period])
Den = summation[Period](abs(close-close[1]))
ER = Num / Den
Alpha = SQUARE(ER *(Fastest - Slowest )+ Slowest)
Kama = (Alpha * Close) + ((1 -Alpha)* Kama[1])
else
Kama = close
endif
ovviamente manca il return per usarlo come indicatore
Potreste illuminarmi su questa cosa?
Grazie
Si, in effetti basta aumentare PERIOD e funziona correttamente.
Non sono riuscito a prima vista a capire dove sia il problema, ci darò un’occhiata più in dettaglio domani.
Dovresti pubblicare l'intero codice che stai utilizzando, poiché un errore potrebbe essere nel modo in cui hai adattato il codice a cui ti riferisci.
Il codice dove stavo iniziando a lavorare (quindi è pieno di commenti inutilil eheh) è questo e lo stavo provando appunto sul dax 1h singolo time frame… mentre sul link sopra a doppio timeframe come per magia l’indicatore funziona anche con 2, 2, 30!!!
// Definizione dei parametri del codice
// Impedisce al sistema di creare nuovi ordini per entrare a mercato o aumentare la taglia della posizione prima dell'orario specificato
// Impedisce al sistema di piazzare nuovi ordini per entrare a mercato o aumentare la taglia della posizione dopo l'orario indicato
// Impedisce al sistema di tradare in giorni specifici della settimana
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
DEFPARAM PRELOADBARS = 400
// gestione posizione *********************************************************
once ttrail = 30 // inizio trailing step dopo 30 di guadagno
once ttstep = 25 // step del trailing stop
once parstop = 70 // ******************************* da parametrizzare con ATR
once tbarspd = 3 //barra entro la quale realizzare un guadagno decente
once tfprofit = 80 // guadagno da realizzare entro TBARSPD barre
once x = 1 //numero contratti da aprire
once pbreakeven = 30
// gestione indicatori ********************************************************
//****************************************************************************
// ********************* SETUP INDICATORI *************************************
// ****************************************************************************
//------------------------------------------------------------------------------------
// Kama & Sma Strategy
//
//https://www.forexstrategiesresources.com/trend-following-forex-strategies/111-kama-strategy/
//
Period = 3 //2 due non funziona dopo un po //2 (standard 10)
FastPeriod = 2 //2 //standard
SlowPeriod = 25 //30 //standard
//
Fastest = 2 / (FastPeriod + 1)
Slowest = 2 / (SlowPeriod + 1)
if barindex >= (Period + 1) then
Num = abs(close-close[Period])
Den = summation[Period](abs(close-close[1]))
ER = Num / Den
Alpha = SQUARE(ER *(Fastest - Slowest )+ Slowest)
Kama = (Alpha * Close) + ((1 -Alpha)* Kama[1])
else
Kama = close
endif
//------------------------------------------------------------------------------------
Sma = average[30](close) //22
//------------------------------------------------------------------------------------
IF NOT ONMARKET THEN
newSL = 0
cbe = 0 //check breakeven
// ********************* SETUP GESTIONE POSIZIONI *****************************
// ****************************************************************************
// controlli volatilità ***************************************************************************
//controlli direzionalità *************************************************************************
// ingressi BUY CHECK ***********************************************************************************************
//entrata LONG ****************************************************************
if Kama CROSSES OVER Sma then
pb1 = 1
else
pb1 = 0
endif
//entrata short ***************************************************************
if Kama CROSSES UNDER Sma then
ps1 = 1
else
ps1 = 0
endif
//CONFERMA SEGNALI *********************************
if (pb1) then
gbuy = 1
else
gbuy = 0
endif
if (ps1) then
gsell = 1
else
gsell = 0
endif
//GESTIONE PREZZO DI ENTRATA A MERCATO ***************************************************
// POSIZIONAMENTO ORDINI A MERCATO
// ****************************************************************************************
ctime = 1
//catr = 1
//buy ***********************************************************
IF ctime and gbuy AND NOT ONMARKET THEN
BUY x CONTRACT AT market
SET STOP pLOSS parstop
ENDIF
////sell ***********************************************************
if ctime and gsell AND NOT ONMARKET THEN
SELLSHORT x CONTRACT AT MARKET
SET STOP pLOSS parstop
ENDIF
ELSIF ONMARKET THEN
// GESTIONE ORDINE
// **********************************************************************************************
//azzera indicatori di setup entrata ****************************
ctime = 0
gbuy = 0
gsell = 0
// MONEY MANAGMENT
// ***********************************************************************************************
trailingstart = ttrail //SUPERATA LA SOGLIA MUOVE LO STOP LOSS IN STOP PROFIT
trailingstep = ttstep // BLOCCO CHE MUOVE LO STEP PROFIT
newstop = parstop
numbar = BarIndex - TRADEINDEX
slnbar = 3
slperc = 0.9
if (numbar > slnbar) then //inizia a ridurre lo stop
newstop = parstop - (slperc * (numbar - slnbar))
if newstop < 10 then
newstop = 10
endif
endif
SET STOP pLOSS newstop //parstop //newstop // stoploss
// TEMPO
//*************************************************************************************************
//ferma tutto il venerdì alle 21:30 ********************************
//if ((OpenDayOfWeek = 5) AND (time >= 180000)) THEN
//sell at market
//exitshort at market
//endif
// POSIZIONI BUY APERTE
// *************************************************************************************************
IF LONGONMARKET THEN
// BREAKEVEN ****************************************************
if (((close - tradeprice) > pbreakeven) and (close > tradeprice)) OR (cbe) then
cbe = 1
SELL AT Tradeprice + 3 STOP
endif
// GESTIONE TRAILING STOP
// ****************************************************************
// Gestione trailing stop ***********************************************************************
IF ((newsl = 0) AND ((close - tradeprice) >= (trailingstart * pipsize))) THEN
newsl = tradeprice + (trailingstep * pipsize)
ENDIF
//next moves
IF ((newsl > 0) AND ((close - newsl) >= (trailingstep * pipsize))) THEN
newsl = newsl + (trailingstep * pipsize)
ENDIF
// guadagno veloce Poche candele take money and run
// ************************************************************************************
if LONGONMARKET and ((BarIndex - TRADEINDEX) <= tbarspd) then
SET TARGET pPROFIT tfprofit
else
SET TARGET pPROFIT 0
//SET TARGET pPROFIT iatr * multipvol * multiproff //fisso o take profit su atr?????
ENDIF
ENDIF
//POSIZIONI SHORT APERTE
// *******************************************************************************************************
IF SHORTONMARKET THEN
// breakeven
if (((tradeprice - close) > pbreakeven) and (tradeprice > close)) OR (cbe) then
cbe = 1
EXITSHORT AT TradePrice -3 STOP
endif
// GESTIONE TRAILING STOP
// **********************************************************************************
IF ((newSL = 0) AND ((tradeprice - close) >= (trailingstart * pipsize))) THEN
newSL = tradeprice - (trailingstep * pipsize)
ENDIF
IF ((newSL > 0) AND ((newSL - close) >= (trailingstep * pipsize))) THEN
newSL = newSL - (trailingstep * pipsize)
ENDIF
// guadagno veloce Poche candele take money and run ********************************************************
if SHORTONMARKET and ((BarIndex - TradeIndex) <= tbarspd) then
SET TARGET pPROFIT tfprofit
else
SET TARGET pPROFIT 0
//SET TARGET pPROFIT iatr * multipvol * multiproff //fisso o take profit su atr?????
endif
ENDIF
//TAKE PROFIT TRAILING EXIT POSITIONS
// **********************************************************************************
IF (newSL > 0) THEN
IF (LONGONMARKET) AND (newSL > close) AND (close > tradeprice) THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND (newSL < close) AND (close < tradeprice) THEN
EXITSHORT AT MARKET
ENDIF
ENDIF
endif
// DEBUG
//***********************************************************************************
//graph newsl
Comunque sono sicuro che il problema è proprio nell’indicatore kama (quello che ho postato sopra) perchè come scrivevo prima, usandolo come semplice indicatore dopo poche candele l’indicatore smette di funzionare cioè rimane fermo su un valore… (accade su dax e altri)! Se può essere di aiuto sul forex eur/usd funziona anche con 2, 2, 30 anche sul coffee cash funziona mentre su quasi tutti gli altri dax, sp500, gold, etc non funziona!
Inoltre notavo che non mi fa ottimizzare più le variabili il proorder visualizzando tutti i risultati ottimizzati a zero ad esempio ottimizzando Period e/o Sme PRT non mi calcola la proiezione del sistema ma lascia tutto a 0.
Sembra state aggiornando versioni PRT oppure è un caso o un errore mio?
Ci sono dei problemi, su 1 minuto tra il 7 ed il 12 Marzo 2019, su H1 tra Maggio 2006 e Giugno/Luglio 2019.
Se fai il backtest con 200K barre vedrai che, su 1-minuto di default, si ferma il 7 Marzo 2019 e devi farlo ripartire dal 13 Marzo 2019.
Se usi H1 con 200K barre inizia ad Aprile 2006 e si ferma dopo un mese circa ed occorre farlo ripartire dal 15 Luglio 2019.
Ho fatto questa segnalazione https://www.prorealcode.com/topic/backtest-fails-on-march-7th-dax-1-minute-tf/#post-107484.
Grazie per la risoluzione