BardParticipant
Master
Can anyone think of why this System won’t optimise the c2 entry condition?
Dow Daily / 26th Aug 2010 – 12th Oct 2017 / 3.8 spread
I actually am not sure how to code it so it takes a long trade after one day of no Bear condition (return to neutral, no Bulls, no Bears) having been preceded by eg, 5, days of a Bear condition? (Other than laboriously programming using, if indicator2[5] = -1, and indicator2[4]= -1, and indicator2[3]= -1, and indicator2[2]= -1, and indicator2[1]= -1 are ALL Bears) AND this is then followed by an end of Bear condition (indicator2=0) (for one day) before the Long trade is then initiated?
I was attempting to optimise the number of days prior that a Bear condition needs to be in place (from 1 to 300 days), before a long trade is initiated but that doesn’t mean it’s continuously been in Bear territory for ALL those days which is what I actually want.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
capital = 100000 + strategyprofit //Current profit made by the closed trades of the running strategy.
n = capital / close
// Conditions to enter long positions
ignored, indicator1, ignored = CALL "Bull/Bear 20% ALMA"(close)
c1 = (indicator1 = 0) // Bear = Off
ignored, indicator2, ignored = CALL "Bull/Bear 20% ALMA"(close)
c2 = (indicator2[a] = -1) // Bear = On
IF c1 AND c2 THEN
BUY n PERPOINT AT MARKET
ENDIF
IF BarIndex - TradeIndex = 30 Then
SELL at Market
EndIF
Thanks in advance for any ideas or help.
I haven’t fully understood what your issue is with the Optimiser, but I’ve had weird stuff happening all day!
The Optimiser will not / does not give me results for Gain other than the Gain which the System shows without the code / variables I am trying to Optimise.
To put it another way … it’s like the System is as good as it can get and the extra conditions / variables that I have added can only make the Gain lower so the Optimiser comes up with all variable combinations that make no difference / don’t exist during the 100k bars I was Optimising over.
Hope that makes sense.
Maybe your indicator has a “division by zero” issue, or uses non integer values or values < 1, say with HIGHEST or similar.
Why do you call the indicator twice? You only need to call it once like this:
// Conditions to enter long positions
ignored, indicator1, ignored = CALL "Bull/Bear 20% ALMA"(close)
c1 = (indicator1 = 0) // Bear = Off
c2 = (indicator1[a] = -1) // Bear = On
If you want to check that it has been in bear territory for a set number of bars then you need to use SUMMATION:
c2 = (summation[a](indicator1 = -1) = a)
BardParticipant
Master
Right, I’m not sure why yours is behaving like that GraHal?
Mine, it turns out didn’t like the date range Aug 2010 to Oct 2017, but when I optimise the system for the Trump rally Nov 2016 to Jan 2018 it optimises and shows 149 days is optimal time to hold before exiting a trade and produces 30k profit BUT… then I use 120 days as it seems to be a number the optimisation results are missing and don’t have a value for (pls see Excel screenshot) and the system makes £100k?
Why does it have “missing” values between 1 and 300 days?
So I set it to exactly 149, the “optimal” nos. of days to exit the trades, (12 of them) and again I get a higher profit (£105k Gain).
I’ve not seen or noticed the Optimiser do this before? Can anyone figure out what it’s doing or why as the code seems “simple” enough?
Cheers.
BardParticipant
Master
Thanks for making the code more efficient Vonasi and showing me that Summation code! This “buy on the Bear spike” with the strategy profit trade size algo did £159k on the Dax – same dates – with 38% Drawdown, typical of trend following systems. See attached. The trade exit = 100 days was a random figure and the first I tried.
Kempen’s head of asset allocation said he had observed that several pension funds had already switched to quarterly rebalancing. However, he argued that rebalancing only once a year would be more beneficial in may cases.
https://www.ipe.com/countries/netherlands/less-frequent-rebalancing-would-benefit-pension-funds-say-managers/www.ipe.com/countries/netherlands/less-frequent-rebalancing-would-benefit-pension-funds-say-managers/10021831.fullarticle
I’m not saying there is a link it was just something I read.
BardParticipant
Master
Cheers.
Do you mean like Line 11: Offset = 0.85? Would that cause a problem is a system optimisation that uses an indicator with a value less than zero?
I’ve not heard of the “division by zero” issue, what is that, or am I experiencing it right now!?
Help Creating Bull Market Indicator with a Custom Indicator
BardParticipant
Master
|
|
c2 = (summation[a](indicator1 = –1) = a)
|
Hi @Vonasi,
When I tested the Summation optimisation as above it produced no trades? Pls see image.
If I remove the = a but keep the last bracket it works.. for a while then I get the optimisation error? (Roberto was referring above to some issues being the possible cause of the optimisation problem. I’m still not sure what it is exactly about this system though that stops it being optimised half way through? The Bull/Bear indicator code has an offset value of 0.85?
Do you or anyone else know why it seem to optimise and then at other times not? The system below in this post optimised okay, but the one in post https://www.prorealcode.com/topic/optimisation-fails/#post-95102
won’t optimise? I have tried two version of the indicator one with the 20% condition and one without but that makes no difference it still won’t optimise…
Ideally I want to be able to optimise the number of days for a Bear before entering and the number of days before exiting (from 1 to 100 days) but can’t?
Cheers,
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
capital = 100000 + strategyprofit //Current profit made by the closed trades of the running strategy.
n = capital / close
// Conditions to enter long positions
ignored, indicator1, ignored = CALL "Bull/Bear 20% ALMA"(close)
c1 = (indicator1 = 0) // Bear = 0
c2 = (summation[a](indicator1 = -1) = a)
IF c1 AND c2 THEN
BUY n PERPOINT AT MARKET
ENDIF
IF BarIndex - TradeIndex = 100 Then
SELL at Market
EndIF
//Bear 20% w. ALMA
// 20% Bull/Bear Market increase/decrease in Prices
//DEFPARAM CalculateOnLastBars = 5000
Period = 50 //start with 50 periods
Series = customclose
FOR j = 1 TO 3
Sigma = 6
Offset = 0.85
m = ROUND(Offset * (Period - 1))
s = Period / Sigma
WtdSum = 0
CumWt = 0
FOR k = 0 TO Period - 1 DO
Wtd = EXP(-((k - m) * (k - m)) / (2 * s * s))
WtdSum = WtdSum + Wtd * Series[Period - 1 - k]
CumWt = CumWt + Wtd
NEXT
IF CumWt <= 0 THEN
AFR = Series
ELSE
AFR = WtdSum / CumWt
ENDIF
IF j = 1 THEN
ShortMA = AFR
ELSIF j = 2 THEN
MediumMA = AFR
ELSE
LongMA = AFR
ENDIF
Period = Period * 2 //double periods
NEXT
// 20% Bull Market increase in Prices
BullC1 = Close[0] > ShortMA
BullC2 = Close[0] > MediumMA
BullC3 = Close[0] > LongMA
BullC4 = Close[0] >= (Close[200] * 1.2)
// 20% Bear Market decrease in Prices
BearC5 = Close[0] < ShortMA
BearC6 = Close[0] < MediumMA
BearC7 = Close[0] < LongMA
BearC8 = Close[0] <= (Close[200] * 1.2)
Return BullC1 and BullC2 and BullC3 and BullC4 as "Bull Market", -(BearC5 and BearC6 and BearC7 and BearC8) as "Bear Market",0
BardParticipant
Master
Now I can’t optimise this benchmark system below either (which Im using to compare to the performance of the Bull/Bear 20% System above) :
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
c1 = (DOpen(0) > DClose(1))
IF c1 THEN
BUY 6 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
ignored, ignored, ignored, ignored, ignored, DEV = CALL "Kase Dev Stop Lisse+SAR+4.5/6"
c2 = (close CROSSES UNDER DEV)
IF c2 THEN
SELL AT MARKET
ENDIF
Set Stop pLoss a
Do you know what is going on with PRT’s optimisation engine @nicolas as I just successfully optimised the same system (using a different parameter (most profitable number of days needed to exit)?
Cheers for any insights,
If you get an error during a optimization run then it is usually due to poor internet. I know this because I ‘borrow’ my internet from a bar just behind my boat and on Saturdays and Sundays when the bar is full of people staring at their mobile phones and the internet is slow I can’t optimize anything without getting the error that you showed earlier.
As for your optimizations showing zero for all the results this is usually because either the entry criteria is never met or the exit criteria is never met so it has a trade or trades open but never closes them and so never makes a profitable trade to show you in the results. You need to GRAPH c1 and c2 to see if your entry conditions are ever met.
BardParticipant
Master
Thanks so much Vonasi, it’s been really hit and miss back testing lately! And thanks for the tip with the graphing. 👌
BardParticipant
Master
Yeah.. it’s not the internet connection and the backtest fails half way through optimisation 100% of the time because of the Bull Bear ALMA indicator being used on the Entry. I just used another entry and it will optimise the number of days before exiting the position.
Does anyone know what specifically is causing the issue with the indicator?
Thanks,
//Bear 20% w. ALMA
// 20% Bull/Bear Market increase/decrease in Prices
//DEFPARAM CalculateOnLastBars = 5000
Period = 50 //start with 50 periods
Series = customclose
FOR j = 1 TO 3
Sigma = 6
Offset = 0.85
m = ROUND(Offset * (Period - 1))
s = Period / Sigma
WtdSum = 0
CumWt = 0
FOR k = 0 TO Period - 1 DO
Wtd = EXP(-((k - m) * (k - m)) / (2 * s * s))
WtdSum = WtdSum + Wtd * Series[Period - 1 - k]
CumWt = CumWt + Wtd
NEXT
IF CumWt <= 0 THEN
AFR = Series
ELSE
AFR = WtdSum / CumWt
ENDIF
IF j = 1 THEN
ShortMA = AFR
ELSIF j = 2 THEN
MediumMA = AFR
ELSE
LongMA = AFR
ENDIF
Period = Period * 2 //double periods
NEXT
// 20% Bull Market increase in Prices
BullC1 = Close[0] > ShortMA
BullC2 = Close[0] > MediumMA
BullC3 = Close[0] > LongMA
BullC4 = Close[0] >= (Close[200] * 1.2)
// 20% Bear Market decrease in Prices
BearC5 = Close[0] < ShortMA
BearC6 = Close[0] < MediumMA
BearC7 = Close[0] < LongMA
BearC8 = Close[0] <= (Close[200] * 1.2)
Return BullC1 and BullC2 and BullC3 and BullC4 as "Bull Market", -(BearC5 and BearC6 and BearC7 and BearC8) as "Bear Market",0
fails half way through optimisation 100% of the time because of the Bull Bear ALMA indicator being used on the Entry
Does it also fail on 10,000 or 5,000 or 1,000 bars etc?
BardParticipant
Master
Yeah cheers @GraHal, it’s not the bar length it’s definitely the Bull/Bear ALMA as it worked on 5000 units using a generic entry like (DOpen(0) < DClose(1)) for entry instead of that indicator. It seems really hit or miss if it’ll work or not… I’m even trying different old systems and they’re also not optimising. The only thing that is different is I’m using wi-fi in a hotel. I will wait until I’m home later and test again using Ethernet because this is wasting an extraordinary amount of time!
Did you sort your gremlins out?
Did you sort your gremlins out?
No I had to go on Mothers day outings on Sunday and I’ve not looked at it since! 🙂
Sometimes we need to be forcible pulled away from problem solving as often ones brain comes up with solutions or at least alternatives to try while we are doing other tasks?