Hi.
I’m new to prorealtime and need some help.
I’ve come across the problem (not a new one, actually well documented) regarding proorder having limited stop loss functionality.
I’m seen the post for how to “Complete trailing stop code function” http://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ but I don’t understand the code.
So I’ve tried to create an indicator than would show me what my stops would be. I’ve dumped the code at the bottom
Basically
- assuming a long position entered @ 1.03
- want a maximum loss of 30bp
- want a trailing stop loss of 20bps with a 5bp step
My question is
- how can I view results for variables I create, ie “mystep”?
- I know my code is poor, what could you recommend to enhance?
//trailing stop function
trailingstart = 20 //trailing will start
trailingstep = 5 //trailing step to move the "stoploss"
mybailout = 30 //my stop loss point
mytradeprice = 1.03 //setting random trade price assumming long position
IF close >= mytradeprice+(trailingstart*pipsize) then
ITM = 1 //if 1 when use trailing loss, if 0 use stop loss
ENDIF
IF close < (mytradeprice+(trailingstart*pipsize)) then
ITM = 0
ENDIF
IF ITM = 0 then
mySL = mytradeprice-(mybailout*pipsize)
ENDIF
IF ITM = 1 then
mystep = (close -trailingstart*pipsize)/trailingstep //counts the number of steps the trailing profit has taken above the trailingstart
ENDIF
IF ITM = 1 then
mySL = mytradeprice+(trailingstart*pipsize)+(mystep*(trailingstep*pipsize))
ENDIF
return mySL as "Closeout"
Hi All
I figured it out, you just have to use the return function. I have done the majority of my coding in VBA so you can see the variable as you step through the code
Have updated my code (for long positions only) to have an indicator that will show you you exit levels
//trailing stop function
//variables
mytradedprice = open
myclose = close
trailingstart = 10 //trailing will start
trailingstep = 5 //trailing step to move the "trailing stop"
mybailout = -10 //my stop loss point
trailingstartprice = mytradedprice+(trailingstart*pipsize)
trailingstopprice = mytradedprice+(mybailout*pipsize)
myprofit = myclose - trailingstartprice
ITM = 0
IF myclose >= trailingstartprice then
ITM = 1
else
ITM = 0
ENDIF
IF ITM = 0 then
mySL = trailingstopprice
else
mysteps = (myclose - trailingstartprice)/(trailingstep*pipsize)
rmysteps = round(mysteps)
mySL = trailingstartprice + (rmysteps*trailingstep*pipsize) - (trailingstart*pipsize)
ENDIF
return mytradedprice as "My Open Price", mySL as "My Closeout Price", myprofit as "Profit"
Great! But in ProBacktest you can also use GRAPH which is likely a ‘return’ function into automated trading code.