Thank you, it is good to know, that the code is actually working, but it is just not working on my pc. What could be a reason for that, since my picture shows a different result?
I can’t be of any help about this, maybe it’s because you deal with Futures while I trade CFDs, or maybe you are using end-of-day data.
I have no further clues.
Once again, when I use the following code with the euro dollar mini chart, the trade does not close when a new lower low forms. This exact code is working at different markets, like DAX or DOW JONES. The picture shows thursday 20.07.2017, and I backtested 100000 units.
Do I have to consider something special when using the euro dollar mini chart? Thank you!:)
// EURO DOLLAR MINI 15 min
DEFPARAM CumulateOrders = false
DEFPARAM FlatBefore = 000000
DEFPARAM FlatAfter = 234500
if OpenDayOfWeek = 1 then
Pivot = (DHigh(2) + DLow(2) + DClose(2)) / 3
//R1 = 2*Pivot - DLow(2)
//S1 = 2*Pivot - DHigh(2)
//rR2 = Pivot + (DHigh(2) - DLow(2))
S2 = Pivot - (DHigh(2) - DLow(2))
//R3 = R1 + (DHigh(2) - DLow(2))
//S3 = S1 - (DHigh(2) - DLow(2))
endif
if OpenDayOfWeek = 2 then
Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
//R1 = 2*Pivot - DLow(1)
//S1 = 2*Pivot - DHigh(1)
//rR2 = Pivot + (DHigh(1) - DLow(1))
S2 = Pivot - (DHigh(1) - DLow(1))
//R3 = R1 + (DHigh(1) - DLow(1))
//S3 = S1 - (DHigh(1) - DLow(1))
endif
if OpenDayOfWeek = 3 then
Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
//R1 = 2*Pivot - DLow(1)
//S1 = 2*Pivot - DHigh(1)
//rR2 = Pivot + (DHigh(1) - DLow(1))
S2 = Pivot - (DHigh(1) - DLow(1))
//R3 = R1 + (DHigh(1) - DLow(1))
//S3 = S1 - (DHigh(1) - DLow(1))
endif
if OpenDayOfWeek = 4 then
Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
//R1 = 2*Pivot - DLow(1)
//S1 = 2*Pivot - DHigh(1)
//rR2 = Pivot + (DHigh(1) - DLow(1))
S2 = Pivot - (DHigh(1) - DLow(1))
//R3 = R1 + (DHigh(1) - DLow(1))
//S3 = S1 - (DHigh(1) - DLow(1))
endif
if OpenDayOfWeek = 5 then
Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
//R1 = 2*Pivot - DLow(1)
//S1 = 2*Pivot - DHigh(1)
//rR2 = Pivot + (DHigh(1) - DLow(1))
S2 = Pivot - (DHigh(1) - DLow(1))
//R3 = R1 + (DHigh(1) - DLow(1))
//S3 = S1 - (DHigh(1) - DLow(1))
endif
dojisizes2d = 10
dojis2d = Range >= ABS(Open[1] - Close[1]) * dojisizes2d
bullishs2d = (dojis2d and low[1] <= s2+abstl2d and low[1] >= s2-abst2d and close>high[1] and low>low[1])
abst2d = 8*pipsize
abstl2d = 2*pipsize
size = 4
if bullishs2d then
ldbs2d = low[1]-2
Buy size Contract at Market
endif
if longonmarket and ldbs2d then
sell at ldbs2d stop
endif
if longonmarket and (close <low[1]) then
sell at market
endif
Once again, when I use the following code with the euro dollar mini chart, the trade does not close when a new lower low forms.
It simply DOES what you wrote. At line 95 you wrote to exit a LONG trade when a CLOSING price is lower THAN the previous low, not when it makes a lower low!
I’ve not really been following this thread but thought I would test the code you have given. I think I have the same section of chart as you and mine works fine.
[attachment file=71266]
I do notice a couple of things in your code that are unrelated. You have declared the variable values after they are used in a condition so as code is processed from top to bottom the value in the condition will be zero rather than your desired value:
bullishs2d = (dojis2d and low[1] <= s2+abstl2d and low[1] >= s2-abst2d and close>high[1] and low>low[1])
abst2d = 8*pipsize
abstl2d = 2*pipsize
Also you give a value to a variable at time of market entry and then use it as a condition to set a sell stop which is unnecessary as just being on the market is sufficient conditions to set the sell stop.
if bullishs2d then
ldbs2d = low[1]-2
Buy size Contract at Market
endif
if longonmarket and ldbs2d then
sell at ldbs2d stop
endif
Also you should consider that when a position is opened the Sell Stop will not be set until one bar later as at the time of entry the condition of OnMarket is not being met so you should put the Sell Stop in at the same time as the market entry is made or use a Set Stop Loss at time of entry and then add the Sell Stop one bar later.
if bullishs2d then
ldbs2d = low[1]-2
Buy size Contract at Market
sell at ldbs2d stop
endif
if longonmarket and close < low[1] then
sell at market
endif
I don’t get it why it sometimes works and sometimes it doesn’t work, this is very frustrating:( But apparently it always works with your computers. Maybe I do have to get some updates on my computer or something.
Isn’t that the same?:)
No.
Decisions are made at the close of a bar and so at that time the low could be lower than the previous bar but the close higher – or both the low and the close could be lower.
What spread have you set for the backtest?
The spread was 2.
OK – that shouldn’t be the issue then.
I’ve taken the liberty of tidying up your code a little but I cannot explain why it closes the position at the wrong time on your chart. Which broker are you using?
// EURO DOLLAR MINI 15 min
DEFPARAM CumulateOrders = false
DEFPARAM FlatBefore = 000000
DEFPARAM FlatAfter = 234500
if OpenDayOfWeek = 1 then
Pivot = (DHigh(2) + DLow(2) + DClose(2)) / 3
S2 = Pivot - (DHigh(2) - DLow(2))
endif
if OpenDayOfWeek = 2 or OpenDayOfWeek = 3 or OpenDayOfWeek = 4 or OpenDayOfWeek = 5 then
Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
S2 = Pivot - (DHigh(1) - DLow(1))
endif
dojisizes2d = 10
dojis2d = Range >= ABS(Open[1] - Close[1]) * dojisizes2d
abst2d = 8*pipsize
abstl2d = 2*pipsize
size = 4
bullishs2d = (dojis2d and low[1] <= s2+abstl2d and low[1] >= s2-abst2d and close>high[1] and low>low[1])
if bullishs2d then
ldbs2d = low[1]-2
Buy size Contract at Market
sell at ldbs2d stop
endif
if longonmarket then
sell at ldbs2d stop
endif
if longonmarket and (close <low[1]) then
sell at market
endif
Adding
GRAPH dojis2d
GRAPH bullishs2d
GRAPH ldbs2d
GRAPH close
GRAPH low[1]
helped me to spot that ldbs2d is negative because it subtracts 2 from 1.14793. Try with line 84 replaced by
ldbs2d = low[1]-2*pipsize
Now the trade you outlined will end at the closing of the candle with a closing price < low[1] (ProOrder will display a cross above the next bullish candlestick).
The spread was 2.
Which broker are you using?
I’m using firefox and I just downloaded a java update, but nothing changed. I will try internet explorer now.