I'm trying to build a proof-of-concept code that writes an array to a file, then later read it back in. I can see that it writes something to the file, but I'm not sure if I have the length code correct. Also, trying to read it back in (and verify) does not work.
Any help on this would be appreciated. Here is a sample code:
Hi dusktrader. I don't think the sizeof is giving you what you want. Since vars is the pointer to an array of var, sizeof will only return the length of the pointer. Instead, if each var is 4 bytes and the length of your series is defaulted to LookBack, shouldn't the length be 4*LookBack?
Re: How to use the file_read/write with array
[Re: DdlV]
#440561 04/28/1410:0004/28/1410:00
Hi dusktrader. OK, I'll guess a little more! vars EquityCurve just defines EquityCurve as a pointer. Before the read I think you need to create the array and assign EquityCurve to the start of the array, which is what series does. So, in the read else add EquityCurve=series(0) before the read.
The read is going to execute on every Bar, just reloading the array every time. Do you want it to be in INITRUN? Or actually EXITRUN for your testing / proof of concept...
In read mode, the plot is going to plot the 1st value in the array at every bar, which will just be a flat line? I think you may be better off using plotGraph in a loop to specify the Bar for each equity value...
Re: How to use the file_read/write with array
[Re: DdlV]
#440587 04/28/1414:0804/28/1414:08
Thanks DdlV, I agree there should be an INITRUN in that logic, so I've added that.
I am still getting a crash when trying to read in the array (note: I'm assuming it was correctly written to the file).
I think the issue could still be the length, which I've arbitrarily set to 1000. I don't think Zorro would know the length when reading in, so I'm not sure how that would work.
plotGraph sounds neat and I might explore that (I haven't used it before) but first I need to figure out the reason for the crash.
At a first glance, the '1000' will overwrite the series and can thus cause a crash - the default LookBack is 80, sizeof(var) is 8, so a series has 80*8 = 640 bytes.
Re: How to use the file_read/write with array
[Re: jcl]
#440590 04/28/1414:3004/28/1414:30
BTW - the crash was being caused by the "1" in the plot statement - change it to "0" and no crash. No idea why... What does "1" mean for the type parameter?
Re: How to use the file_read/write with array
[Re: DdlV]
#440601 04/28/1415:1604/28/1415:16
Hmm... ok, but that plotGraph code doesn't seem to produce the EquityCurve values. That looks more like the price() series. See screenshots... the EquityCurve should be a steady downward decline like the image labelled "write".
Also, I noticed that Zorro doesn't seem to care about the size parameter in the file_read() function. I can set it to 0 and it produces the same result. Not sure if that is an issue.
I normally use 0 or 1 in plot to signify the last/main window (0) or a new window (1).
Change to EXITRUN. Doing it in INITRUN will try to plot before the chart is even started. (If it even works at all in INITRUN per jcl's comments in another thread...)