|
|
SGT_FW
by Aku_Aku. 06/02/25 17:54
|
|
|
|
|
|
|
0 registered members (),
357
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Difficulty in Making Series from CSV
#488662
03/16/25 14:35
03/16/25 14:35
|
Joined: Apr 2023
Posts: 56
vicknick
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2023
Posts: 56
|
So after getting the prices from my CSV file, I am able to place the prices into the series. This series prints out the correct prices.
vars readLatestPrices(string AssetName)
{
string FilePath = strf("C:\\Users\\chu_h\\Desktop\\output\\%s.csv", AssetName);
string content = file_content(FilePath);
.....rest of the code
vars ClosePrice= series(0, 1500);
int i, idx;
for(i = 0; i < size; i++) {
idx = (head - 1 - i + 1500) % 1500;
ClosePrice[i] = Prices[idx];
}
int i;
for(i = 0; i < 10; i++) {
printf("#Prices[%d] = %.6f\n", i, ClosePrice[i]); //Prints correct latest 10 prices
}
return CloseSeries;
}
However, when I try to use this prices series to create another series, Zorro doesn't seem to go though the series, and instead it remain at the latest price.
vars Prices = readLatestPrices("GC_J"); //This gives the correct price series
vars PricesDiff = series(Prices[0] - Prices[1]); //This always give same value, for example if ClosePrice[0]-ClosePrice[1] = 10, the series will just be 10,10,10,...
// Print the 10 most recent PricesDiff
printf("\n#Asset: %s - Latest 10 PricesDiff (newest first):\n", "GC_J");
int i;
for(i = 0; i < 10; i++) {
printf("#PricesDiff[%d] = %.6f\n", i, PricesDiff[i]);
}
The resulting PricesDiff series is such: #Asset: GC_J - Latest 10 PricesDiff (newest first):
PricesDiff[0] = 10
PricesDiff[1] = 10
PricesDiff[2] = 10
PricesDiff[3] = 10
PricesDiff[4] = 10
PricesDiff[5] = 10
PricesDiff[6] = 10
PricesDiff[7] = 10
PricesDiff[8] = 10
PricesDiff[9] = 10 It only prints out the difference of the first and second element (ClosePrice[0]-ClosePrice[1]), which is 10 in this case. This is in contrast when Zorro get the price from T6, which Zorro will automatically loop through the previous series value to fill in the series. Is there a way to make Zorro loop through CloseSeries to get correct PricesDiff, instead of having to rewrite the code with "for" loop to fill the series?
Last edited by vicknick; 03/16/25 14:59.
|
|
|
Re: Difficulty in Making Series from CSV
[Re: AndrewAMD]
#488669
03/19/25 04:22
03/19/25 04:22
|
Joined: Apr 2023
Posts: 56
vicknick
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2023
Posts: 56
|
Thanks for your suggestion, but I think it's getting a bit off topic here. The CSV data has been tested to load successfully.
I just want to know if its appropriate to use for loop to create a secondary series based on a first series, since Zorro is not able to increment in this case.
Last edited by vicknick; 03/19/25 04:23.
|
|
|
Re: Difficulty in Making Series from CSV
[Re: vicknick]
#488671
03/19/25 11:13
03/19/25 11:13
|
Joined: Apr 2023
Posts: 56
vicknick
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2023
Posts: 56
|
The problem is not about shifting, but about series giving the wrong value: vars Prices = readLatestPrices("GC_J"); //This gives the correct price series
vars PricesDiff = series(Prices[0] - Prices[1]); //will just be 10,10,10,... However, if I manually loop through the Prices series to create PriceDiff, I get the correct values: vars Prices = readLatestPrices("GC_J"); //This gives the correct price series
vars PricesDiff = series(0);
int i;
for(i = 0; i < LookBack; i++) PricesDiff[i] = Prices[i] - Prices[i+1]; //will be 10, 3, -5, 4,... I think it's appropriate to do so right?
Last edited by vicknick; 03/19/25 11:25.
|
|
|
Re: Difficulty in Making Series from CSV
[Re: vicknick]
#488673
03/21/25 13:28
03/21/25 13:28
|
Joined: Feb 2017
Posts: 1,790 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,790
Chicago
|
If you're only printing out the CSV at INITRUN and not a subsequent run() call, then it's going to only give you the initial value, which in your case is 10. Verify which run() call it is by checking for is(INITRUN). If this is your first run() call, then you'll obviously have insufficient lookback. You need 11 run calls to get 10 items in a series, one for INITRUN and 10 more after that.Reconsider your usage of series() and consider when exactly run() is called. If this is a daily bar system, run() will basically be called once a day. In this case, it can be useful to use a static series with a manual shift call. From the manual: Since the LookBack value is normally only known after the INITRUN, series are allocated in the FIRSTRUN. During the INITRUN they are set to a temporary pointer and filled with the initial value. This temporary content is overwritten by the series allocation in the FIRSTRUN. Series are only valid during the session and released after the EXITRUN. https://zorro-project.com/manual/en/series.htmAnd this: At the first call of the run function, is(INITRUN) and is(FIRSTINITRUN) are true. Since price and bar data are not yet set up at that initial run before the first asset call, all price functions and indicators return 0. https://zorro-project.com/manual/en/run.htmBy the way, you cannot trade during the lookback period. If your CSV data has all of the data it needs, you can even set lookback to zero in Trade mode so that you can trade immediately.
|
|
|
|