Hi there,
I am having a problem with a set of “sell at stop” and “set stop loss” commands that I am trying to use to manage my losing positions.
I know what they both do and how to use them (let’s just go with that for a minute) – but I seem to be getting an inconsistent response from the the following set of commands:
if C1=8 and longonmarket then
sell at positionprice-240 stop
endif
if (C1<8 and C1>1) and longonmarket then
set stop loss 300
endif
if C1=1 and longonmarket then
sell at positionprice-10 stop
endif
Now, the problem is, is that sometimes I am getting a “set stop loss 300” response, which would be correct if the C1 value is from 7 to 2 inclusive (C1<8 and C1>1); but what I am seeing when I go through my backtest trade records, is that I am taking a 300 point stop loss when the C1 values seem to be 8 (loss should be 240 – sell at positionprice-240 stop) or when C1 = 1 (loss should be 10 – sell at positionprice-10 stop).
I found this problem because I was trying to turn the “set stop loss 300” into a “sell at positionprice-300 stop”, but I seemed to be losing money by doing this – and through investigation why into this I uncovered this problem.
There is only 1 variable at play, C1, and it can only take a value from 1 to 8.
The obvious consequence is that I am taking losses larger than intended – the thing that concerns me more is that I don’t know why this is happening and I’ve lost control of the process.
I have attached some pics to show when it seems to be working as planned, and when I am having the problem as described above.
Picture 1, or “P1” seems to show this problem – the closing C1 value of the bar before was 8. Now, this closing value of 8, should have meant that when the trade was opened, because C1=8, the stop for the trade should have been “sell at positionprice-240 stop”, or 240 points under the open. However, the stop was a 300 point loss, which would have meant that the “set stop loss 300” value was triggered – even though C1 had a value of 8.
Picture 2, or “P2” shows where this problem wasn’t evident and the code worked as planned – the closing value of C2 the value the bar before was 7, and the “set stop loss 300” for a 300 point loss was correctly triggered.
Picture 3, or “P3” seems to show the problem in action again – the last closing value for C1 the bar before was 1, so the stop should have been 10, “sell at positionprice-10 stop”, however the “set stop loss 300” came into play, and a 300 point loss was taken.
I was thinking that “hang on, is the C1 value of the last close, or is it from the current bar?” Should be from the last close… but if it wasn’t, in Picture 1 P1, the C1 value on the close of the trade bar is 1, so that would mean the loss should have been 240 or 10, and not 300.
Have also tried putting:
and longonmarket or not longonmarket
on all 3 IF lines, and it didn’t change anything.
I was also thinking that it might of been a time sync issue – the market, DJI A$1, has a time of UTC+00. I have all of my markets set to this UTC+00 time… was wondering if something was amiss there but that seems to line up.
Any ideas what I’ve done wrong, or what has gone wrong?
Thanks for your time and help,
Finning.