BardParticipant
Master
I posted this: https://www.prorealcode.com/topic/how-do-you-optimise-bands-based-on-price/#post-77380
a month ago and would still like to know how this achieved using the PRT platform.
Cheers in advance.
Was 2 weeks ago. Please don’t double post! You can “up” your topic if you think people are not answering as fast as you want.
BardParticipant
Master
Sorry! Wrong link above. The request was actually posted a month ago: https://www.prorealcode.com/topic/optimisation-of-atr-dev-stops/
How do I “up” my own post?
(Have a few tech issues using Safari here on PRC – hence comment about not seeing the post when I first posted as it wasn’t in my Topics list and so I reposted it later that day.
I won’t double post again… Frankly I have no idea how you keep up with the myriad of single posts/comment threads here but appreciate that you do)
Ok, so that is a triple posts! First time for me! 😆
To “up” your topic (being freshness), just reply to it.
When posting a new topic, be sure to have sufficient words in your title (at least 2 words).
I replied yesterday to the second one, link in the first post of this topic! (so confusing…).
BardParticipant
Master
“First time for me!” You and me!
My original post disappeared, so I thought better makes sure… then it reappeared later on a new log in.. ooops.
Then I reposted the same question 2 wks later.. ooops.
Should I hand myself in to ‘Forum Etiquette’ jail?
Thank you for the optimisation tip @nicolas.
I was trying to do it from the Variable Optimisation spanner and also didn’t have the indicator code in the strategy.
Now, when I add my (Stop and Reverse) Kase Dev Stop code posted here:
to the System code (Kase Peak Oscillator entry and Dev Stop exit) I am still not sure how to proceed?
A lot of the indicator code needed to be removed with: “//” as “it’s not found” when I click on the backtest button.
If I try and “optimise” the Dev Stop 3.6 by adding the line with something like: p3=optimiseddevstop
I’m getting the same profit result when I know that using Dev 1.0 or Dev 2.2 makes a difference in the profit when running backtests.
Why do I get the feeling I’m going to be saying “D’oh!” when you explain what I’m doing wrong?
BardParticipant
Master
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
ignored, ignored, ignored, ignored, indicator2 = CALL "Kase Peak Oscillator"
c1 = (indicator2 < 0)
IF c1 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
ignored,ignored,indicator3,ignored,ignored, ignored = CALL "Kase Dev Stop Lisse +SAR+4.5/6"
c2 = (close CROSSES UNDER indicator3)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
ignored, ignored, ignored, ignored, indicator5 = CALL "Kase Peak Oscillator"
c3 = (indicator5 > 0)
IF c3 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to exit short positions
ignored,ignored,indicator6,ignored, ignored, ignored = CALL "Kase Dev Stop Lisse +SAR+4.5/6"
c4 = (close CROSSES OVER indicator6)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
//SET STOP pTrailing 500 //OPTIMISED = 430
//250 and anything over 300 to 500 tics)
//Settings
n=30
p1=1.0
p2=2.2
p3=optimiseddev
p4=4.5
p5=6.0
difference=0
Hg=highest[2](high)
Lw=lowest[2](low)
DTR=max(max(Hg-Lw,abs(Hg-close[2])),abs(Lw-close[2]))
aDTR=average[n](DTR)
for i=0 to n-1 do
difference=difference+square(DTR[i]-aDTR)
next
difference=difference/n
sdev=sqrt(difference)
dev0=close-aDTR
dev1=close-aDTR-p1*sdev
dev2=close-aDTR-p2*sdev
dev3=close-aDTR-p3*sdev
dev4=close-aDTR-p4*sdev
dev5=close-aDTR-p5*sdev
if dev0<dev0[1] and close>dev5[1] then
dev0=dev0[1]
endif
if dev1<dev1[1] and close>dev5[1] then
dev1=dev1[1]
endif
if dev2<dev2[1] and close>dev5[1] then
dev2=dev2[1]
endif
if dev3<dev3[1] and close>dev5[1] then
dev3=dev3[1]
endif
if dev4<dev4[1] and close>dev5[1] then
dev4=dev4[1]
endif
if dev5<dev5[1] and close>dev5[1] then
dev5=dev5[1]
endif
dev6=close+aDTR
dev7=close+aDTR+p1*sdev
dev8=close+aDTR+p2*sdev
dev9=close+aDTR+p3*sdev
dev10=close+aDTR+p4*sdev
dev11=close+aDTR+p5*sdev
if dev6>dev6[1] and close<dev11[1] then
dev6=dev6[1]
endif
if dev7>dev7[1] and close<dev11[1] then
dev7=dev7[1]
endif
if dev8>dev8[1] and close<dev11[1] then
dev8=dev8[1]
endif
if dev9>dev9[1] and close<dev11[1] then
dev9=dev9[1]
endif
if dev10>dev10[1] and close<dev11[1] then
dev10=dev10[1]
endif
if dev11>dev11[1] and close<dev11[1] then
dev11=dev11[1]
endif
if close>dev11[1] then
//flag=-1
else
if close<dev5[1] then
//flag=1
endif
endif
//if flag=-1 then
//ind0=dev0
//ind1=dev1
//ind2=dev2
//ind3=dev3
//ind4=dev4
//ind5=dev5
//k=1
//r=0
//g=191
//b=255
//else
//ind0=dev6
//ind1=dev7
//ind2=dev8
//ind3=dev9
//ind4=dev10
//ind5=dev11
//k=-1
//r=255
//g=128
//b=0
//endif
//ORANGE AND LIGHT BLUE
//return ind0 coloured(r,g,b) style(dottedline,2) as "Warning Line", ind1 coloured(r,g,b) style(dottedline,2) as "Dev Stop 1.0", ind2 coloured(r,g,b) style(dottedline,2) as "Dev Stop 2.2", ind3 coloured(r,g,b) style(line,2) as "Dev Stop 3.6", ind4 coloured(r,g,b) style(dottedline,2) as "Dev Stop 4.5", ind5 coloured(r,g,b) style(line,2) as "Dev Stop 6.0"
To optimise variables in a strategy REM them out by typing // in front of them where their value is set and then click the spanner shown in my image and then enter the variable name and assign the start and finish quantities and steps you want to optimize over. Add multiple variables to do several at the same time – up to a limit.
[attachment file=78493]
BardParticipant
Master
Thanks @Vonassi I didnt know about the REM strikeouts.
However I get the same profit result of 15.427k (please see screenshot) which is wrong because I’ve seen different profits results by using different Dev Stops. i.e. I’ve individually tested which Dev Stop to use to produce the most profit for this system by manually moving the Dev Stop by changing Dev 2.2 (standard deviations) to Dev 3.6, by moving “indicator 6” code over to the right from:
// Conditions to exit short positions
ignored,ignored,indicator6,ignored, ignored, ignored = CALL "Kase Dev Stop Lisse +SAR+4.5/6"
c4 = (close CROSSES OVER indicator6)
to:
// Conditions to exit short positions
ignored,ignored,ignored,indicator6,ignored, ignored = CALL "Kase Dev Stop Lisse +SAR+4.5/6"
c4 = (close CROSSES OVER indicator6)
Yet these screens show 15.427k profit for ALL the Dev Stops ranging from 1.0 to 6.0?
(I did try using “//” for all the Dev Stops for P1 to P5 – it just produces the same 15.427k profit figure).
Cheers
Bard
I’ve not been following the thread closely enough to understand all the ins and outs of it but if you see all the same results in your optimization then it is usually the fact that the different value has no effect on the result or you have the optimized variable still fixed at a value somewhere in the code.
BardParticipant
Master
Then it must be this: “you have the optimized variable still fixed at a value somewhere in the code” although I’m not sure where?
The Dev Stops are basically just like an ATR band being used as a Stop, so it’s like asking: how far away is the optimal distance from price so I know where to put my ATR band to maximise returns.
“you have the optimized variable still fixed at a value somewhere in the code” although I’m not sure where?
Use Find (right click within the coding window) to search for the variable name … sounds like you have used the same name twice??
BardParticipant
Master
I can see another reference for the p1, p2 etc starting from line 87. Is that what is causing this Dev Stop not to be able to be optimised? Yet it is supposed to be possible?
Here is the full code a few posts further up this page @GraHal
https://www.prorealcode.com/topic/how-do-you-optimise-atr-stops-around-price/#post-78491
Cheers
Your ProOrder program don’t have sufficient information to know what to optimize. All the indicators declared at lines 5,13,21,29 don’t have settings. These indicators must have their settings set as external ones and not in their codes to be CALLed and optimized with ProBacktest.
For example, the settings for the “Kase Dev Stop Lisse +SAR+4.5/6” indicator should be REM or // like Vonasi said:
//n=30
//p1=1.0
//p2=2.2
//p3=3.6
//p4=4.5
//p5=6.0
and these settings added as external variables like explained in this video:
[youtube]https://youtu.be/HHxh9Vti4VM[/youtube]
BardParticipant
Master
Cheers @nicolas, right, that makes sense why it wouldn’t work using “//” on all the variables as per Vonasi’s tip.
Now that I have an improved indicator with adjustable settings (as per the video above) and an optimised parameter set in the auto system (made in steps of 0.2 because 0.1 is too much to calculate/optimise), I get this warning when running an optimised backtest, please see screenshot ?
Ideally I’d want to just use one variable “devstopoptimised” or “p1” (with values ranging from 1 to 7) to test the whole range of values, from dev stop 1.0 (standard deviations) all the way up to dev stop 7.5 which is the widest stop used by Cynthia Kase… but that would alter the whole way that the Stop and Reverse SAR works in this indicator.
That’s normal since your CALL function is no longer valid. Now, if you want to call your indicator, you must embed the variables when you declare it:
CALL "Kase Dev Stop Lisse +SAR+4.5/6"[p1,p2,p3,p4,p5]
See CALL instruction in the documentation: https://www.prorealcode.com/documentation/call/