Gamestudio Links
Zorro Links
Newest Posts
IBKR datasave problem
by NewbieZorro. 06/11/25 15:11
Marking Exit trades
by jcl. 06/11/25 14:02
SGT_FW
by Aku_Aku. 06/02/25 17:54
The Perfect Adventure Game
by tian. 05/27/25 04:32
ADX values
by Yogpot. 05/25/25 15:11
Transfer of Lots between Algos?
by Jack_Zodiac. 05/25/25 09:30
AUM Magazine
Latest Screens
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Zeal-X2
Who's Online Now
0 registered members (), 357 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
WardyJoubertIII, NewbieZorro, Squarei, tian, Yogpot
19139 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Difficulty in Making Series from CSV #488662
03/16/25 14:35
03/16/25 14:35
Joined: Apr 2023
Posts: 56
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

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.

Code
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.

Code
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:
Code
#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: vicknick] #488664
03/18/25 02:07
03/18/25 02:07
Joined: Feb 2017
Posts: 1,790
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,790
Chicago
Your code snippets have insufficient context.

Do you know how series() works? At every run() call, Zorro pushes back the timeseries data one spot. Now if you decide to load a CSV file at every run call and therefore overwrite the timeseries at every run call, the increment effect is nullified.

In general, remember that Zorro calls the run() function thousands of times. This has many implications.

Re: Difficulty in Making Series from CSV [Re: AndrewAMD] #488665
03/18/25 02:15
03/18/25 02:15
Joined: Apr 2023
Posts: 56
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 56
How do we able to solve this problem in this case? Since my price series is different for each run() call, so I'll have load the csv every time.

Is there any method to overcome this nullified increment effect? My first instinct is to just loop through the price series to calculate the difference.

Re: Difficulty in Making Series from CSV [Re: vicknick] #488666
03/18/25 12:29
03/18/25 12:29
Joined: Feb 2017
Posts: 1,790
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,790
Chicago
Are you running your script in Test mode or Trade mode?

If Trade mode, is the CSV different every time?

Re: Difficulty in Making Series from CSV [Re: AndrewAMD] #488667
03/19/25 00:01
03/19/25 00:01
Joined: Apr 2023
Posts: 56
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 56
In trade mode. The CSV content is different.

Re: Difficulty in Making Series from CSV [Re: vicknick] #488668
03/19/25 02:28
03/19/25 02:28
Joined: Feb 2017
Posts: 1,790
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,790
Chicago
You’re waiting until you’re in Trade mode to test your code? This is not good.

You have some troubleshooting to do. Might I offer some suggestions?

1) Test your parser in Test mode first to verify 100% that it actually works. Print the latest five entries and their timestamps to verify. Double check and triple check the documentation regarding the format string.
2) Try the dataParse() function. It has a feature where you can sort data from newest to oldest if the data is actually oldest to newest. The other related dataset functions are quite useful.

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
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

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] #488670
03/19/25 10:45
03/19/25 10:45
Joined: Apr 2008
Posts: 594
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 594
Austria
It makes only sense for loops over asset or algo to create a series inside a loop. Otherwise create it outside and shift it inside if needed. Alternatively to the automatic shifting per bar, you can use the shift() function.

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
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 56
The problem is not about shifting, but about series giving the wrong value:
Code
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:
Code
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] #488672
03/20/25 13:29
03/20/25 13:29
Joined: Apr 2008
Posts: 594
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 594
Austria
If your series prints 10,10,10, it is not shifted. And if it is not shifted, I would assume that it is a shifting problem. Your code above does not shift the series before printing.

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 Offline
Serious User
AndrewAMD  Offline
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:
Quote
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.htm

And this:
Quote
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.htm

By 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.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1