ProRealCode - Trading & Coding with ProRealTime™
Bonjour,
j’ai un petit souci avec ce bout de programme. Il ne prend de “position short” lorsqu’en UT 4h la kama 150 & trendEnvelop4h = -1
Je n’arrive pas à voir où ça coince.
Si quelqu’un a une idée, merci d’avance.
/// Définition des paramètres du code
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
Timeframe (4 hours)
//////////////////////////////////////////////////////////////////// parameters KAMA
Period4h = 150
FastPeriod4h = 2
SlowPeriod4h = 30
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
KAMAUp4h = (KAMA4h > KAMA4H[1])
KAMADN4h = (KAMA4h < KAMA4H[1])
/////////////////////////////// Trend Envelopppes (développé par Nicolas)
timePeriod4h=14
Deviation4h=0.1
price14h=customclose
dsma4h = WeightedAverage[timePeriod4h](price14h)
valuesHigh4h = (1 + deviation4h / 100) * dsma4h
valuesLow4h = (1 - deviation4h / 100) * dsma4h
inputs4h=price14h
if (inputs4h > valuesHigh4h)then
trendEnvelop4h = 1
elsif (inputs4h < valuesLow4h) then
trendEnvelop4h = -1
endif
TrendUp4h = kamaup4h and TrendEnvelop4h = 1
TrendDn4h = kamadn4h and TrendEnvelop4h = -1
Timeframe (15 minutes)
//////////////////////////////////////////////////////////////////// parameters KAMA
Period15min = 150
FastPeriod15min = 2
SlowPeriod15min = 30
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
KAMAUp15min = (KAMA15min > KAMA15min[1])
KAMADN15min = (KAMA15min < KAMA15min[1])
/////////////////////////////// Trend Envelopppes
timePeriod15min=14
Deviation15min=0.1
price115min=customclose
dsma15min = WeightedAverage[timePeriod15min](price115min)
valuesHigh15min = (1 + deviation15min / 100) * dsma15min
valuesLow15min = (1 - deviation15min / 100) * dsma15min
inputs15min=price115min
if (inputs15min > valuesHigh15min)then
trendEnvelop15min = 1
elsif (inputs15min < valuesLow15min) then
trendEnvelop15min = -1
endif
// Keltner Channel
periodMA15min=20
MA15min = ExponentialAverage[periodMA15min](close)
//============================== Indicateur Heikin Ashi IV avec le vrai close
//Hienkin IV
if barindex>1 then
haclosex15min=(open+close+low+high)/4
endif
KeltnerUp15min = haclosex15min > MA15min
KeltnerDn15min = haclosex15min < MA15min
TrendSignalUp15min = KAMAUp15min and KeltnerUp15min and trendEnvelop15min = 1
TrendSignalDn15min = KAMADn15min and KeltnerDn15min and trendEnvelop15min = -1
if TrendUp4h and TrendSignalUp15min then
buy 1 contract at market
endif
if TrendDn4h and TrendSignalDn15min then
sellshort 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
Bonjour,
Le problème que vous rencontrez dans votre code réside dans la condition TrendDn4h and TrendSignalDn15min pour l’ouverture d’une position short. Dans cette condition, vous avez utilisé TrendSignalDn15min qui est basé sur KAMADn15min, alors que dans votre code, vous utilisez KAMADN15min (avec des majuscules).
Il suffit de modifier la condition comme suit je crois :
if TrendDn4h and KAMADN15min then
sellshort 1 contract at market
endifBonjour,
merci pour votre aide mais le problème persiste.
Après avoir examiné à nouveau votre code, j’ai identifié un autre problème potentiel. Vous utilisez TrendDn4h pour vérifier la tendance baissière dans la condition if TrendDn4h and KAMADN15min then, mais TrendDn4h est basé sur kamadn4h (avec des minuscules), alors que vous utilisez KAMADN15min (avec des majuscules).
Veuillez modifier la condition comme suit :
if kamadn4h and KAMADN15min then
sellshort 1 contract at market
endif
Avec cette modification, le code devrait prendre une position short lorsque kamadn4h est vrai et que la condition KAMADN15min est également vraie.
Rebonjour,
non cela ne fonctionne toujours pas. Je ne crois pas que les lignes de programme soient sensibles au minuscule et au majuscule. Je pense qu’il y a une erreur évidente mais que je ne vois pas (d’autant plus que ces quelques lignes de code sont hyper simples).
j ai fait un BT sur dax 15 min, j ai des positions short. (dans l’état de votre code est publié ici).
Rien chez moi. Que des longs. Je ne comprends rien. Quelque chose m’échappe.
en prenant le 1 code sans rien faire j’ai des positions long et courte en DJI M5
ok merci. Je ne comprends pas alors ce qui se passe chez moi.
c’est quoi comme indice ou forex
// Définition des paramètres du code
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
//PRC_BuySell MagicBuySell Magic | indicator
//17.04.23
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//
// Starting from: https://www.prorealcode.com/prorealtime-indicators/buysell-magical-trend/
// Screener at user request 05.05.23 JC_Bywan https://www.prorealcode.com/topic/screener-buy-sell-magic-indicator/
//PRC_BuySell MagicBuySell Magic | indicator
//17.04.23
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//
// Starting from: https://www.prorealcode.com/prorealtime-indicators/buysell-magical-trend/
// Screener at user request 05.05.23 JC_Bywan https://www.prorealcode.com/topic/screener-buy-sell-magic-indicator/
Timeframe (4 hours)
//////////////////////////////////////////////////////////////////// parameters KAMA
Period4h = 150
FastPeriod4h = 2
SlowPeriod4h = 30
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
KAMAUp4h = (KAMA4h > KAMA4H[1])
KAMADN4h = (KAMA4h < KAMA4H[1])
/////////////////////////////// Trend Envelopppes (développé par Nicolas)
timePeriod4h=14
Deviation4h=0.1
price14h=customclose
dsma4h = WeightedAverage[timePeriod4h](price14h)
valuesHigh4h = (1 + deviation4h / 100) * dsma4h
valuesLow4h = (1 - deviation4h / 100) * dsma4h
inputs4h=price14h
if (inputs4h > valuesHigh4h)then
trendEnvelop4h = 1
elsif (inputs4h < valuesLow4h) then
trendEnvelop4h = -1
endif
// Keltner Channel
periodMA4h=20
MA4h = ExponentialAverage[periodMA4h](close)
//============================== Indicateur Heikin Ashi IV avec le vrai close
//Hienkin IV
if barindex>1 then
haclosex4h=(open+close+low+high)/4
endif
KeltnerUp4h = haclosex4h > MA4h
KeltnerDn4h = haclosex4h < MA4h
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//
// Starting from library: https://www.prorealcode.com/prorealtime-indicators/buysell-magical-trend/
// Screener at user request 05.05.23 JC_Bywan @ www.prorealcode.com
// https://www.prorealcode.com/topic/screener-buy-sell-magic-indicator/
// --- settings
SignalPeriod4h = 12
ArrowPeriod4h = 2
// --- end of settings
bbup4h = average[signalperiod4h]+std[signalperiod4h]*arrowperiod4h
bbdn4h = average[signalperiod4h]-std[signalperiod4h]*arrowperiod4h
if ts4h=0 then
if close crosses over bbup4h then
ts4h=bbdn4h
trendSignal4h=1
elsif close crosses under bbdn4h then
ts4h=bbup4h
trendSignal4h=-1
endif
endif
if trendSignal4h=1 then
ts4h=max(ts4h,bbdn4h)
elsif trendSignal4h=-1 then
ts4h=min(ts4h,bbup4h)
endif
if trendSignal4h=1 and close crosses under ts4h then
trendSignal4h=-1
ts4h=bbup4h
//r=255
//g=0
//drawarrowdown(barindex,ts) coloured("red")
//drawsegment(startbar,startts,barindex,ts) style(dottedline2) coloured("blue")
//startbar=barindex
//startts=ts
endif
if trendSignal4h=-1 and close crosses over ts4h then
trendSignal4h=1
ts4h=bbdn4h
//r=0
//g=255
//drawarrowup(barindex,ts) coloured("lime")
//drawsegment(startbar,startts,barindex,ts) style(dottedline2) coloured("blue")
//startbar=barindex
//startts=ts
endif
cup4h= trendSignal4h[1]=-1 and trendSignal4h=1
cdown4h= trendSignal4h[1]=1 and trendSignal4h=-1
TrendMagicalUp4h = cup4h or cup4h[1] or cup4h[2]
TrendMagicalDn4h = cdown4h or cdown4h[1] or cdown4h[2]
/////////////////////////////////////////////////// Trend4h paramètres
TrendSignalUp4h = KAMAUp4h and KeltnerUp4h and trendEnvelop4h = 1
TrendSignalDn4h = KAMADn4h and KeltnerDn4h and trendEnvelop4h = -1
Timeframe (1 hour)
//////////////////////////////////////////////////////////////////// parameters KAMA
Period1h = 150
FastPeriod1h = 2
SlowPeriod1h = 30
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
KAMAUp1h = (KAMA1h > KAMA1H[1])
KAMADN1h = (KAMA1h < KAMA1H[1])
/////////////////////////////// Trend Envelopppes (développé par Nicolas)
timePeriod1h=14
Deviation1h=0.1
price11h=customclose
dsma1h = WeightedAverage[timePeriod1h](price11h)
valuesHigh1h = (1 + deviation1h / 100) * dsma1h
valuesLow1h = (1 - deviation1h / 100) * dsma1h
inputs1h=price11h
if (inputs1h > valuesHigh1h)then
trendEnvelop1h = 1
elsif (inputs1h < valuesLow1h) then
trendEnvelop1h = -1
endif
// Keltner Channel
periodMA1h=20
MA1h = ExponentialAverage[periodMA1h](close)
//============================== Indicateur Heikin Ashi IV avec le vrai close
//Hienkin IV
if barindex>1 then
haclosex1h=(open+close+low+high)/4
endif
KeltnerUp1h = haclosex1h > MA1h
KeltnerDn1h = haclosex1h < MA1h
//17.04.23
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//
// Starting from library: https://www.prorealcode.com/prorealtime-indicators/buysell-magical-trend/
// Screener at user request 05.05.23 JC_Bywan @ www.prorealcode.com
// https://www.prorealcode.com/topic/screener-buy-sell-magic-indicator/
// --- settings
SignalPeriod1h = 12
ArrowPeriod1h = 2
// --- end of settings
bbup1h = average[signalperiod1h]+std[signalperiod1h]*arrowperiod1h
bbdn1h = average[signalperiod1h]-std[signalperiod1h]*arrowperiod1h
if ts1h=0 then
if close crosses over bbup1h then
ts1h=bbdn1h
trendSignal1h=1
elsif close crosses under bbdn1h then
ts1h=bbup1h
trendSignal1h=-1
endif
endif
if trendSignal1h=1 then
ts1h=max(ts1h,bbdn1h)
elsif trendSignal1h=-1 then
ts1h=min(ts1h,bbup1h)
endif
if trendSignal1h=1 and close crosses under ts1h then
trendSignal1h=-1
ts1h=bbup1h
//r=255
//g=0
//drawarrowdown(barindex,ts) coloured("red")
//drawsegment(startbar,startts,barindex,ts) style(dottedline2) coloured("blue")
//startbar=barindex
//startts=ts
endif
if trendSignal1h=-1 and close crosses over ts1h then
trendSignal1h=1
ts1h=bbdn1h
//r=0
//g=255
//drawarrowup(barindex,ts) coloured("lime")
//drawsegment(startbar,startts,barindex,ts) style(dottedline2) coloured("blue")
//startbar=barindex
//startts=ts
endif
cup1h= trendSignal1h[1]=-1 and trendSignal1h=1
cdown1h= trendSignal1h[1]=1 and trendSignal1h=-1
TrendMagicalUp1h = cup1h or cup1h[1] or cup1h[2]
TrendMagicalDn1h = cdown1h or cdown1h[1] or cdown1h[2]
/////////////////////////////////////////////////// Trend1h paramètres
TrendSignalUp1h = KAMAUp1h and KeltnerUp1h and trendEnvelop1h = 1
TrendSignalDn1h = KAMADn1h and KeltnerDn1h and trendEnvelop1h = -1
BuySignal1h = TrendMagicalUp1h and trendSignalUp1h and trendSignalUp4h
SellSignal1h = TrendMagicalDn1h and trendSignalDn1H and trendSignalDn4h
BuySignal4h = TrendMagicalUp4h and trendSignalUp1h and trendSignalUp4h
SellSignal4h = TrendMagicalDn4h and trendSignalDn1H and trendSignalDn4h
if BuySignal1h then
buy 1 contract at market
endif
if SellSignal1h then
sellshort 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
Je reviens avec mon programme : je joints donc le code en 4h et 1h et une pièce jointe pour montrer que le système prend bien une position vendeuse le 20 juin à 14 heures (je suis sur XAU / USD). Par contre, dans le code quand je change timeframe (1 hour) par timeframe (15 minutes) et que je lance bien mon back testing avec les UT 4h et 15 min et bien aucune position short n’est prise. Je ne comprends pas pourquoi.
en Backtest 5K unité
il y a bien des shorts en H4 et M15
j’ai juste changé le TF 1 H en 15 minute voir ci joint le screen
Merci fifi743. Alors je ne sais pas ce qui se passe sur ma plateforme.
alors je viens de mettre 5000 unités et tout fonctionne parfaitement. Merci.
merci pour ce partage ;
la strat s’avère perdante sur du H1 malheureusement sauf erreur ;
Système ne prenant pas la tendance baissière
This topic contains 19 replies,
has 5 voices, and was last updated by
Nicolas
2 years, 6 months ago.
| Forum: | ProOrder : Trading Automatique & Backtests |
| Language: | French |
| Started: | 06/24/2023 |
| 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.