make an array of series

Posted By: maxwellreturn

make an array of series - 07/21/19 15:33

hi guys is it possible obtain something like this?
Code
vars Price = series(priceClose());
var per = 50;
  int i = optimize(0,0,2,1);
vars a[3] = {
                    series(SMA(Price,per)),
                    series(EMA(Price,per)),
                   series(TEMA(Price,per))
                    };
vars Trends1 = a[i];
if(crossOver(Price,Trends1))
enterLong;
if(crossUnder(Price,Trends1))
exitLong;


obviously it goes on error frown
thanks
Posted By: AndrewAMD

Re: make an array of series - 07/21/19 15:45

Did you read the error and adjust likewise?
Posted By: maxwellreturn

Re: make an array of series - 07/21/19 16:48

yeah it give me a syntax error :
syntax error
< series(SMA(Price,per)),>.

thank you for your time andrew
Posted By: AndrewAMD

Re: make an array of series - 07/21/19 17:25

Now if you read the manual and look at the definitions of the functions SMA, EMA, and TEMA, you will learn the second argument needs to be an int rather than a var. (A var is actually a double.)
Posted By: maxwellreturn

Re: make an array of series - 07/21/19 23:10

thank you andrew you are right i ve changed in "int per = 50" but i still get the same sintax error frown

headhache
Posted By: AndrewAMD

Re: make an array of series - 07/22/19 02:47

Now here’s the other issue:

You are optimizing to select one of three series calls in an array, but you chose to call all three series in all cases? Even if it did compile, very suboptimal.

So do this:
Declare a vars, no definition, no array.
Then based on the optimize output, use an if-then statement to determine which series call goes to the vars.
Posted By: maxwellreturn

Re: make an array of series - 07/22/19 09:47

thank you andrew i get it in this way if it can help other forum's users
Code
	
vars Price = series(priceClose());
int per = 50;
int x = 3;
 int i = optimize(0,0,2,1);
 vars Trends1;
vars Trends2;
   if(i == 0) {
		Trends1 = series(SMA(Price,per));
		Trends2 = series(SMA(Price,per*x));
		}  
	else if(i ==	1) {
		Trends1 = series(EMA(Price,per));
		Trends2 = series(EMA(Price,per*x));
		}       
	else if(i ==	2) { 
	Trends1 = series(TEMA(Price,per));
	Trends2 = series(TEMA(Price,per*x));
	}    


but i still dont understand what im doing wrong in the previous array. I still get the syntax error and i tried various combination of ";","}", "," or blank spaces but nothing, still get the same error
Posted By: AndrewAMD

Re: make an array of series - 07/23/19 00:59

Originally Posted by maxwellreturn
but i still dont understand what im doing wrong in the previous array. I still get the syntax error and i tried various combination of ";","}", "," or blank spaces but nothing, still get the same error
This is probably a limitation of Lite-C. I don't think you can initialize an array with functions upon declaration.
Posted By: jcl

Re: make an array of series - 07/23/19 07:22

That's right. Arrays are initialized with constants, not with functions.
© 2020 lite-C Forums