Stopploss gives differents result in backtest
Forums › ProRealTime English forum › ProOrder support › Stopploss gives differents result in backtest
- This topic has 6 replies, 3 voices, and was last updated 4 years ago by
Pellejons.
-
-
01/28/2021 at 7:22 PM #159716
Hi trader! I have a problem i can´t solve properly. I would like to set different values for stopploss /profit when going long and use antoher value when im short! And not have same value for both long and short!
I also use trailing stop and breakeven.
I hope if anyone can help and tell me why its not working properly?
Best regards123456789101112131415161718192021222324252627282930313233343536373839//Entry en position//POSITION LONGIF CONDBUY THENbuy positionsize contract at marketSET STOP %LOSS 2.6 // i Want different value here for long??SET STOP PLOSS 102 // i Want different value here for long??ENDIF//POSITION SHORTIF CONDSELL THENSellshort positionsize contract at marketSET STOP %LOSS 0.6 // i Want different value here for short??SET STOP PLOSS 45 // i Want different value here for short??ENDIFSET STOP PLOSS 100 // I dont get same result even if i put same value in both long/shortSET TARGET %PROFIT 2.8 // I dont get same result even if i put same value in both long/short//--------------------------------------------------------------------------------------------------------------------------------------------------// TrailingstopIF Not OnMarket THEN//// when NOT OnMarket reset values to default values//TrailStart = 15 // 15=85%...62=61% Start trailing profits from this pointBasePerCent = 0.04 // Profit percentage to keep when setting BerakEvenStepSize = 7 // 15/7= 86%win- Pip chunks to increase PercentagePerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkRoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0Barnumber = 52 // 20Barpercent = 0 //0.2 // 20%PriceDistance = 7 * pipsizey1 = 0y2 = 0etcetc01/28/2021 at 7:30 PM #15971901/28/2021 at 7:52 PM #159722Pellejons – Please pay attention to where you post your topics. Your topic has been moved to the correct forum as described in the forum rules.
Post your topic in the correct forum:
_ ProRealTime Platform Support: only platform related issues.
_ ProOrder: only strategy topics.
_ ProBuilder: only indicator topics.
_ ProScreener: only screener topics
_ General Discussion: any other topics.
_ Welcome New Members: for new forum members to introduce themselves.01/30/2021 at 12:10 PM #159911I explain myself bad. I have tested a lot of times now. It seems to be a error in trailingstop code or platform it self that occurs 3 times at 200k bars where it lets through and lets the price go down to set stop %loss.
There will be some maxdraw losses I want to avoid.
The question is whether there is another code that can back up and catch what the trailing top misses? or other way to fix it?
Best regards!
01/30/2021 at 12:31 PM #159919To be able to help you we need to recreate exactly the same trades.
To help us, please:
- post the full working code
- tell us the date & time of entry of the trade(s) that produced unexpected results.
At present we only know you are trading Wall Street Cash (1€) on a 3-minute TF.
1 user thanked author for this post.
01/30/2021 at 1:10 PM #159920123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258DEFPARAM CumulateOrders = falseDEFPARAM Preloadbars = 50000positionsize=1Ctime = time >= 140000 and time < 221400//Euro timeONCE PeriodeA = 4ONCE nbChandelierA= 30MMA = Exponentialaverage[PeriodeA](close)ADJASUROPPO = (MMA-MMA[nbchandelierA]) / nbChandelierAANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTECB1 = ANGLE >= 34CS1 = ANGLE <= - 48//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILEONCE PeriodeB = 30ONCE nbChandelierB= 35lag = 0MMB = Exponentialaverage[PeriodeB](close)pente = (MMB-MMB[nbchandelierB]) / nbchandelierBtrigger = Exponentialaverage[PeriodeB+lag](pente)CB2 = (pente > trigger) AND (pente < 0)CS2 = (pente CROSSES UNDER trigger) AND (pente > - 0.5)mx = average[54,0](close)CB3 = mx > mx[1]mx2 = average[21,6](close)CS3 = mx2 < mx2[1]//------------------------------------------lengthRSI = 25 //RSI periodlengthStoch = 20 //Stochastic periodsmoothK = 12 //Smooth signal of stochastic RSIsmoothD = 2 //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K = average[smoothK](stochrsi)*100D = average[smoothD](K)cb4 = K>Dcs4 = K<D//--------------------------------------------Tenkan = (highest[9](high)+lowest[9](low))/2Kijun = (highest[26](high)+lowest[26](low))/2SSpanA = (tenkan[26]+kijun[26])/2SSpanB = (highest[52](high[26])+lowest[52](low[26]))/2If SSpanA>SSpanB thenif open<SSpanA and open>SSpanB or close<SSpanA and close>SSpanB thenCondIchi = 0ElseCondIchi = 1endifendifIf SSpanB>SSpanA thenif open>SSpanA and open<SSpanB or close>SSpanA and close<SSpanB thenCondIchi = 0ElseCondIchi = 1endifendifCONDBUY = CB1 and CB2 and CB3 and cb4 and CTime and CondIchiCONDSELL = CS1 and CS2 and CS3 and cs4 and Ctime and CondIchiVarDistIchiBuy = 6VarDistIchiSell = 21If CONDBUY thenDistIchiSSA = Open - SSpanADistIchiSSB = Open - SSpanBCondDistIchi = DistIchiSSA >= VarDistIchiBuy AND DistIchiSSB >= VarDistIchiBuyEndifIf CONDSELL thenDistIchiSSA = SSpanA - OpenDistIchiSSB = SSpanB - OpenCondDistIchi = DistIchiSSA >= VarDistIchiSell AND DistIchiSSB >= VarDistIchiSellEndifCONDBUY = CONDBUY and CondDistIchiCONDSELL = CONDSELL and CondDistIchi//--------------------------------------------------------------------------------------------------------------------------------------------------//Entry en position//POSITION LONGIF CONDBUY THENbuy positionsize contract at marketSET STOP %LOSS 2.6SET TARGET %PROFIT 2.2ENDIF//POSITION SHORTIF CONDSELL THENSellshort positionsize contract at marketSET STOP %LOSS 1.2//.5SET TARGET %PROFIT 1.2//2.5ENDIF//Break evenbreakevenPercent = 0.21PointsToKeep = 5startBreakeven = tradeprice(1)*(breakevenpercent/100)once breakeven = 1//1 on - 0 off//reset the breakevenLevel when no trade are on marketif breakeven>0 thenIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeepENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeepENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIFendif// trailing atr stoponce trailingstoptype = 1 // trailing stop - 0 off, 1 ononce tsincrements = .05 // set to 0 to ignore tsincrementsonce tsminatrdist = 7once tsatrperiod = 18 // ts atr parameteronce tsminstop = 12 // ts minimum stop distanceonce tssensitivity = 1 // [0]close;[1]high/lowif trailingstoptype thenif barindex=tradeindex thentrailingstoplong = 3 // ts atr distancetrailingstopshort = 3 // ts atr distanceelseif longonmarket thenif tsnewsl>0 thenif trailingstoplong>tsminatrdist thenif tsnewsl>tsnewsl[1] thentrailingstoplong=trailingstoplongelsetrailingstoplong=trailingstoplong-tsincrementsendifelsetrailingstoplong=tsminatrdistendifendifendifif shortonmarket thenif tsnewsl>0 thenif trailingstopshort>tsminatrdist thenif tsnewsl<tsnewsl[1] thentrailingstopshort=trailingstopshortelsetrailingstopshort=trailingstopshort-tsincrementsendifelsetrailingstopshort=tsminatrdistendifendifendifendiftsatr=averagetruerange[tsatrperiod]((close/8.8))/1000//tsatr=averagetruerange[tsatrperiod]((close/1)) // (forex)tgl=round(tsatr*trailingstoplong)tgs=round(tsatr*trailingstopshort)if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thentsmaxprice=0tsminprice=closetsnewsl=0endifif tssensitivity thentssensitivitylong=hightssensitivityshort=lowelsetssensitivitylong=closetssensitivityshort=closeendifif longonmarket thentsmaxprice=max(tsmaxprice,tssensitivitylong)if tsmaxprice-tradeprice(1)>=tgl*pointsize thenif tsmaxprice-tradeprice(1)>=tsminstop thentsnewsl=tsmaxprice-tgl*pointsizeelsetsnewsl=tsmaxprice-tsminstop*pointsizeendifendifendifif shortonmarket thentsminprice=min(tsminprice,tssensitivityshort)if tradeprice(1)-tsminprice>=tgs*pointsize thenif tradeprice(1)-tsminprice>=tsminstop thentsnewsl=tsminprice+tgs*pointsizeelsetsnewsl=tsminprice+tsminstop*pointsizeendifendifendifif longonmarket thenif tsnewsl>0 thensell at tsnewsl stopendifif tsnewsl>0 thenif low crosses under tsnewsl thensell at market // when stop is rejectedendifendifendifif shortonmarket thenif tsnewsl>0 thenexitshort at tsnewsl stopendifif tsnewsl>0 thenif high crosses over tsnewsl thenexitshort at market // when stop is rejectedendifendifendifendifif onmarket thenif dayofweek=0 and (hour=0 and minute>=57) and abs(dopen(0)-dclose(1))>50 and positionperf(0)>0 thenif shortonmarket and close>dopen(0) thenexitshort at marketendifif longonmarket and close<dopen(0) thensell at marketendifendifendifI have tried different trailing script .But it same result it let 3-6 long trades through the trailingscripts and hit at last set stop loss… Thats strange!?
01/30/2021 at 1:24 PM #159922 -
AuthorPosts
Find exclusive trading pro-tools on