Range Filter buy and sell
Forums › ProRealTime forum Français › Support ProOrder › Range Filter buy and sell
- This topic has 1 reply, 2 voices, and was last updated 3 weeks ago by Iván.
-
-
11/30/2024 at 4:54 PM #240942
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
endifif 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 5012/10/2024 at 1:49 PM #241311Bonnes! il a récupéré le code préparé dans le message que vous avez mentionné.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183// Original Script > @DonovanWall// Adapted Version > @guikrothDEFPARAM CumulateOrders = False // Cumul des positions désactivé//////////////////////////////////////////////////////////////////////////// Settings for 5min chart, BTCUSDC. For Other coin, change the parameters//////////////////////////////////////////////////////////////////////////// Color variablesdownColorR = 255downColorG = 69downColorB = 0upColorR = 50upColorG = 205upColorB = 50midColorR = 0midColorG = 191midColorB = 255// Sourcesrc = customclose// Sampling Period// Settings for 5min chart, BTCUSDC. For Other coin, change the paremetersper = 100//defval=100, minval=1, "Sampling Period"// Range Multipliermult = 3//defval=3.0, minval=0.1, "Range Multiplier"// Smooth Average Rangewper = per*2 -1avrng = exponentialaverage[per](abs(src-src[1]))smrng = mult * exponentialaverage[wper](avrng)// Range Filterrngfilt = srcIf src > rngfilt[1] thenIf rngfilt[1] > src-smrng thenrngfilt = rngfilt[1]Elserngfilt = src-smrngendifelsif rngfilt[1] < src+smrng thenrngfilt = rngfilt[1]elserngfilt = src+smrngendiffilt = rngfilt// Filter Directionupward = 0If filt > filt[1] thenupward = upward[1]+1elsif filt < filt[1] thenupward = 0elseupward = upward[1]endifdownward = 0If filt < filt[1] thendownward = downward[1]+1elsif filt > filt[1] thendownward = 0elsedownward = downward[1]endif// Target Bandshband = filt + smrnglband = filt - smrng// ColorsIf upward > 0 thenfiltcolorR = upColorRfiltcolorG = upColorGfiltcolorB = upColorBelsif downward > 0 thenfiltcolorR = downColorRfiltcolorG = downColorGfiltcolorB = downColorBelsefiltcolorR = midColorRfiltcolorG = midColorGfiltcolorB = midColorBendifif src > filt and src > src[1] and upward > 0 thenbarcolorR = upColorRbarcolorG = upColorGbarcolorB = upColorBelsif src > filt and src < src[1] and upward > 0 thenbarcolorR = upColorRbarcolorG = upColorGbarcolorB = upColorBelsif src < filt and src < src[1] and downward > 0 thenbarcolorR = downColorRbarcolorG = downColorGbarcolorB = downColorBelsif src < filt and src > src[1] and downward > 0 thenbarcolorR = downColorRbarcolorG = downColorGbarcolorB = downColorBelsebarcolorR = midColorRbarcolorG = midColorGbarcolorB = midColorBendif// Break OutslongCond = (src > filt and src > src[1] and upward > 0) or (src > filt and src < src[1] and upward > 0)shortCond = (src < filt and src < src[1] and downward > 0) or (src < filt and src > src[1] and downward > 0)CondIni = 0If longCond thenCondIni = 1elsif shortCond thenCondIni = -1elseCondIni = CondIni[1]endiflongCondition = longCond and CondIni[1] = -1shortCondition = shortCond and CondIni[1] = 1//AlertsIf longCondition thenbuy 1 contract at marketendifIf shortCondition thensellshort 1 contract at marketendif///trailing stop functiontrailingstart = 5 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THENIF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF// points based STOP LOSS and TRAILING STOP// initial STOP LOSSSET STOP pLOSS 50// trailing stopSET STOP pTRAILING 50//-----------------------------------------//graphonprice filt coloured(barcolorR,barcolorG,barcolorB,255)graphonprice hband coloured(upColorR,upColorG,upColorB,100)graphonprice lband coloured(downColorR,downColorG,downColorB,100) -
AuthorPosts
Find exclusive trading pro-tools on