Hi
Was hoping someone can shed some light on the code below:
IF Bullish THEN
buy (100/(2*atr)) perpoint AT MARKET
set stop loss (2*atr)
set stop trailing (4*atr)
ENDIF
In the back test i was expecting the worst trade value to be £100 but turns out as £466. If you swap the position of the set stop loss and trailing i.e. have
set stop trailing (4*atr)
set stop loss (2*atr)
then the worst trade value os £384
If you change everything to 4*atr as below then the max loss comes to £232
IF Bullish THEN
buy (100/(4*atr)) perpoint AT MARKET
set stop loss (4*atr)
set stop trailing (4*atr)
ENDIF
I’m quite confused as to what i’m doing wrong. Anybody able to help please?
Kind regards
JV
Since you are using two different SL instructions, the second one will always override the first one.
Moreover, set stop trailing will backtest using a 1-pip step.
You’d better using custom code, instead.
You can retrieve many snippets on the forum or from the Snippet Library you can find using the search box.
jayvee – Welcome to the forums.
There are some basic rules that everyone needs to follow when posting in the forums and you have broken two of them.
Please always use the ‘Insert PRT Code’ button when putting code in your posts as it makes it much easier for others to read. The ‘Insert PRT Code’ button can be found at the far right of the tools that are located above the box where you type your post.
I have tidied up the code in your last post for you. 🙂
Also ensure that you post your topic in the correct forum. You posted in the General Discussion forum with a ProOrder autotrading related question. I have moved your topic to the correct forum.
Thank you Roberto and Vonasi. Apologies, will keep in mind next time; I’m new to this
I presume where it says in the documentation (https://www.prorealcode.com/blog/learning/kinds-trailing-stop-proorder/) the below is incorrect then?
SET STOP LOSS x TRAILING y
Is there a way of combining a hard stop loss (set stop loss x) as I’ve done above with Nicolas’ code as it only executes when the candle closes? Apologies, I know this is probably really basic!
//trailing stop function
trailingstart = 20 //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
//first move (breakeven)
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
Despite documentation, the line:
SET STOP LOSS x TRAILING y
is incorrect, since it contains 2 different kinds of SL on the same line. Use
SET STOP LOSS 0040 //requirese difference in Price, say 0040
SET STOP pLOSS 40 //requires numbers of Pips
then add the above code, as is (provided you set your own pip values), to your strategy.
40 pips for a forex pair like EURUSD is set with these instructions:
SET STOP LOSS 0.0040 //requirese difference in Price, say 0040
SET STOP pLOSS 40 //requires numbers of Pips