Dear All,
I have had a problem with optimisation of the MA crossover and would like to narrow down the optimisation report to only those scenarios where the slow moving average (days) > fast moving average (days). Currently both genetic and exhaustive optimisation list scenarios where fast moving average is for example 200 while the slow moving average is 50. Is there a piece of code which can be embedded in the script of the signal as a condition that only if slow moving average (days) > fast moving average (days) to execute trade and therefore the optimisation will automatically exclude scenarios where fast moving average is larger than slow moving average.
Many thanks for all your assistance.
Best regards,
XIKON
Optimisation
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Optimisation
Hi Xikon,
Edit: The following code would be a better solution, since it saves MultiCharts from having to calculate the variables when these aren't needed (i.e. when the strategy shouldn't trade):
You could try something like this:Is there a piece of code which can be embedded in the script of the signal as a condition that only if slow moving average (days) > fast moving average (days) to execute trade and therefore the optimisation will automatically exclude scenarios where fast moving average is larger than slow moving average.
Code: Select all
Inputs:
LengthQuickMA(50);
LengthSlowMA(200);
Variables:
quickMA(0), slowMA(0);
quickMA = Average(Close, LengthQuickMA);
slowMA = Average(Close, LengthSlowMA);
if (quickMA crosses above slowMA) and (LengthSlowMA > LengthQuickMA) then begin
Buy ("EL #1") 1 contracts next bar at market;
end;
Code: Select all
Inputs:
LengthQuickMA(50);
LengthSlowMA(200);
Variables:
quickMA(0), slowMA(0);
if (LengthSlowMA > LengthQuickMA) then begin
quickMA = Average(Close, LengthQuickMA);
slowMA = Average(Close, LengthSlowMA);
if (quickMA crosses above slowMA) and (LengthSlowMA > LengthQuickMA) then begin
Buy ("EL #1") 1 contracts next bar at market;
end;
end;
Re: Optimisation
Dear Josh,
I have tried a slight modification as MC does not recognise the function LengthslowMA for some reason so I am using FastLength, SlowLength instead. Although I can successfully compile the signal, when running optimisation still I am getting a report where some values of FastLength are larger than Slowlength. Not sure why this is happening. Would you be able to shed some light on this?
Many thanks for your assistance.
Best regards,
XIKON
I have tried a slight modification as MC does not recognise the function LengthslowMA for some reason so I am using FastLength, SlowLength instead. Although I can successfully compile the signal, when running optimisation still I am getting a report where some values of FastLength are larger than Slowlength. Not sure why this is happening. Would you be able to shed some light on this?
Code: Select all
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: var0( 0 ), var1( 0 ) ;
var0 = XAverage( Price, FastLength );
var1 = XAverage( Price, SlowLength ) ;
condition1 = ( SlowLength > FastLength );
condition2 = Date > ELDate (02, 01, 1984) and Date < ELDate (12, 31, 2011);
condition3 = CurrentBar > 1 and var0 crosses over var1 ;
condition4 = Currentbar > 1 and var0 crosses under var1 ;
condition5 = Date = ELDate (12, 30, 2011) ;
if condition1 then begin
if condition2 then begin
if condition3 then Buy ( "XIKON XMA2CrossLE" ) next bar at market;
if condition4 then Sellshort ( "XIKON XMA2CrossSE" ) next bar at market;
end;
if condition5 then setexitonclose;
end;
Best regards,
XIKON
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Optimisation
No problems here - the optimization variants where FastLength is greater than SlowLength generate no trades:Although I can successfully compile the signal, when running optimisation still I am getting a report where some values of FastLength are larger than Slowlength. Not sure why this is happening. Would you be able to shed some light on this?
Code: Select all
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: var0( 0 ), var1( 0 ) ;
if (SlowLength > FastLength) then begin
var0 = XAverage( Price, FastLength );
var1 = XAverage( Price, SlowLength ) ;
condition2 = Date > ELDate (02, 01, 1984) and Date < ELDate (12, 31, 2011);
condition3 = CurrentBar > 1 and var0 crosses over var1 ;
condition4 = Currentbar > 1 and var0 crosses under var1 ;
condition5 = Date = ELDate (12, 30, 2011) ;
if (condition2 = true) and (condition3 = true) then
Buy ( "XIKON XMA2CrossLE" ) next bar at market;
if (condition4 = true)
then Sellshort ( "XIKON XMA2CrossSE" ) next bar at market;
if condition5 then
setexitonclose;
end;
- Attachments
-
- scr.06-03-2012 18.23.17.png
- (46.12 KiB) Downloaded 337 times
Re: Optimisation
Hi Josh,
Many thanks. I think I had completely switched off and purely scrolling to the last column without taking notice of all those zero values. I was expecting them not to come up on the optimisation report at all so was ignoring anything in the previous columns.
Thanks a lot for pointing this out.
Best regards,
XIKON
Many thanks. I think I had completely switched off and purely scrolling to the last column without taking notice of all those zero values. I was expecting them not to come up on the optimisation report at all so was ignoring anything in the previous columns.
Thanks a lot for pointing this out.
Best regards,
XIKON