Optimization Issues

Posted By: Sage

Optimization Issues - 12/03/21 23:19

Okay so I am trying to optimize but keep getting same result for each parameter except the best optimal result. How can I go about it?
Check below for screenshots. Here lies the code:



function run()
{
set(LOGFILE);
StartDate = 20160101;
EndDate = 20210101;
BarPeriod = 240;
LookBack = 200;
MaxLong = 1;
MaxShort = 1;

set(PARAMETERS);
vars Close = series(priceClose());
vars Prices = series(price());
var ma_period = optimize(50,10,200,10);

BBands(Prices,50,2,2,MAType_SMA);
vars upperBand = series(rRealUpperBand);
vars lowerBand = series(rRealLowerBand);


if (crossOver(Close, upperBand)) enterLong();
else if (crossUnder(Close, lowerBand)) enterShort();


PlotWidth = 1000;
PlotHeight1 = 300;


}

Attached picture Opt01.PNG
Attached picture OPT02.PNG
Posted By: Grant

Re: Optimization Issues - 12/04/21 00:22

The ma_period variable isn't used in the trade rule.
Posted By: Sage

Re: Optimization Issues - 12/04/21 06:24

Yes that is true the ma_period variable isnt used in the trade rule, I get it now why it was not optimized.
But in reality, the ma_period affects the bands of the bollinger thereby affecting the entry and exit signals.

How can I include the ma_period variable in optimization yet excluded from the trade rules?
Posted By: MegaTanker

Re: Optimization Issues - 12/04/21 09:14

I'm not sure what you are trying to do. If you pass the ma_period to the BBands function, it will be optimized. But why would you want to exclude it from the trade rules?
Posted By: Sage

Re: Optimization Issues - 12/04/21 13:32

It was excluded from the trading rules because I want a bollinger system that enters on a breakout and exit and also reverse position on the breakout to the other side
Posted By: Grant

Re: Optimization Issues - 12/04/21 14:22

Your code makes no logical sense to me. You optimize the ma_period for no reason and your rRealUpperBand & rRealLowerBand variables have default values.
Posted By: Sage

Re: Optimization Issues - 12/04/21 14:30

I dont want the upperband and lowerband optimized. Help or not?
Posted By: Grant

Re: Optimization Issues - 12/04/21 16:47

Fair enough, but that's the reason why you get the same results
Posted By: Sage

Re: Optimization Issues - 12/04/21 20:13

Okay I will optimize the bands and feed you back
Posted By: Sage

Re: Optimization Issues - 12/07/21 01:10

I included the bands in the optimization and the issue was solved. Thanks
© 2024 lite-C Forums