ProRealCode - Trading & Coding with ProRealTime™
kama1h et kama15min" >/// Définition des paramètres du code
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
Timeframe (1 hour)
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(close-close[Period1h])
Den1h = summation[Period1h](abs(close-close[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h - Slowest1h )+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
Timeframe (15 minutes)
/////////////////////////////////////////////////////////////////// parameters KAMA
Period4h = 150
FastPeriod4h = 2
SlowPeriod4h = 50
Fastest4h = 2 / (FastPeriod4h + 1)
Slowest4h = 2 / (SlowPeriod4h + 1)
if barindex < Period4h+1 then
Kama4h=close
else
Num4h = abs(close-close[Period4h])
Den4h = summation[Period4h](abs(close-close[1]))
ER4h = Num4h / Den4h
Alpha4h = SQUARE(ER4h *(Fastest4h - Slowest4h )+ Slowest4h)
KAMA4h = (Alpha4h * Close) + ((1 -Alpha4h)* Kama4h[1])
endif
//-------------------------------------//
//PRC_RSI Cyclic Smoothed
//version = 0
//19.11.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-------------------------------------//
//Inputs
//-------------------------------------//
src4h=close
domcycle4h=20
cyclelen4h=domcycle4h/2
vibration4h=10
leveling4h=10
cyclicmemory4h=domcycle4h*2
once crsi4h=0
//-------------------------------------//
// CRSI calculation
//-------------------------------------//
torque4h=2/(vibration4h+1)
phasinglag4h=floor((vibration4h-1)/2)
length4h = cyclelen4h
alpha4h = 1/length4h
srcUp4h = max(src4h-src4h[1],0)
if barindex = length4h then
up4h = average[length4h](srcUp4h)
else
up4h = alpha4h*srcUp4h + (1-alpha4h)*up4h[1]
endif
srcDw4h = -min(src4h-src4h[1],0)
if barindex = length4h then
dw4h = average[length4h](srcdw4h)
Bonjour,
je rencontre un problème dans ce code. Je souhaiterai entrer long lorsque les cours sont au-dessus des Kama 150 sur les unités de temps 1h et 15 min. Or en faisant un back test, une entrée longue a été faite le 25 novembre 2024 (et ce n’est pas la seule date qui pose problème). Or d’après mon graphique en 1 heure, les cours étaient au dessous de la kama150 à cette période.
Pourriez-vous m’indiquer ce qui cloche dans mon code ?
merci.
le code en entier
Timeframe (1 hour)
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(close-close[Period1h])
Den1h = summation[Period1h](abs(close-close[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h – Slowest1h )+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
Timeframe (15 minutes)
/////////////////////////////////////////////////////////////////// parameters KAMA
Period15min = 150
FastPeriod15min = 2
SlowPeriod15min = 50
Fastest15min = 2 / (FastPeriod15min + 1)
Slowest15min = 2 / (SlowPeriod15min + 1)
if barindex < Period15min+1 then
Kama15min=close
else
Num15min = abs(close-close[Period15min])
Den15min = summation[Period15min](abs(close-close[1]))
ER15min = Num15min / Den15min
Alpha15min = SQUARE(ER15min *(Fastest15min – Slowest15min )+ Slowest15min)
KAMA15min = (Alpha15min * Close) + ((1 -Alpha15min)* Kama15min[1])
endif
//————————————-//
//PRC_RSI Cyclic Smoothed
//version = 0
//19.11.2024
//Iván González @ http://www.prorealcode.com
//Sharing ProRealTime knowledge
//————————————-//
//Inputs
//————————————-//
src15min=close
domcycle15min=20
cyclelen15min=domcycle15min/2
vibration15min=10
leveling15min=10
cyclicmemory15min=domcycle15min*2
once crsi15min=0
//————————————-//
// CRSI calculation
//————————————-//
torque15min=2/(vibration15min+1)
phasinglag15min=floor((vibration15min-1)/2)
length15min = cyclelen15min
alpha15min = 1/length15min
srcUp15min = max(src15min-src15min[1],0)
if barindex = length15min then
up15min = average[length15min](srcUp15min)
else
up15min = alpha15min*srcUp15min + (1-alpha15min)*up15min[1]
endif
srcDw15min = -min(src15min-src15min[1],0)
if barindex = length15min then
dw15min = average[length15min](srcdw15min)
else
dw15min = alpha15min*srcdw15min + (1-alpha15min)*dw15min[1]
endif
if dw15min=0 then
myrsi15min=100
elsif up15min=0 then
myrsi15min=0
else
myrsi15min=100-100/(1+up15min/dw15min)
endif
if barindex>cyclicmemory15min then
crsi15min=torque15min*(2*myrsi15min-myrsi15min[phasinglag15min])+(1-torque15min)*crsi15min[1]
endif
//————————————-//
// LowBand and HighBand calculation
//————————————-//
Period15min=cyclicMemory15min
percent15min = leveling15min/100
periodMinusone15min = period15min-1
maxima15min = -999999.0
minima15min = 999999.0
for i15min=0 to periodMinusone15min do
if crsi15min[i15min] > maxima15min then
maxima15min = crsi15min[i15min]
elsif crsi15min[i15min] < minima15min then
minima15min = crsi15min[i15min]
endif
next
stepfactor15min = (maxima15min-minima15min)/100
lowband15min = 0
for steps15min=0 to 100 do
testvalue15min = minima15min+stepfactor15min*steps15min
below15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]<testvalue15min then
below15min=below15min+1
endif
next
if below15min/period15min >= percent15min then
lowband15min = testvalue15min
break
endif
next
highband15min=0
for steps15min=0 to 100 do
testvalue15min=maxima15min-stepfactor15min*steps15min
above15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]>=testvalue15min then
above15min=above15min+1
endif
next
if above15min/Period15min >= percent15min then
highband15min=testvalue15min
break
endif
next
mbb15min = average[50](crsi15min)
CRSISmooth15min = average[7](crsi15min)
LongPos = (kama1h > kama1h[1]) and (close > kama1h) and (kama15min > kama15min[1]) and (close > kama15min) and (CRSI15min crosses over CRSISmooth15min)
if longpos then
buy 1 contract at market
endif
///trailing stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the “stoploss”
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
// points based STOP LOSS and TRAILING STOP
// initial STOP LOSS
SET STOP pLOSS 50
// trailing stop
SET STOP pTRAILING 50
regarder les deux screens
un avec 1K unité et l’autre avec 5 K
Voici mon système (J’ai ajouté UPDATEONCLOSE aux deux timeframe, puis j’ai ajouté le timeframe défaut):
Timeframe (1 hour,updateonclose)
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(close-close[Period1h])
Den1h = summation[Period1h](abs(close-close[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h - Slowest1h )+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
Timeframe (15 minutes,updateonclose)
/////////////////////////////////////////////////////////////////// parameters KAMA
Period15min = 150
FastPeriod15min = 2
SlowPeriod15min = 50
Fastest15min = 2 / (FastPeriod15min + 1)
Slowest15min = 2 / (SlowPeriod15min + 1)
if barindex < Period15min+1 then
Kama15min=close
else
Num15min = abs(close-close[Period15min])
Den15min = summation[Period15min](abs(close-close[1]))
ER15min = Num15min / Den15min
Alpha15min = SQUARE(ER15min *(Fastest15min - Slowest15min )+ Slowest15min)
KAMA15min = (Alpha15min * Close) + ((1 -Alpha15min)* Kama15min[1])
endif
//————————————-//
//PRC_RSI Cyclic Smoothed
//version = 0
//19.11.2024
//Iván González @ http://www.prorealcode.com
//Sharing ProRealTime knowledge
//————————————-//
//Inputs
//————————————-//
src15min=close
domcycle15min=20
cyclelen15min=domcycle15min/2
vibration15min=10
leveling15min=10
cyclicmemory15min=domcycle15min*2
once crsi15min=0
//————————————-//
// CRSI calculation
//————————————-//
torque15min=2/(vibration15min+1)
phasinglag15min=floor((vibration15min-1)/2)
length15min = cyclelen15min
alpha15min = 1/length15min
srcUp15min = max(src15min-src15min[1],0)
if barindex = length15min then
up15min = average[length15min](srcUp15min)
else
up15min = alpha15min*srcUp15min + (1-alpha15min)*up15min[1]
endif
srcDw15min = -min(src15min-src15min[1],0)
if barindex = length15min then
dw15min = average[length15min](srcdw15min)
else
dw15min = alpha15min*srcdw15min + (1-alpha15min)*dw15min[1]
endif
if dw15min=0 then
myrsi15min=100
elsif up15min=0 then
myrsi15min=0
else
myrsi15min=100-100/(1+up15min/dw15min)
endif
if barindex>cyclicmemory15min then
crsi15min=torque15min*(2*myrsi15min-myrsi15min[phasinglag15min])+(1-torque15min)*crsi15min[1]
endif
//————————————-//
// LowBand and HighBand calculation
//————————————-//
Period15min=cyclicMemory15min
percent15min = leveling15min/100
periodMinusone15min = period15min-1
maxima15min = -999999.0
minima15min = 999999.0
for i15min=0 to periodMinusone15min do
if crsi15min[i15min] > maxima15min then
maxima15min = crsi15min[i15min]
elsif crsi15min[i15min] < minima15min then
minima15min = crsi15min[i15min]
endif
next
stepfactor15min = (maxima15min-minima15min)/100
lowband15min = 0
for steps15min=0 to 100 do
testvalue15min = minima15min+stepfactor15min*steps15min
below15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]<testvalue15min then
below15min=below15min+1
endif
next
if below15min/period15min >= percent15min then
lowband15min = testvalue15min
break
endif
next
highband15min=0
for steps15min=0 to 100 do
testvalue15min=maxima15min-stepfactor15min*steps15min
above15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]>=testvalue15min then
above15min=above15min+1
endif
next
if above15min/Period15min >= percent15min then
highband15min=testvalue15min
break
endif
next
mbb15min = average[50](crsi15min)
CRSISmooth15min = average[7](crsi15min)
LongPos = (kama1h > kama1h[1]) and (close > kama1h) and (kama15min > kama15min[1]) and (close > kama15min) and (CRSI15min crosses over CRSISmooth15min)
if longpos then
buy 1 contract at market
endif
Timeframe (default)
///trailing stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
// points based STOP LOSS and TRAILING STOP
// initial STOP LOSS
SET STOP pLOSS 50
// trailing stop
SET STOP pTRAILING 50
Grazie Roberto.
Je vais regarder.
Merci.
Pour revenir aux deux écrans, tu conseilles 5K unités ?
Pour les premières vérifications de code, 5K unités peuvent être suffisants, mais lorsque vous effectuez des backtests définitifs, je vous recommande d’en utiliser beaucoup plus. J’utilise 200K (le maximum).
D’accord. merci pour la rapidité de la réponse. Une dernière demande : l’indicateur corrigé par vous est-il transposable en screener ? Si oui, je ferai une demande dans le forum adéquat.
Pour revenir aux deux écrans, tu conseilles 5K unités ?
oui
merci fifi743
D’accord. merci pour la rapidité de la réponse. Une dernière demande : l’indicateur corrigé par vous est-il transposable en screener ? Si oui, je ferai une demande dans le forum adéquat.
Essaye ça. Je ne sais pas si le résultat sera correct, car les screeners n’ont pas UPDATEONCLOSE :
Timeframe (1 hour)
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 50
Fastest1h = 2 / (FastPeriod1h + 1)
Slowest1h = 2 / (SlowPeriod1h + 1)
if barindex < Period1h+1 then
Kama1h=close
else
Num1h = abs(close-close[Period1h])
Den1h = summation[Period1h](abs(close-close[1]))
ER1h = Num1h / Den1h
Alpha1h = SQUARE(ER1h *(Fastest1h - Slowest1h )+ Slowest1h)
KAMA1h = (Alpha1h * Close) + ((1 -Alpha1h)* Kama1h[1])
endif
Timeframe (15 minutes)
/////////////////////////////////////////////////////////////////// parameters KAMA
Period15min = 150
FastPeriod15min = 2
SlowPeriod15min = 50
Fastest15min = 2 / (FastPeriod15min + 1)
Slowest15min = 2 / (SlowPeriod15min + 1)
if barindex < Period15min+1 then
Kama15min=close
else
Num15min = abs(close-close[Period15min])
Den15min = summation[Period15min](abs(close-close[1]))
ER15min = Num15min / Den15min
Alpha15min = SQUARE(ER15min *(Fastest15min - Slowest15min )+ Slowest15min)
KAMA15min = (Alpha15min * Close) + ((1 -Alpha15min)* Kama15min[1])
endif
//————————————-//
//PRC_RSI Cyclic Smoothed
//version = 0
//19.11.2024
//Iván González @ http://www.prorealcode.com
//Sharing ProRealTime knowledge
//————————————-//
//Inputs
//————————————-//
src15min=close
domcycle15min=20
cyclelen15min=domcycle15min/2
vibration15min=10
leveling15min=10
cyclicmemory15min=domcycle15min*2
once crsi15min=0
//————————————-//
// CRSI calculation
//————————————-//
torque15min=2/(vibration15min+1)
phasinglag15min=floor((vibration15min-1)/2)
length15min = cyclelen15min
alpha15min = 1/length15min
srcUp15min = max(src15min-src15min[1],0)
if barindex = length15min then
up15min = average[length15min](srcUp15min)
else
up15min = alpha15min*srcUp15min + (1-alpha15min)*up15min[1]
endif
srcDw15min = -min(src15min-src15min[1],0)
if barindex = length15min then
dw15min = average[length15min](srcdw15min)
else
dw15min = alpha15min*srcdw15min + (1-alpha15min)*dw15min[1]
endif
if dw15min=0 then
myrsi15min=100
elsif up15min=0 then
myrsi15min=0
else
myrsi15min=100-100/(1+up15min/dw15min)
endif
if barindex>cyclicmemory15min then
crsi15min=torque15min*(2*myrsi15min-myrsi15min[phasinglag15min])+(1-torque15min)*crsi15min[1]
endif
//————————————-//
// LowBand and HighBand calculation
//————————————-//
Period15min=cyclicMemory15min
percent15min = leveling15min/100
periodMinusone15min = period15min-1
maxima15min = -999999.0
minima15min = 999999.0
for i15min=0 to periodMinusone15min do
if crsi15min[i15min] > maxima15min then
maxima15min = crsi15min[i15min]
elsif crsi15min[i15min] < minima15min then
minima15min = crsi15min[i15min]
endif
next
stepfactor15min = (maxima15min-minima15min)/100
//lowband15min = 0
for steps15min=0 to 100 do
testvalue15min = minima15min+stepfactor15min*steps15min
below15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]<testvalue15min then
below15min=below15min+1
endif
next
if below15min/period15min >= percent15min then
//lowband15min = testvalue15min
break
endif
next
//highband15min=0
for steps15min=0 to 100 do
testvalue15min=maxima15min-stepfactor15min*steps15min
above15min=0
for m15min=0 to periodMinusone15min do
if crsi15min[m15min]>=testvalue15min then
above15min=above15min+1
endif
next
if above15min/Period15min >= percent15min then
//highband15min=testvalue15min
break
endif
next
//mbb15min = average[50](crsi15min)
CRSISmooth15min = average[7](crsi15min)
LongPos = (kama1h > kama1h[1]) and (close > kama1h) and (kama15min > kama15min[1]) and (close > kama15min) and (CRSI15min crosses over CRSISmooth15min)
Signal = 0
if longpos then
Signal = 1
endif
SCREENER[Signal]
merci. Fifi743 m’a transmis ce screener mais il ne fonctionne pas très bien (problème de l’updateonclose je pense).
Entrée longue en erreur
This topic contains 11 replies,
has 3 voices, and was last updated by finplus
1 year ago.
| Forum: | ProBuilder : Indicateurs & Outils Personnalisés |
| Language: | French |
| Started: | 01/18/2025 |
| Status: | Active |
| Attachments: | 3 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.