plot multiple assets

Posted By: fz5

plot multiple assets - 09/07/17 17:15


// plot price series for each asset in a separate chart

function run()
{
BarPeriod = 1440;
NumYears = 1;

int N=0;
while(asset(loop("AUD/USD","EUR/USD","GBP/USD"))) {
vars Price = series(price());
plot(strf("price_%i",N), Price, NEW, BLACK);
N++;
}
}
Posted By: fz5

Re: plot multiple assets - 09/07/17 17:22

Sorry, I submitted the above code accidentally before I typed my question. I'm testing the simple code to plot the price series for each asset in a separate chart. Somehow it only plots for the first asset. Can anyone point out what's wrong with the code? Thanks a lot!
Posted By: AndrewAMD

Re: plot multiple assets - 09/07/17 20:42

Probably because you're sending "plot" inside the asset loop.

This works, though.
Code:
// plot price series for each asset in a separate chart 

function run()
{
    set(PLOTNOW);

    BarPeriod = 1440;	
    NumYears = 1;

    vars Price[3];
    int N=0;
    string names[3];
    while(asset(loop("AUD/USD","EUR/USD","GBP/USD"))) 
    {	
        names[N] = Asset;
        Price[N] = series(price());	
        N++;	
    }

    for(N=0; N<3; N++)
    {
        plot(strf("price_%s",names[N]), Price[N], NEW, BLACK);
    }

}

Posted By: fz5

Re: plot multiple assets - 09/07/17 21:21

That works! Thank you very much!
© 2024 lite-C Forums