Hello all,

I'm working on a script which needs to keep an array up-to-date with multiple asset prices for further analysis. In short, my script performs 3 steps:

1. It prefetches the history (1999 bars) into an array during the 'FIRSTRUN'.
2. Each bar from the history gets shifted 1 bar back in time to make space for the last price.
3. The last prices are fetched and added to this array.

I can't make step #3 work correctly, because it's unable to fetch a more recent price than the last one from step #1.

Is there any way to solve this issue?

Thank you in advance!

Grant


Code
double PP1[2000][5];
int i, j;


function run()
	{
	History = ".t6";
	BarPeriod = 1;
	LookBack = 2000;
	set(TICKS);	

	if(is(TESTMODE)) 
		{
		StartDate = 20200101;
		}
	else
		{
		StartDate = NOW;
		}	
	
	if(is(INITRUN))
		{
	  //Sequence based most on complete price history
		asset("EUR/USD");
		asset("USD/JPY");
		asset("GBP/USD");
		asset("AUD/USD");
		asset("USD/CAD");
		}

	if(Bar < LookBack)
		{
		return;	
		}
	
  //#1) Prefetch history
	if(is(FIRSTRUN))
		{
		for(i = 1; i < LookBack; i++)
			{
		  //Sequence based most on complete price history		
			asset("EUR/USD");
			PP1[i][1] = priceClose(LookBack - i + 1);

			asset("USD/JPY");
			PP1[i][4] = priceClose(LookBack - i + 1);

			asset("GBP/USD");
			PP1[i][2] = priceClose(LookBack - i + 1);

			asset("AUD/USD");
			PP1[i][0] = priceClose(LookBack - i + 1);

			asset("USD/CAD");
			PP1[i][3] = priceClose(LookBack - i + 1);
			}							
	
		return;
		}	
	
  //#2) Shift history 1 bar back in time
	for(i = 0; i < (LookBack - 1); i++)
		{
		for(j = 0; j <= 4; j++)
			{
			PP1[i][j] = PP1[i + 1][j];
			}
		}

  //#3) Fetch latest price	
  //Sequence based most on complete price history	
	asset("EUR/USD");
	PP1[LookBack][1] = priceClose();

	asset("USD/JPY");
	PP1[LookBack][4] = priceClose();		

	asset("GBP/USD");
	PP1[LookBack][2] = priceClose();

	asset("AUD/USD");
	PP1[LookBack][0] = priceClose();
	
	asset("USD/CAD");
	PP1[LookBack][3] = priceClose();

  //Debugging
	for(i = 0; i < LookBack; i++)
		{
		for(j = 0; j <= 4; j++)
			{
			if(j < 4)
				{
				print(TO_CSV, "%.5f,", PP1[i][j]);
				}
			else
				{
				print(TO_CSV, "%.5f\n", PP1[i][j]);
				}
			}
		}
	
	printf("\nFinished");
	quit();
	}

Last edited by Grant; 09/15/21 23:07.