Hope someone can help me out with this, PING NICOLAS!
My backtest takes a short while when putting it on automatic trading it took a long today (see picture) Happened several times now.
This is the code im using:
//-------------------------------------------------------------------------
// Main code : Open DAX 5 optimerad
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Main code : Open DAX 5 optimerad
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Main Code : Straddle Dayopen V2.0
//-------------------------------------------------------------------------
// Test On DAX 30 Cash 10 Minute Timeframe 200k bars or from 1/1/2015
// Common Rules
Defparam Cumulateorders = False
Defparam Preloadbars = 1000
// On/off
Extratradecriteria = 0 // I.e. Long; Only Enters When The Current Bar High Is Lower Then The Lowest Daily High From Today, Yesterday And Day Before.
Usepercentage = 0 // The Minimum Difference In Percentage [[1] From Dayopen Or In Points [0] From Dayopen
Mfetrailing = 1 // Mfe Trailing Stop
Wtrailing = 1 // Williams 3 Bar Trailing Stop
Breakevenstop = 1 // Breakevenstop, Move Stoploss When Position Is In Profit.
Excludefirsttwoweeks = 1 // Exclude The First 2 Weeks Of Every Year (Weeknumber 1 And 2)
// Settings
Positionsize = 1
SL = 0.6 // % Stoploss
PT = 1.5 // % Profit Target
MFETS = 0.35 // % Mfe Trailing Stop
BES = 0.35 // % Break Even Stop
BESMP = 0.05 // % Break Even Stop Minimum Profit
WTSMP = 0.50 // % Williams Trailing Stop Minimum Profit If Mfe Trailing Stop Is Not Used
ETD = 0 // Exclude a Trade Day; Sunday = 0
If Usepercentage Then
Nopl=((Dayopen*0.15)/100)/pointsize
Nops=((Dayopen*0.15)/100)/pointsize
Else
Nopl=16 //number of points long
Nops=12 //number of points short
Endif
// Day & Time
Once Entertime = 090000
Once Lasttime = 100000
Once Closetime = 172500 // Greater Then 23.59 Means It Continues Position Overnight
Once Closetimefr=173500
If Excludefirsttwoweeks=1 Then
If Year=2015 And Month=1 And (Day>=1 And Day<=18) Then
Notrading = 1
Elsif Year=2016 And Month=1 And (Day>=1 And Day<=24) Then
Notrading = 1
Elsif Year=2017 And Month=1 And (Day>=1 And Day<=22) Then
Notrading = 1
Elsif Year=2018 And Month=1 And (Day>=1 And Day<=21) Then
Notrading = 1
Elsif Year=2019 And Month=1 And (Day>=1 And Day<=20) Then
Notrading = 1
Else
Notrading = 0
Endif
Endif
Tt1 = Time >= Entertime
Tt2 = Time <= Lasttime
Tradetime = Tt1 And Tt2 and Notrading = 0 And Dayofweek <> ETD
// Reset At Start
If Intradaybarindex = 0 Then
Longtradecounter = 0
Shorttradecounter = 0
Tradecounter = 0
Mclong = 0
Mcshort = 0
Endif
// [pc] Position Criteria
Pclong = Countoflongshares < 1 And Longtradecounter < 1 And Tradecounter < 1
Pcshort = Countofshortshares < 1 And Shorttradecounter < 1 And Tradecounter < 1
// [mc] Main Criteria
If Time = Entertime Then
Dayopen=open
Endif
If High > Dayopen+nopl Then
Mclong=1
Else
Mclong=0
Endif
If Low < Dayopen-nops Then
Mcshort=1
Else
Mcshort=0
Endif
// [ec] Extra Criteria
If Extratradecriteria Then
Min1 = Min(Dhigh(0),dhigh(1))
Min2 = Min(Dhigh(1),dhigh(2))
Max1 = Max(Dlow(0),dlow(1))
Max2 = Max(Dlow(1),dlow(2))
Eclong = High < Min(Min1,min2)
Ecshort = Low > Max(Max1,max2)
else
Eclong=1
Ecshort=1
Endif
// Long & Short Entry
If Tradetime Then
If Pclong and Mclong And Eclong Then
Buy Positionsize Contract At Market
Longtradecounter=longtradecounter + 1
Tradecounter=tradecounter+1
Endif
If Pcshort and Mcshort And Ecshort Then
Sellshort Positionsize Contract At Market
Shorttradecounter=shorttradecounter + 1
Tradecounter=tradecounter+1
Endif
Endif
// Break Even Stop
If Breakevenstop Then
If Not Onmarket Then
Newsl=0
Endif
If Longonmarket And close-tradeprice(1)>=((Tradeprice/100)*BES)*pipsize Then
Newsl = Tradeprice(1)+((Tradeprice/100)*BESMP)*pipsize
Endif
If Shortonmarket And Tradeprice(1)-close>=((Tradeprice/100)*BES)*pipsize Then
Newsl = Tradeprice(1)-((Tradeprice/100)*BESMP)*pipsize
Endif
If Newsl>0 Then
Sell At Newsl Stop
Exitshort At Newsl Stop
Endif
Endif
// Exit Mfe Trailing Stop
If Mfetrailing Then
Trailingstop = (Tradeprice/100)*MFETS
If Not Onmarket Then
Maxprice = 0
Minprice = Close
Priceexit = 0
Endif
If Longonmarket Then
Maxprice = Max(Maxprice,close)
If Maxprice-tradeprice(1)>=trailingstop*pipsize Then
Priceexit = Maxprice-trailingstop*pipsize
Endif
Endif
If Shortonmarket Then
Minprice = Min(Minprice,close)
If Tradeprice(1)-minprice>=trailingstop*pipsize Then
Priceexit = Minprice+trailingstop*pipsize
Endif
Endif
If Onmarket And Wtrailing=0 And Priceexit>0 Then
Sell At Market
Exitshort At Market
Endif
Endif
// Exit Williams Trailing Stop
If Wtrailing Then
Count=1
I=0
J=i+1
Tot=0
While Count<4 Do
Tot=tot+1
If (Low[j]>=low[i]) And (High[j]<=high[i]) Then
J=j+1
Else
Count=count+1
I=i+1
J=i+1
Endif
Wend
Basso=lowest[tot](Low)
Alto=highest[tot](High)
If Close>alto[1] Then
Ref=basso
Endif
If Close<basso[1] Then
Ref=alto
Endif
If Onmarket And Mfetrailing=0 And Positionperf>WTSMP Then
If Low[1]>ref And High<ref Then
Sell At Market
Endif
If High[1]<ref And Low>ref Then
Exitshort At Market
Endif
Endif
If Onmarket And Mfetrailing=1 And Priceexit>0 Then
If High<ref Then
Sell At Market
Endif
If Low>ref Then
Exitshort At Market
Endif
Endif
Endif
// Exit At Closetime
If Onmarket Then
If Time >= Closetime Then
Sell At Market
Exitshort At Market
Endif
Endif
// Exit At Closetime Friday
If Onmarket Then
If (Currentdayofweek=5 And Time>=closetimefr) Then
Sell At Market
Exitshort At Market
Endif
Endif
// Build-in Exit
Set Stop %loss SL
Set Target %profit PT
//graph 0 Coloured(300,0,0) As "Zeroline"
//graph (Positionperf*100)coloured(0,0,0,255) As "Positionperformance"
Did you start it today? Customized trading hours on your chart or not?
Did you start it today? Customized trading hours on your chart or not?
started it like a week ago. Yes have customized trading hours on chart to be able to see gaps. +1 timezon and showing 08:00-16:30 (shows std at 0 timezon) since DAX opens at 09-17,30
can you please help me out Nicolas? Seems that only you might have to correct approach
did the same today, even changed showing custom trading hours… is there a code i should enter i my strategy?
Are you making it as easy as you possibly can for somebody to see at a glance what the symptoms of your problem are?
For example, why don’t you show 2 screenshots side by side with arrows pointing to the 2 trade positions that are in opposite directions?
Folks are busy and there are so many draws on our time, life even – outside of PRT 🙂 , that we need the symptoms to jump out of the screen at us then we may go looking for the source of the symptoms (the problem).
If you have done above and I am still missing it then apologies.
What is the screen shot attached (copied from your original post) supposed to show / tell us? There is no trade running at all at time of the screen shot indicated by the red arrow?
According to the first picture, and if I have understood it clearly, the BUY and SELLSHORT are not happening on the same candlestick but one later? IMO, it is a problem of custom trading hours. Do you have or not weekend data displayed? If not, you should.
What happen if you are not using custom trading hours at all, but with the real market time?
Are you making it as easy as you possibly can for somebody to see at a glance what the symptoms of your problem are?
For example, why don’t you show 2 screenshots side by side with arrows pointing to the 2 trade positions that are in opposite directions?
Folks are busy and there are so many draws on our time, life even – outside of PRT
, that we need the symptoms to jump out of the screen at us then we may go looking for the source of the symptoms (the problem).
If you have done above and I am still missing it then apologies.
What is the screen shot attached (copied from your original post) supposed to show / tell us? There is no trade running at all at time of the screen shot indicated by the red arrow?
it shows that its that strategy im running, showing im not backtesting another strategy and another running on auto..
Try to set preloadbars to 0.
It is only a matter of conditions read differently in the 2 environment. I can’t replicate the same order on 28th November, orders are opened later in the day..