Hello,
I want to create a backtesting code for intraday Pivot Points. I used the indicator which Nicolas posted here:
Pivot points intraday
The code works, except for the stop loss and target profit. I want to buy or sell a contract at R1 / S1 and want to set the target at R2/S2. Stop Loss should be the Pivot Point.
I use the code for Forex.
Any help would be greatly appreciated 🙂
defparam cumulate orders = false
defparam flatbefore = 090000
if dayofweek=1 then //Monday
daytrading=1
endif
if dayofweek=2 then // Tuesday
daytrading=1
endif
if dayofweek=3 then // Wednesday
daytrading=1
endif
if dayofweek=4 then //Thursday
daytrading=1
endif
if dayofweek=5 then // Friday
daytrading=1
endif
// time
myStartHour = 7
myStartMinute = 00
myEndHour = 8
myEndMinute = 55
// time
start = (myStartHour * 10000) + (myStartMinute * 100)
ende = (myEndHour * 10000) + (myEndMinute * 100)
If (Day > Day[1]) Then
myLow = Low
myHigh = High
myClose = Close
countB = 0
countS = 0
currentdate=date
Endif
If (Time >= start) Then
myClose = Close
If High > myHigh Then
myHigh = High
Else
myHigh = myHigh[1]
Endif
If (Time > ende) Then
myHigh = myHigh[1]
myClose = myClose[1]
Endif
If Low < myLow Then
myLow = Low
Else
myLow = myLow[1]
Endif
If (Time > ende) Then
myLow = myLow[1]
Endif
Endif
If Time = ende Then //
// PP-Calculation
PP = (myHigh + myLow + myClose) / 3
R1 = 2 * PP - myLow
R22 = PP + (myHigh-myLow)
//R3 = 2*(PP-myLow)+myHigh
//R4 = 3*(PP-myLow)+myHigh
S1 = 2 * PP - myHigh
S2 = PP - (myHigh-mylow)
//S3 = myLow-(2*(myHigh-PP))
//S4 = myLow-(3*(myHigh-PP))
Endif
if longonmarket and positionprice<>lastpriceB then
countB = countB+1
countS = countS+1
lastpriceB = positionprice
endif
if shortonmarket and positionprice<>lastpriceS then
countS = countS+1
countB = countB+1
lastpriceS = positionprice
endif
if date=currentdate and time<=220000 and daytrading=1 then
if not longonmarket and countB=0 and close<R1 then
buy 1 share at R1 stop
set stop loss pp
set target profit R22
endif
if not shortonmarket and countS=0 and close>S1 then
sellshort 1 share at S1 stop
set stop loss pp
set target profit S2
endif
endif
Is anyone able to help? 🙂
Try it this way:
if not longonmarket and countB=0 and close<R1 then
buy 1 share at R1 stop
endif
if not shortonmarket and countS=0 and close>S1 then
sellshort 1 share at S1 stop
endif
if longonmarket then
sell at pp stop
sell at R22 limit
elsif shortonmarket then
exitshort at pp stop
exitshort at S2 limit
endif
Thanks a lot, that already works better!
But still, the “sell at R22 limit” and “exitshort at S2 limit” is not working correctly.
Maybe it is calculating the R22 and S2 from the moment the system buys or sells a share? Is there anything I can do that it calculates R22 and S2 at the given time above?
Check your variables with “graph” if they are calculated correctly.
It’s working 🙂 Thanks a lot!
Hi RoLaDay you write that you use your strategy on Forex, but works very well on DAX 1min, I have still built a MM the results are incredible.
But I used the first code without the conversion of desperation lg
Hello Jessar, maybe you can post your results here. I don’t get the incredible results you said 🙂 Thanks
I have tried the same backtest on the real account because I get no trades, and when I try to run the program I get the error stop / limit distance too far away, very funny. lg
I am surprised, however, how the baking to come to such results, they can not be invented