Rotational system (Differents ROC for each Wachtlist)

I am setting up a system in AMI that really is quite simple, but when it comes to join it, I have doubts in the code. I explain to you to see if there is luck:

  1. I need to calculate differents Wachtlist with differents ROC periods and the same SMA.
  2. After that, ranking the TOP10 for buy in a monthly rotational systmem.

Here my poor code with errors, i don't know to continue validate...

///////////////TRADING SYSTEM PARAMETERS

//Parametros and Setup of rotacional
SetBacktestMode(backtestRotational); //Se activa el backtes rotational
SetOption( "InitialEquity", 50000 ); 
SetOption("CommissionMode", 2); 
SetOption("CommissionAmount", 7);
SetOption( "AllowPositionShrinking", True );
SetOption("WorstRankHeld", 1); 
SetOption("MaxOpenPositions", 10 ); 
PositionSize=-100/10;




///////////////OPTIMIZACION VARIABLES ROC and SMA
//I need calculate a differents ROC for each wachtlist, inside batch of ETFs. After that raking the top 10 for buy.

if(InWatchList(602))
{ROC1periodo=Optimize("ROC1periodo",1,1,20,1);
ROC1= ROC(C,ROC1periodo);}//OPTIMIZACION GRUPO ETFs EQUITY USA

if(InWatchList(603))
{ROC2=Optimize("ROC2",1,1,20,1);
ROC2= ROC(C,ROC2periodo);}//OPTIMIZACION GRUPO ETFs SECTORES USA

if(InWatchList(605))
{ROC3=Optimize("ROC3",1,1,20,1);
ROC3= ROC(C,ROC3periodo);}//OPTIMIZACION GRUPO ETFs COMODITY

if(InWatchList(606))
{ROC4=Optimize("ROC4",1,1,20,1);
ROC4= ROC(C,ROC4periodo);}//OPTIMIZACION GRUPO ETFs BOND_Fixed income

if(InWatchList(607))
{ROC5=Optimize("ROC5",1,1,20,1);
ROC5= ROC(C,ROC5periodo);}//OPTIMIZACION GRUPO ETFs REAL ESTATE

if(InWatchList(603))
{ROC6=Optimize("ROC6",1,1,20,1);
ROC6= ROC(C,ROC6periodo);}//OPTIMIZACION GRUPO ETFs EQUITY EX-USA

Momentum=ROC1=ROC2=ROC3=ROC4=ROC5=ROC6;

///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo= Optimize("SMA Periodo",1,1,20,1);
SMA7= MA(C,SMAPeriodo); //Variable la media simple del precio de ciere


///////////////BUY CRITERIA
//Average medium simple sloping up
SMA7_UP=SMA7>(Ref(SMA7,-1));//Calculo media ascendente
SMA7_OK=IIf(SMA7_UP,1,0); //Para seƱalar en el explorer 1=media ascendente, 0=madia no ascendente

OCEAN=Momentum AND SMA7_UP;

// Monthly change criteria
EndofMonth  = Month() != Ref( Month(), 1 ) ;
isRebalance = EndofMonth ;

// Ranking top 10 and calculate
PositionScore= IIf(isRebalance  , OCEAN, scoreNoRotate);

////////////EXPLORER
 Filter = Momentum AND SMA_OK
 AddColumn(Momemtum,"Momemtum",1.3);
 AddColumn(SMA_OK,"SMA_OK",1.3,IIf( SMA7==1, colorGreen, colorRed);
 SetSortColumns( 1 ); //sort by 1st column in increasing order

Hi to every one!

I'm finished with a system, and I get a series of codes wrong, could you help me?

-1 Parametization OK

-2 Initialization of variables Ok

-3 Calculation of different ROC and SMA value to the set of 5 Watchlist: I think I'm not doing it right.

-4 Collect all the ROC and SMA results from all the watchlists and make a purchase position score of the 10 best ROCs: I think I'm not doing well.

-5 Explorer: Add column number of 10 position, Add ROC organized by the top 10 of the 5 wachtlist I choose, Add column 1 = SMA> (SMA-1), 0 = SMA <(SMA-1)

Here the code:

///////////////TRADING SYSTEM PARAMETERS

//Parametros and Setup of rotacional
SetBacktestMode(backtestRotational); //Se activa el backtes rotational
SetOption( "InitialEquity", 50000 ); 
SetOption("CommissionMode", 2); 
SetOption("CommissionAmount", 7);
SetOption( "AllowPositionShrinking", True );
SetOption("WorstRankHeld", 1); 
SetOption("MaxOpenPositions", 10 ); 
PositionSize=-100/10;

//Time frame
TimeFrameSet(inMonthly);


///////////////OPTIMIZACION VARIABLES ROC
//I need calculate a differents ROC for each wachtlist, inside batch of ETFs. After that raking the top 10 for buy.

ROC1periodo=Optimize("ROC1n",3,1,20,1);
ROC1= ROC(C,ROC1periodo);
Momentum1 = 100+ROC1;

ROC2periodo=Optimize("ROC2n",3,1,20,1);
ROC2= ROC(C,ROC2periodo);
Momentum2 = 100+ROC2;

ROC3periodo=Optimize("ROC3n",9,1,20,1);
ROC3= ROC(C,ROC3periodo);
Momentum3 = 100+ROC3;

ROC4periodo=Optimize("ROC4n",9,1,20,1);
ROC4= ROC(C,ROC4periodo);
Momentum4 = 100+ROC4;

ROC5periodo=Optimize("ROC5n",12,1,20,1);
ROC5= ROC(C,ROC5periodo);
Momentum5 = 100+ROC5;

ROC6periodo=Optimize("ROC6n",3,1,20,1);
ROC6= ROC(C,ROC6periodo);
Momentum6 = 100+ROC6;

///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo= Optimize("SMA Periodo",7,1,20,1);
SMA7= MA(C,SMAPeriodo); //Variable sma of montly close period

SMA7_UP=SMA7>(Ref(SMA7,-1));//calculate SMA sloping up
SMA7_OK=IIf(SMA7_UP,1,0); //to ssigment  in  explorer 1=SMA sloping up, 0=SMA no sloping down



///////////////RESEARCH WACHTLIST AND ASSIGMENT ROC

if(InWatchList(602))
{Momentum1;}//OPTIMIZACION GRUPO ETFs EQUITY USA

if(InWatchList(603))
{Momentum2;}//OPTIMIZACION GRUPO ETFs SECTORES USA

if(InWatchList(605))
{Momentum3;}//OPTIMIZACION GRUPO ETFs COMODITY

if(InWatchList(606))
{Momentum4;}//OPTIMIZACION GRUPO ETFs BOND_Fixed income

if(InWatchList(607))
{Momentum5;}//OPTIMIZACION GRUPO ETFs REAL ESTATE

if(InWatchList(603))
{Momentum6;}//OPTIMIZACION GRUPO ETFs EQUITY EX-USA

Momentum_OK= Momentum1 AND Momentum2 AND Momentum3 AND Momentum4 AND Momentum5 AND Momentum6;



///////////////BUY CRITERIA
//Momentum and Average medium simple sloping up
Ocean= Momentum_OK AND SMA7_OK;

// Monthly change criteria
EndofMonth  = Month() != Ref( Month(), 1 ) ;
isRebalance = EndofMonth ;

// Ranking top 10 and calculate
PositionScore= IIf(isRebalance  , Ocean, scoreNoRotate);

////////////EXPLORER
 Filter =1;
 AddColumn(momentum_OK,"ROC",1.3);
 AddColumn(SMA7_OK,"SMA 7",1.3, IIf( SMA7_OK==1, colorGreen, colorRed));
 SetSortColumns( 1 ); //sort by 1st column in increasing order

Two ideas you can try::

  1. "SetBacktestMode(backtestRotational)" means that you want Amibroker to make the portfolio rotation. Then you only have to set "Monthly" periodicity in "General" tab of "Analysis Settings". I think that "TimeFrameSet" is not appropiate to do this, and you don't need to do it manually (with EndOfMonth, IsRebalance)
  2. The only difference between your six WatchList ifs the optimization's default value. You can simplify your code like this:
///////////////TRADING SYSTEM PARAMETERS

//Parametros and Setup of rotacional
SetBacktestMode(backtestRotational); //Se activa el backtest rotacional
SetOption( "InitialEquity", 50000);
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 7);
SetOption( "AllowPositionShrinking", True);
SetOption("WorstRankHeld", 1);

NumPosiciones = 10;
SetOption("MaxOpenPositions", NumPosiciones);
PositionSize = -100/NumPosiciones;


///////////////OPTIMIZACION VARIABLES ROC
//I need calculate a differents ROC for each wachtlist, inside batch of ETFs. After that raking the top 10 for buy.

///////////////RESEARCH WACHTLIST AND ASSIGMENT ROC

// OPTIMIZACIƓN EN FUNCIƓN DE LA WATCHLIST

defROCperiodo = 3;  // Default value

// Ajusto el valor en funciĆ³n de la WatchList
if(InWatchList(602)) defROCperiodo = 3;  // ETFs EQUITY USA
if(InWatchList(603)) defROCperiodo = 3;  // ETFs SECTORES USA
if(InWatchList(605)) defROCperiodo = 9;  // ETFs COMODITY
if(InWatchList(606)) defROCperiodo = 9;  // ETFs BOND_Fixed income
if(InWatchList(607)) defROCperiodo = 12;  // ETFs REAL ESTATE
if(InWatchList(603)) defROCperiodo = 3;  // ETFs EQUITY EX-USA


ROCperiodo = Optimize("Periodo ROC", defROCperiodo, 1, 20, 1);
ROCValue = ROC(C, ROCperiodo);
MomentumScore = 100 + ROCValue;


///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo = Optimize("SMA Periodo", 7, 1, 20, 1);
SMA7 = MA(C, SMAPeriodo); //Variable sma of montly close period

SMA7_UP = SMA7>(Ref(SMA7,-1));//calculate SMA sloping up
//SMA7_OK = IIf(SMA7_UP,1,0); //to ssigment  in  explorer 1=SMA sloping up, 0=SMA no sloping down


// Ranking top 10 and calculate
PositionScore = IIf(SMA7_UP, MomentumScore, scoreNoRotate);

////////////EXPLORER
 Filter = 1;
 AddColumn(Momentum_OK,"ROC",1.3);
 AddColumn(SMA7_OK,"SMA 7",1.3, IIf( SMA7_OK==1, colorGreen, colorRed));
 SetSortColumns( 1 ); //sort by 1st column in increasing order

In the "PositionScore" assignment I've supposed that you only want to rebalance your portfolio if SMA7_UP if true...
May be I'm wrong, but hope this ideas help you...

Hi LeoCV

Thanks very much for your help, it is great value for my.

  1. OPITMIZATION: How can I optimize independtly ROC now with your code? because there is just one at the end, and i need find the best one, for each wachtlist. CAnyou explain me how is works your formula "defROCperiodo=3"?

  2. BUY AND SELL: Buy the top 10 ranking ROC and SMA7_OK=1, But not entry SMA7_OK=0.
    ej. if the next month there is one in the top 10 ROC but SMA7_OK is =0 this ticker is sold or if is new is not to buy, and then the portafolio is 9
    How can write that for backtest code and explorer (with correct columms)?

// OPTIMIZACIƓN EN FUNCIƓN DE LA WATCHLIST

defROCperiodo = 3;  // Default value

// Ajusto el valor en funciĆ³n de la WatchList
if(InWatchList(602)) defROCperiodo = 3;  // ETFs EQUITY USA
if(InWatchList(603)) defROCperiodo = 3;  // ETFs SECTORES USA
if(InWatchList(605)) defROCperiodo = 9;  // ETFs COMODITY
if(InWatchList(606)) defROCperiodo = 9;  // ETFs BOND_Fixed income
if(InWatchList(607)) defROCperiodo = 12;  // ETFs REAL ESTATE
if(InWatchList(603)) defROCperiodo = 3;  // ETFs EQUITY EX-USA


ROCperiodo = Optimize("Periodo ROC", defROCperiodo, 1, 20, 1);
ROCValue = ROC(C, ROCperiodo);
MomentumScore = 100 + ROCValue;


///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo = Optimize("SMA Periodo", 7, 1, 20, 1);
SMA7 = MA(C, SMAPeriodo); //Variable sma of montly close period

SMA7_UP = SMA7>(Ref(SMA7,-1));//calculate SMA sloping up
//SMA7_OK = IIf(SMA7_UP,1,0); //to ssigment  in  explorer 1=SMA sloping up, 0=SMA no sloping down


// Ranking top 10 and calculate
PositionScore = IIf(SMA7_UP, MomentumScore, scoreNoRotate);`

```
  1. If you are not using a WatchList between 602 and 607 the variable defROCperiodo will be unassigned. The line "defROCperiodo = 3" solves this problem. By the way: you are using the same code (603) for "ETFs SECTORES USA" and "ETFs EQUITY EX-USA". May be one of it should be 604?

  2. I suppose that you are doing the optimization of the code SIX times, one for each watchlist. The line:

ROCperiodo = Optimize("Periodo ROC", defROCperiodo, 1, 20, 1);

ensures that this test is done the six times with the same parameters ("Periodo ROC" between 1 and 20, in steps of 1). Once you select the optimal value for every WatchList, you should change the assigment of the corresponding line. For example, if the optional value for WatchList 605 is 8, then you should change

if(InWatchList(605)) defROCperiodo = 9;

to

if(InWatchList(605)) defROCperiodo = 8;

Note that the parameter "defROCperiodo" in the function "Optimize" is not used in this step (Optimization).

Once you have the six optimized values of defROCperiodo, I suppose that you'd like to test them with the "Backtest" button. Now Amibroker will use only the second parameter of the "Optimize" function ("defROCperiodo"). During backtesting, the line

ROCperiodo = Optimize("Periodo ROC", defROCperiodo, 1, 20, 1);

is "equivalent" to:

ROCperiodo = defROCperiodo;
  1. You wants to buy a maximum of 10 values. This is controlled with the line:
NumPosiciones = 10;
SetOption("MaxOpenPositions", NumPosiciones);

But Amibroker will buy an ETF only if the associated score is not equal to 0.

If you don't want to buy an ETF if SMA7_UP=False, I think that then you should ensure to set PositionScore=0 in this situation, changing:

PositionScore = IIf(SMA7_UP, MomentumScore, scoreNoRotate);

to

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

DISCLAIMER: Don't assume that everything I've said is true. I'm not an Amibroker expert!!!

  1. Yes it is mistake, the wachtlist is (608). Sorry.

  2. I can't understand how optimatize as you told without runing the "optimize" button.
    Can you explain me step by step 6 six times for optimize? (Apologize but your way for optimize is the first time that i saw it, i'm sure is easy).

  3. If we make that kind of optimize(as you said), after that, if we want run a "walkforward", how can we analize each ROC... becouse just we have 1 variable of ROC and not 6 variables. so is dificult study if the system is robust. isn't it?

///////////////TRADING SYSTEM PARAMETERS

//Parametros and Setup of rotacional
SetBacktestMode(backtestRotational); //Se activa el backtes rotational
SetOption( "InitialEquity", 50000 ); 
SetOption("CommissionMode", 2); 
SetOption("CommissionAmount", 7);
SetOption( "AllowPositionShrinking", True );
SetOption("WorstRankHeld", 1); 
SetOption("MaxOpenPositions", 10 ); 
PositionSize=-100/10;
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice=SellPrice=close;

// OPTIMIZACIƓN EN FUNCIƓN DE LA WATCHLIST

defROCperiodo = 3;  // Default value

// Ajusto el valor en funciĆ³n de la WatchList
if(InWatchList(602)) defROCperiodo = 3;  // ETFs EQUITY USA
if(InWatchList(603)) defROCperiodo = 3;  // ETFs SECTORES USA
if(InWatchList(605)) defROCperiodo = 9;  // ETFs COMODITY
if(InWatchList(606)) defROCperiodo = 9;  // ETFs BOND_Fixed income
if(InWatchList(607)) defROCperiodo = 12;  // ETFs REAL ESTATE
if(InWatchList(608)) defROCperiodo = 3;  // ETFs EQUITY EX-USA


ROCperiodo = Optimize("Periodo ROC", defROCperiodo, 1, 20, 1);
ROCValue = ROC(C, ROCperiodo);
MomentumScore = 100 + ROCValue;


///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo = Optimize("SMA Periodo", 7, 1, 20, 1);
SMA7 = MA(C, SMAPeriodo); //Variable sma of montly close period

SMA7_UP = SMA7>(Ref(SMA7,-1));//calculate SMA sloping up
//SMA7_OK = IIf(SMA7_UP,1,0); //to ssigment  in  explorer 1=SMA sloping up, 0=SMA no sloping down


// Ranking top 10 and calculate

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

From your first post:

I've supposed that you want to test the same trading system in 6 different sets of ETFs... Maybe to invert 1/6 of your money in every one, or maybe to use all of the money with the best of them...

That's why I'm talking about doing six optimizations:

  1. Open new analysis
  2. Select "*Filter" in the "Apply to"
  3. Press "Filter" button, and select first watchlist
  4. Press "Optimize" button
  5. Select optimal values for parameters, and change it in code
  6. Press "Backtest" to check results

I repeat this steps the other 5 watchlists...

Am I missing something? May be are you trying to use the ETFs contained in then six lists at a time?

Thanks LeoCV.

After 6 times that and change the best preiods ROC of all wachtlist, already i can to run the final backtest with all ROC optimizated, isn't it?

regarding your question:

The idea of that system, is run the system in all 6 six list in the same time, and select the best 10 ROC and up SMA7 of all tickers in the 6 lists ( i have 31 tickers in total). Your code is doing that? or just is for individual wachtlist?

I need run the system in the same time for all 6 list together and select the conditions we tolk before.

Best

OK, now it's clear for me... You want to use the same formula for scoring every value:

MomentumScore = 100 + ROC(C, ROCperiodo);

But the value of ROCperiodo should be optimized independently for every watchlist...

You can try:

// Ajusto el valor en funciĆ³n de la WatchList
if(InWatchList(602)) ROCperiodo = Optimize("ROC1", 3, 1, 20, 1);  // ETFs EQUITY USA
if(InWatchList(603)) ROCperiodo = Optimize("ROC2", 3, 1, 20, 1);  // ETFs SECTORES USA
if(InWatchList(605)) ROCperiodo = Optimize("ROC3", 9, 1, 20, 1);  // ETFs COMODITY
if(InWatchList(606)) ROCperiodo = Optimize("ROC4", 9, 1, 20, 1);  // ETFs BOND_Fixed income
if(InWatchList(607)) ROCperiodo = Optimize("ROC5", 12, 1, 20, 1);  // ETFs REAL ESTATE
if(InWatchList(608)) ROCperiodo = Optimize("ROC6", 3, 1, 20, 1);  // ETFs EQUITY EX-USA

ROCValue = ROC(C, ROCperiodo);
MomentumScore = 100 + ROCValue;

This code should work if you select the six watchlists at a time in then "Filter" dialog box.
The line...

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

... will buy an ETF only if SMA7_UP = True
And then lines...

NumPosiciones = 10;
SetOption("MaxOpenPositions", NumPosiciones);
PositionSize = -100/NumPosiciones;

... ensures that there should be a maximum of 10 positions.
Could this be the solution for you?

1 Like

Amazing Leo!! That is the idea!!

I can't understant that formula (can you explaing me):

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

...Because, if the main point is ranking TOP 10, after organize just buy the SMA7_UP, so may be we'll in 6 positions to buy:

Ej:
image

By another hand:

How can i get columms in explorer like the picture?

////////////EXPLORER
 Filter =1;
 AddColumn(momentumScore,"ROC",1.3);
 AddColumn("SMA 7",1.3, IIf( SMA7_OK==1, colorGreen, colorRed));
 SetSortColumns( 1 ); //sort by 1st column in increasing order


Best

Hi Leo,
Are you spanish? can you give your email and i'll send you more information?
My email: morenossm@gmail.com

Best

Hi LeoCV,

1 . I'm validating the code we are checking and is show me 2 mistakes:
image

Do you know why?

Find attached the code:

///////////////TRADING SYSTEM PARAMETERS

//Parametros and Setup of rotacional
SetBacktestMode(backtestRotational); //Se activa el backtes rotational
SetOption( "InitialEquity", 50000 ); 
SetOption("CommissionMode", 2); 
SetOption("CommissionAmount", 7);
SetOption( "AllowPositionShrinking", True );
SetOption("WorstRankHeld", 1); 
SetOption("MaxOpenPositions", 10 ); 
PositionSize=-100/10;
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice=SellPrice=close;


// OPTIMIZACIƓN EN FUNCIƓN DE LA WATCHLIST

// Ajusto el valor en funciĆ³n de la WatchList
if(InWatchList(602)) ROCperiodo = Optimize("ROC1", 3, 1, 20, 1);  // ETFs EQUITY USA
if(InWatchList(603)) ROCperiodo = Optimize("ROC2", 3, 1, 20, 1);  // ETFs SECTORES USA
if(InWatchList(605)) ROCperiodo = Optimize("ROC3", 9, 1, 20, 1);  // ETFs COMODITY
if(InWatchList(606)) ROCperiodo = Optimize("ROC4", 9, 1, 20, 1);  // ETFs BOND_Fixed income
if(InWatchList(607)) ROCperiodo = Optimize("ROC5", 12, 1, 20, 1);  // ETFs REAL ESTATE
if(InWatchList(608)) ROCperiodo = Optimize("ROC6", 3, 1, 20, 1);  // ETFs EQUITY EX-USA

ROCValue = ROC(C, ROCperiodo);
MomentumScore = 100 + ROCValue;


///////////////OPTIMIZACION VARIABLE SMA
SMAPeriodo = Optimize("SMA Periodo", 7, 1, 20, 1);
SMA7 = MA(C, SMAPeriodo); //Variable sma of montly close period

SMA7_UP = SMA7>(Ref(SMA7,-1));//calculate SMA sloping up
SMA7_OK = IIf(SMA7_UP,1,0); //to ssigment  in  explorer 1=SMA sloping up, 0=SMA no sloping down


// Ranking top 10 and calculate

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

How about pressing F1 key in the editor when mouse is over error - this will show you HELP page with relevant error page:
http://www.amibroker.com/guide/errors/29.html

Hi Tomasz,

Thanks for you help, but i know about your notice. The point is , i donā€™t know where is the mistake becouse everything looks good.

Can you help me?

No, it doesn't. As message says your ROCperiodo is NOT defined.

It is not defined because if conditions that you used are NOT met, see: How do I debug my formula?

Secondly, Optimize() MUST NEVER be called conditionally. You can not place them in if because Optimizer runs setup phase and needs to know ALL optimization variables before optimization begins

1 Like

It seems that you are trying to code a very complex system without knowing the basics of AFL, and that's why you have so much problems.

To complement @Tomasz's answers:

  1. About the line:

PositionScore = IIf(SMA7_UP, MomentumScore, 0);

The manual (http://www.amibroker.com/guide/afl/enablerotationaltrading.html) states that: "the score of zero means no trade (exit the trade if there is already open position on given symbol)". IIf function ensures that when SMA7_UP is False, the score assigned is zero (to not trade the ETF).

  1. About the errors that you are getting: If the backtest is done on an ETF that is in no one of the watchlists, then variable ROCperiodo is not assigned a value. This leads to error 29 (ROCperiodo not initialized), and this means that the first argument of the function ROC is null (your second error).

Thanks both for your help!

Yes, i'm begginer in AFL and I'm learning a lot thanks you!

After your reply, i'm trying change some code and i'm thinks is good way, the problem is:

1.When i'm run the "optimize" AMI to get the best ROCs, it has a long time cheking all numbers, aproximatly 1 year!!!!

2.Can you help me if there is something for improve or to change?

Here the code:

///////////////OPTIMIZACION VARIABLES ROC

ROC1periodo=Optimize("ROC1",1,1,20,1);
ROCValue= ROC(C,ROC1periodo);

ROC2periodo=Optimize("ROC2",1,1,20,1);
ROCValue= ROC(C,ROC2periodo);


ROC3periodo=Optimize("ROC3",1,1,20,1);
ROCValue= ROC(C,ROC3periodo);


ROC4periodo=Optimize("ROC4",1,1,20,1);
ROCValue= ROC(C,ROC4periodo);


ROC5periodo=Optimize("ROC5",1,1,20,1);
ROCValue= ROC(C,ROC5periodo);


ROC6periodo=Optimize("ROC6",1,1,20,1);
ROCValue= ROC(C,ROC6periodo);



///////////////BUSQUEDA Y ASIGNACION

if(InWatchList(602)) ROCValue= ROC(C,ROC1periodo);//OPTIMIZACION GRUPO ETFs EQUITY USA

if(InWatchList(603)) ROCValue= ROC(C,ROC2periodo);//OPTIMIZACION GRUPO ETFs SECTORES USA

if(InWatchList(605)) ROCValue= ROC(C,ROC3periodo);//OPTIMIZACION GRUPO ETFs COMODITY

if(InWatchList(606)) ROCValue= ROC(C,ROC4periodo);//OPTIMIZACION GRUPO ETFs BOND_Fixed income

if(InWatchList(607)) ROCValue= ROC(C,ROC5periodo);//OPTIMIZACION GRUPO ETFs REAL ESTATE

if(InWatchList(603)) ROCValue= ROC(C,ROC6periodo);//OPTIMIZACION GRUPO ETFs EQUITY EX-USA


MomentumScore = 100 + ROCValue;

Try to understand what you are coding:

The line...
ROC1periodo=Optimize("ROC1",1,1,20,1);
... is telling Amibroker that you want to try 20 posible values of the variable ROC1. That is 20 simulations.

If you add a second optimization...
ROC2periodo=Optimize("ROC2",1,1,20,1);
... you are telling Amibroker that you want to test every combination of possible values of ROC1 and ROC2, i.e., Amibroker will test the 20 possible values of ROC2 for every posible value of ROC1. That is 20 x 20 = 400 simulations.

...

When you add the sixth optimization variable, Amibroker will test...
20 x 20 x 20 x 20 x 20 x 20 x 20 = 64 million simulations...
... The really impressive thing is that it will need only 1 year!

UPDATE: See also this topic: Any Amibroker optimization (render) farm out there?

Hi LEo,

Just I've finished the code and i did your advice por cut the long time for optimztion. Was greatfull!

Thanks

1 Like