Bonsoir,
le problème de mon programme rejoint ma demande dans le forum screener posté sur ce site. je voudrais entrer en position (long ou short) dès que le ruban (bleu ou rouge) change de couleur.
Sauf que en faisant un back test, les entrés en position affichés ne correspondent pas aux changements de couleur.
Merci pour votre aide.
/// Définition des paramètres du code
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
//////////////////////////////////////////////////////////////////// parameters KAMA
//////////////////////////////////////////////////////////////////////////
// Settings for 5min chart, BTCUSDC. For Other coin, change the parameters
//////////////////////////////////////////////////////////////////////////
// Source
src = customclose
// Sampling Period
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
per =100
// Range Multiplier
mult =3.0
// Smooth Average Range
wper = per*2 -1
avrng = exponentialaverage[per](abs(src-src[1]))
smrng = mult * exponentialaverage[wper](avrng)
// Range Filter
rngfilt = src
If src > rngfilt[1] then
If rngfilt[1] > src-smrng then
rngfilt = rngfilt[1]
Else
rngfilt = src-smrng
endif
elsif rngfilt[1] < src+smrng then
rngfilt = rngfilt[1]
else
rngfilt = src+smrng
endif
filt = rngfilt
// Filter Direction
upward = 0
If filt > filt[1] then
upward = upward[1]+1
elsif filt < filt[1] then
upward = 0
else
upward = upward[1]
endif
downward = 0
If filt < filt[1] then
downward = downward[1]+1
elsif filt > filt[1] then
downward = 0
else
downward = downward[1]
endif
//// Zone de couleurs : selon des conditions
////////////////////////////////////////////////////////////////////////////
mbTendance = ( Average[3](filt) + filt)/2
mbtendanceUP = mbTendance > mbTendance[1]
mbTendanceDn = mbTendance < mbTendance[1]
if not mbtendanceUp[1] and mbtendanceUp then
buy 1 contract at market
endif
if not mbtendanceDn[1] and mbtendanceDn 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
// points based STOP LOSS and TRAILING STOP
// initial STOP LOSS
SET STOP pLOSS 50
// trailing stop
SET STOP pTRAILING 50