ProRealCode - Trading & Coding with ProRealTime™
It may be that the code needs an extra Endif adding as the last line of the code?
Thanks, i will try.
That’s curious it works on backtest but not in autotrading.
I will tell back
You can’t launch the system in autotrading because there are variables in the optimization boxes; you have first to define the values through the code, delete the optimization boxes and then you can run it.
I don’t think i have to do it with the last version of prorealtime V11.
The problem doesn’t come from it in my opinion
I have v11 and can’t run it for the problem i mentioned you
NIK 1m Hull-SAR
Hello everyone
Thank you very much for this good basic strategy. I ask for your indulgence and understanding, because I am still a beginner, do not speak English and work with a translator!
I do a test and optimization with Nikkei, with good results (see appendix). It doesn’t run live for very long and keeps getting error messages (see appendix). During the American trading hours it runs for 4 to 5 hours and a profit trade has already been achieved, but I need your help. How to get the algorithm stable, without error message and shutdown. On Nasdaq, things are going better but not perfect either, with 2 to 3 errors a week (always live).
– Error 1: Division by zero – what protections are there? That’s why I use MTF 5min over 7min to 22min total runs on 1min.
– Error 2: Historical data is not sufficient?
Ask for your help. I think the algorithm has potential. What is your opinion on this?
One more general question at the end. Can algorithms, after hundreds of hours of invested work, win in the long run? When will the marketplace come? ( I have at the moment 10 Algo live, of which 5 for rent )
Once again, pay tribute to your work!
Here are the .itf and pictures.
Thank you for your comment and help.
// Definition of code parameters
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
DEFPARAM preloadbars = 10000
//Money Management NAS
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize=0.5
ENDIF
if MM = 1 then
ONCE startpositionsize = 0.5
ONCE factor = 6 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 200 // IG first tier margin limit
ONCE maxpositionsize = 2000 // IG tier 2 margin limit
ONCE minpositionsize = .5 // enter minimum position allowed
IF StrategyProfit <> StrategyProfit[1] THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
Ctime = time >=103000 and time <211400
TIMEFRAME(22 minutes)
Period= 80
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULLa = weightedaverage[round(sqrt(Period))](inner)
c1 = HULLa > HULLa[1] or HULLb > HULLa
c2 = HULLa < HULLa[1] or HULLb < HULLa
ST1 = SAR[0.02,0.015,0.025]
c1a = (close > ST1)
c2a = (close < ST1)
TIMEFRAME(7 minutes)
Periodb= 17
innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
c3 = HULLb > HULLb[1]
c4 = HULLb < HULLb[1]
c3b = HULLb > HULLb[1] and HULLb[1] < HULLb[2]
c4b = HULLb < HULLb[1] and HULLb[1] > HULLb[2]
ST2 = SAR[0.015,0.015,0.02]
c3a = (close > ST2)
c4a = (close < ST2)
//Stochastic RSI | indicator
lengthRSI = 3 //RSI period
lengthStoch = 3 //Stochastic period
smoothK = 6 //Smooth signal of stochastic RSI
smoothD = 4 //Smooth signal of smoothed stochastic RSI
myRSI = RSI[lengthRSI](close)
MinRSI = lowest[lengthStoch](myrsi)
MaxRSI = highest[lengthStoch](myrsi)
StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
K = average[smoothK](stochrsi)*100
D = average[smoothD](K)
c3c = K>D
c4c = K<D
TIMEFRAME(5 minutes)
Periodc= 4
innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
c5 = HULLc > HULLc[1] and HULLc[1] < HULLc[2]
c6 = HULLc < HULLc[1] and HULLc[1] > HULLc[2]
c5b = HULLc > HULLc[1]
c6b = HULLc < HULLc[1]
ST3 = SAR[0.005,0.015,0.015]
c5a = (close > ST3)
c6a = (close < ST3)
TIMEFRAME(default)
Once MaxPositionsAllowed = 5*positionsize
// Conditions to enter long positions
IF not longonmarket and Ctime and c1 and c1a AND C3a and c3b and c3c AND C5a and c5b THEN
BUY positionsize CONTRACT AT MARKET
elsif longonmarket and Ctime and c1 and c1a and c3 and c3a and c5 and COUNTOFLONGSHARES < MaxPositionsAllowed then
BUY positionsize CONTRACT AT MARKET
SET STOP %LOSS 1.6
SET TARGET %PROFIT 1.4
ENDIF
// Conditions to enter short positions
IF not shortonmarket and Ctime and c2 and c2a AND C4a and c4b and c4c AND C6a and c6b THEN
sellshort positionsize CONTRACT AT MARKET
elsif shortonmarket and Ctime and c2 and c2a and c4 and c4a and c6 and COUNTOFSHORTSHARES < MaxPositionsAllowed then
sellshort positionsize CONTRACT AT MARKET
SET STOP %LOSS 1.2
SET TARGET %PROFIT 1.7
ENDIF
// %trailing stop function incl. cumulative positions
once trailingstoptype = 1
if trailingstoptype then
//====================
once trailingpercentlong = 0.47 // %
once trailingpercentshort = 0.56 // %
once accelerator = 0.095 // 1 = default; always > 0 (i.e. 0.5-3)
once accelerator2 = 0.31 // 1 = default; always > 0 (i.e. 0.5-3)
once ts2sensitivity = 0 // [0]close;[1]high/low;[2]low;high
//====================
once steppercentlong = (trailingpercentlong/10)*accelerator
once steppercentshort = (trailingpercentshort/10)*accelerator2
if onmarket then
trailingstartlong = positionprice[1]*(trailingpercentlong/100)
trailingstartshort = positionprice[1]*(trailingpercentshort/100)
trailingsteplong = positionprice[1]*(steppercentlong/100)
trailingstepshort = positionprice[1]*(steppercentshort/100)
endif
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
newsl = 0
mypositionprice = 0
endif
positioncount = abs(countofposition)
if newsl > 0 then
if positioncount > positioncount[1] then
if longonmarket then
newsl = max(newsl,positionprice * newsl / mypositionprice)
else
newsl = min(newsl,positionprice * newsl / mypositionprice)
endif
endif
endif
if ts2sensitivity=1 then
ts2sensitivitylong=high
ts2sensitivityshort=low
elsif ts2sensitivity=2 then
ts2sensitivitylong=low
ts2sensitivityshort=high
else
ts2sensitivitylong=close
ts2sensitivityshort=close
endif
if longonmarket then
if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize then
newsl = positionprice+trailingsteplong*pipsize
endif
if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize then
newsl = newsl+trailingsteplong*pipsize
endif
endif
if shortonmarket then
if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize then
newsl = positionprice-trailingstepshort*pipsize
endif
if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize then
newsl = newsl-trailingstepshort*pipsize
endif
endif
if barindex-tradeindex>1 then
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
if newsl>0 then
if low crosses under newsl then
sell at market
endif
endif
endif
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
if newsl>0 then
if high crosses over newsl then
exitshort at market
endif
endif
endif
endif
mypositionprice = positionprice
endif
You can’t launch the system in autotrading because there are variables in the optimization boxes; you have first to define the values through the code, delete the optimization boxes and then you can run it.
In v11 you can launch it like this (or should be able to do that). PRT changed my values to 17 decimal places as described in #165505. I have made a copy with fixed values in the code instead but then I get “Division by zero”.
You can’t launch the system in autotrading because there are variables in the optimization boxes; you have first to define the values through the code, delete the optimization boxes and then you can run it.
I don’t think i have to do it with the last version of prorealtime V11.
The problem doesn’t come from it in my opinion
I have v11 and can’t run it for the problem i mentioned you
The problem is line 2. There must not exist any blank lines before the defparam lines. Remove the line or put // into it.
The error message is confusing.
Hi, thanks for that, I would not normally have tried working with the Nikkei because the spread is so high.
This is a good start but you’ve got various problems:
first, it’s optimized on very little data so it really only works from July 2020, before that it’s a bust – sorry!
Also, you’ve changed the logic of the original. The idea is that it enters when the middle TF (ie 6 min) changes direction, then adds subsequent positions when the fast TF (2min) dips. You have it entering at the 7min level and adding at the 5min level, where there’s hardly any difference between the two.
If you really want to make a version for Japan 225 (although personally I think the spread is a killer), I would stick to the original 2min structure (v5.5) which is tried and tested and you’ll get twice as much data to work with.
As for the NAS version, I’ve been running it live for many months and never had a div/zero problem. No idea why you would get that error. Are you running the most recent version?
It may be that the code needs an extra Endif adding as the last line of the code?
It is the exact same version as the NAS one that works, only optimized for Short on DJ. I also get the same problem with other optimizations on other markets, even with Long. It´s so frustrating after so many hours of testing to get this problem…
As for the NAS version, I’ve been running it live for many months and never had a div/zero problem. No idea why you would get that error. Are you running the most recent version?
I have also been running the NAS 5.3 version for a long time without problems, so one issue can be the values I have chosen when optimizing. I can get Long to work on some markets, but never Short…
It may be that the code needs an extra Endif adding as the last line of the code?
It is the exact same version as the NAS one that works, only optimized for Short on DJ. I also get the same problem with other optimizations on other markets, even with Long. It´s so frustrating after so many hours of testing to get this problem…
Is there a blank line before the defparam instructions? This is not allowed, the resulting error message is confusing
Is there a blank line before the defparam instructions? This is not allowed, the resulting error message is confusing
Thanks for your reply! I´m checking right now but it doesn´t seem to help, but very good to know!
I delete a space line 2 and modified endif as @Grahal said and now there is no error to launch in autotrading.
First step is done. Now trouble with preloadbars
I still have error message after 100k preloadbars !!!
Still have problem after 500k preloadbars because an indicator …
Try again with 10000 preload bars as that is the maximum allowed anyway.
Have you got an indicator with a massive period like 20000 or something that requires more than 10000 bars to calculate?
Hello Nevertheless, thank you for your response and I appreciate her excellent work. I have 2 variants Live, NAS 1m Hull-SAR v.7.5 is very good for Long and Short ( see appendix ), but unfortunately brings bugs every now and then, Division Zero, which was also template for Nikkei, where it doesn’t work at all and then I still have NAS 2m Hull-SAR v5.5L Live, runs first without errors but unfortunately only Long good and Short rather bad (see appendix) . Is it possible to optimize, as the short also runs? That would be perfect! There are other times that the whole market short goes. Have version v5.5 also tested on Nikkei looks perfect ( see appendix ) it would pay off to get the short under control. I think you should have other values in your portfolio than DOW, DAX and so on. I’m happy to hear from them again and maybe you’re going to get to the short problem. Unfortunately, I am only a user and not a programmer, because I lack too many connections.
NAS 2m HULL-SAR trading system
This topic contains 343 replies,
has 42 voices, and was last updated by bege
3 years, 8 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 10/09/2020 |
| Status: | Active |
| Attachments: | 129 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.