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 regards
//Entry en position
//POSITION LONG
IF CONDBUY THEN
buy positionsize contract at market
SET STOP %LOSS 2.6 // i Want different value here for long??
SET STOP PLOSS 102 // i Want different value here for long??
ENDIF
//POSITION SHORT
IF CONDSELL THEN
Sellshort positionsize contract at market
SET STOP %LOSS 0.6 // i Want different value here for short??
SET STOP PLOSS 45 // i Want different value here for short??
ENDIF
SET STOP PLOSS 100 // I dont get same result even if i put same value in both long/short
SET TARGET %PROFIT 2.8 // I dont get same result even if i put same value in both long/short
//--------------------------------------------------------------------------------------------------------------------------------------------------
// Trailingstop
IF Not OnMarket THEN
//
// when NOT OnMarket reset values to default values
//
TrailStart = 15 // 15=85%...62=61% Start trailing profits from this point
BasePerCent = 0.04 // Profit percentage to keep when setting BerakEven
StepSize = 7 // 15/7= 86%win- Pip chunks to increase Percentage
PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk
RoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0
Barnumber = 52 // 20
Barpercent = 0 //0.2 // 20%
PriceDistance = 7 * pipsize
y1 = 0
y2 = 0
etc
etc
Simply remove lines 17-18.
Pellejons – 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.
I 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!
To 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.
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
positionsize=1
Ctime = time >= 140000 and time < 221400//Euro time
ONCE PeriodeA = 4
ONCE nbChandelierA= 30
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTE
CB1 = ANGLE >= 34
CS1 = ANGLE <= - 48
//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
ONCE PeriodeB = 30
ONCE nbChandelierB= 35
lag = 0
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]) / nbchandelierB
trigger = 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 period
lengthStoch = 20 //Stochastic period
smoothK = 12 //Smooth signal of stochastic RSI
smoothD = 2 //Smooth signal of smoothed stochastic RSI
myRSI = RSI[lengthRSI](close)
MinRSI = lowest[lengthStoch](myrsi)
MaxRSI = highest[lengthStoch](myrsi)
StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
K = average[smoothK](stochrsi)*100
D = average[smoothD](K)
cb4 = K>D
cs4 = K<D
//--------------------------------------------
Tenkan = (highest[9](high)+lowest[9](low))/2
Kijun = (highest[26](high)+lowest[26](low))/2
SSpanA = (tenkan[26]+kijun[26])/2
SSpanB = (highest[52](high[26])+lowest[52](low[26]))/2
If SSpanA>SSpanB then
if open<SSpanA and open>SSpanB or close<SSpanA and close>SSpanB then
CondIchi = 0
Else
CondIchi = 1
endif
endif
If SSpanB>SSpanA then
if open>SSpanA and open<SSpanB or close>SSpanA and close<SSpanB then
CondIchi = 0
Else
CondIchi = 1
endif
endif
CONDBUY = CB1 and CB2 and CB3 and cb4 and CTime and CondIchi
CONDSELL = CS1 and CS2 and CS3 and cs4 and Ctime and CondIchi
VarDistIchiBuy = 6
VarDistIchiSell = 21
If CONDBUY then
DistIchiSSA = Open - SSpanA
DistIchiSSB = Open - SSpanB
CondDistIchi = DistIchiSSA >= VarDistIchiBuy AND DistIchiSSB >= VarDistIchiBuy
Endif
If CONDSELL then
DistIchiSSA = SSpanA - Open
DistIchiSSB = SSpanB - Open
CondDistIchi = DistIchiSSA >= VarDistIchiSell AND DistIchiSSB >= VarDistIchiSell
Endif
CONDBUY = CONDBUY and CondDistIchi
CONDSELL = CONDSELL and CondDistIchi
//--------------------------------------------------------------------------------------------------------------------------------------------------
//Entry en position
//POSITION LONG
IF CONDBUY THEN
buy positionsize contract at market
SET STOP %LOSS 2.6
SET TARGET %PROFIT 2.2
ENDIF
//POSITION SHORT
IF CONDSELL THEN
Sellshort positionsize contract at market
SET STOP %LOSS 1.2//.5
SET TARGET %PROFIT 1.2//2.5
ENDIF
//Break even
breakevenPercent = 0.21
PointsToKeep = 5
startBreakeven = tradeprice(1)*(breakevenpercent/100)
once breakeven = 1//1 on - 0 off
//reset the breakevenLevel when no trade are on market
if breakeven>0 then
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
endif
// trailing atr stop
once trailingstoptype = 1 // trailing stop - 0 off, 1 on
once tsincrements = .05 // set to 0 to ignore tsincrements
once tsminatrdist = 7
once tsatrperiod = 18 // ts atr parameter
once tsminstop = 12 // ts minimum stop distance
once tssensitivity = 1 // [0]close;[1]high/low
if trailingstoptype then
if barindex=tradeindex then
trailingstoplong = 3 // ts atr distance
trailingstopshort = 3 // ts atr distance
else
if longonmarket then
if tsnewsl>0 then
if trailingstoplong>tsminatrdist then
if tsnewsl>tsnewsl[1] then
trailingstoplong=trailingstoplong
else
trailingstoplong=trailingstoplong-tsincrements
endif
else
trailingstoplong=tsminatrdist
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
if trailingstopshort>tsminatrdist then
if tsnewsl<tsnewsl[1] then
trailingstopshort=trailingstopshort
else
trailingstopshort=trailingstopshort-tsincrements
endif
else
trailingstopshort=tsminatrdist
endif
endif
endif
endif
tsatr=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)) then
tsmaxprice=0
tsminprice=close
tsnewsl=0
endif
if tssensitivity then
tssensitivitylong=high
tssensitivityshort=low
else
tssensitivitylong=close
tssensitivityshort=close
endif
if longonmarket then
tsmaxprice=max(tsmaxprice,tssensitivitylong)
if tsmaxprice-tradeprice(1)>=tgl*pointsize then
if tsmaxprice-tradeprice(1)>=tsminstop then
tsnewsl=tsmaxprice-tgl*pointsize
else
tsnewsl=tsmaxprice-tsminstop*pointsize
endif
endif
endif
if shortonmarket then
tsminprice=min(tsminprice,tssensitivityshort)
if tradeprice(1)-tsminprice>=tgs*pointsize then
if tradeprice(1)-tsminprice>=tsminstop then
tsnewsl=tsminprice+tgs*pointsize
else
tsnewsl=tsminprice+tsminstop*pointsize
endif
endif
endif
if longonmarket then
if tsnewsl>0 then
sell at tsnewsl stop
endif
if tsnewsl>0 then
if low crosses under tsnewsl then
sell at market // when stop is rejected
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
exitshort at tsnewsl stop
endif
if tsnewsl>0 then
if high crosses over tsnewsl then
exitshort at market // when stop is rejected
endif
endif
endif
endif
if onmarket then
if dayofweek=0 and (hour=0 and minute>=57) and abs(dopen(0)-dclose(1))>50 and positionperf(0)>0 then
if shortonmarket and close>dopen(0) then
exitshort at market
endif
if longonmarket and close<dopen(0) then
sell at market
endif
endif
endif
I 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!?
Feb 21 2020
Mar 17 2020
Jun 19 2020
I think its more! But those 3 are obvious..