Good Morning guys,
I need some help for the following simple strategy.
Basically if i use the strategies in separated long and short versions, probacktest works fine, but if I use them together in this way probacktests start to calculate and gets stuck.
Could someone help me and show me if I make some mistakes?
Thanks a lot in advance.
Max
defparam cumulateorders=false
// LONG STRATEGY
barlimit =10
c1=low[2]>low[1] and low[0]>low[1] and average[10](close)>average[24](close)
if not longonmarket and c1 then
entrylong=highest[1](high)+2*pointsize
myindex=barindex
SLlong=entrylong-(lowest[2](low)-2*pointsize)
endif
if barindex>=myindex + barlimit then
entrylong =0
endif
if entrylong>0 and not longonmarket then
BUY 1 shares at entrylong stop
set stop loss SLlong trailing SLlong
endif
//-----------------------------------------------
// SHORT STRATEGY
barlimit =10
c2=high[2]<high[1] and high[0]<high[1] and average[10](close)<average[24](close)
if not shortonmarket and c2 then
entryshort=lowest[1](low)-2*pointsize
myindex=barindex
SLshort=(highest[2](high)+2*pointsize)-entryshort
endif
if barindex>=myindex + barlimit then
entryshort =0
endif
if entryshort>0 and not shortonmarket then
sellshort 1 shares at entryshort stop
set stop loss SLshort trailing SLshort
endif
graph entrylong as "entry long"
graph entryshort as "entry short"
graph entrylong-SLlong as "stop loss long"
graph entryshort+SLshort as "stop loss short"
You should name your variable differently for short and long side of the strategy. For example ‘myindex’ is used in both sides and could generate problem when you compare it with barindex at lines 14 and 35. This is just what first come in mind when reading your code.
Of course as you already know it, you can have together long and short orders in the same strategy, one cancels other (also known as OCO).
Hi Nicolas, I’ve changed the name of the variables in “mylongindex” and “myshortindex” as you suggested but it doesn’t work the same.
I’ve also tried with “if not onmarket” instead of ” if not longonmarket” and “if not shortonmarket” but the system doesn’t work either.
Have you some other ideas?
Thanks
Max
I tested your code on Eur/Usd, h1, and it didn’t get stuck, as you can see from the screenshot.
I only modified the names as suggested by Nicolas and commented out all GRAPH instructions.
Hi Roberto, I’ve tried and it works only as soon as i shut and restart the platform, but when i relaunch the system it gets stuck.
It always works with you ? Have you tried to launch it several times?
Thanks
Max
Yes, it works anytime I launch it.
Thanks Roberto, yes probably it’s my internet connection, but it has happened also on the pc where I work.
Very strange it’s the first time that a system gets stuck.
Now with the forex market closed it works everytime i launch it.