Page 42 of 180
Re: Coding Help
Posted: Mon Jul 03, 2017 10:39 pm
by Newton51
I meant to illustrate what I tried....
FileWrite(handle,TimeToString(Time),iHigh(NULL,PERIOD_D1,i+1),iLow(NULL,PERIOD_D1,i+1),iClose(NULL,PERIOD_D1,i+1),iOpen(NULL,PERIOD_D1,i));
When I use this or anything similar I do not get (say) the same Daily Open value in each new H1 bar for that day/date.
Re: Coding Help
Posted: Mon Jul 03, 2017 10:43 pm
by mladen
Newton51 wrote: Mon Jul 03, 2017 10:39 pm
I meant to illustrate what I tried....
FileWrite(handle,TimeToString(Time
),iHigh(NULL,PERIOD_D1,i+1),iLow(NULL,PERIOD_D1,i+1),iClose(NULL,PERIOD_D1,i+1),iOpen(NULL,PERIOD_D1,i));
When I use this or anything similar I do not get (say) the same Daily Open value in each new H1 bar for that day/date.
Instead of using "i", use
iBarShift(NULL,PERIOD_D1,Time)
Re: Coding Help
Posted: Mon Jul 03, 2017 11:34 pm
by Newton51
mladen wrote: Mon Jul 03, 2017 10:43 pm
Instead of using "i", use
iBarShift(NULL,PERIOD_D1,Time)
mladen, I am so grateful. Thankyou.
Re: Coding Help
Posted: Tue Jul 04, 2017 11:20 am
by Newton51
I tried substituting the "i" with iBarShift(NULL, PERIOD_D1,Time) but Editor insisted on Time being an array [ ]. When I added the array, I entered "1". It compiled fine but all values over the 300 bars (several days) in the csv were identical in each respective column, except for the Date and Time (unchanged) which works correctly.
This is what compiled code was:
FileWrite(handle,TimeToString(Time),iHigh(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])),iLow(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])),iClose(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])));
I don't understand why I erred? And I am sorry to come back asking for help.
Possible to edit the line so I can't go wrong?? TIA.
Re: Coding Help
Posted: Tue Jul 04, 2017 3:52 pm
by mladen
Newton51 wrote: Tue Jul 04, 2017 11:20 am
I tried substituting the "i" with iBarShift(NULL, PERIOD_D1,Time) but Editor insisted on Time being an array [ ]. When I added the array, I entered "1". It compiled fine but all values over the 300 bars (several days) in the csv were identical in each respective column, except for the Date and Time (unchanged) which works correctly.
This is what compiled code was:
FileWrite(handle,TimeToString(Time
),iHigh(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])),iLow(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])),iClose(NULL,PERIOD_D1,iBarShift(NULL, PERIOD_D1,Time[1])));
I don't understand why I erred? And I am sorry to come back asking for help.
Possible to edit the line so I can't go wrong?? TIA.
My bad
The exact code should have been :
Code: Select all
iBarShift(NULL, PERIOD_D1,Time[i])
Re: Coding Help
Posted: Tue Jul 04, 2017 6:47 pm
by Newton51
Thanks very much mladen. I didn't use "i" because I thought that was what were avoiding. It compiles properly and seems to yield the data I am trying to get for my analysis. I have learned another new thing today. Thank you for taking the time to resolve.
Re: Coding Help
Posted: Sun Jul 09, 2017 2:02 pm
by Newton51
I feel awful asking where I am going wrong again.
I made up a screenshot showing the Code used and the csv file output, then marked up / documented in an xls.
The code I used as this:
Code: Select all
FileWrite(handle,TimeToString(Time[i]),Open[i],High[i],Low[i],Close[i],iOpen(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iHigh(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iLow(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iClose(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])));
The highlighted purple are not the same as the first bar for the new day (starting 00:00h) ad yet they are the same as desired.
The green, yellow, orange and red highlights show all else is correct. The problem is hours 0100 ~ 23:00h and only affects the BarShift related cells.
I have shown the full 24h period plus last and first bar of the previous and subsequent days. The symmetry is always the same i.e. I have not "cherry picked" an untypical day.
Have I erred or am I trying to do something intrinsically not do-able?
TIA for any critique and/or corrections.
Re: Coding Help
Posted: Sun Jul 09, 2017 3:31 pm
by mladen
Newton51 wrote: Sun Jul 09, 2017 2:02 pm
I feel awful asking where I am going wrong again.
I made up a screenshot showing the Code used and the csv file output, then marked up / documented in an xls.
The code I used as this:
Code: Select all
FileWrite(handle,TimeToString(Time[i]),Open[i],High[i],Low[i],Close[i],iOpen(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iHigh(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iLow(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])),iClose(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i+1])));
The highlighted purple are not the same as the first bar for the new day (starting 00:00h) ad yet they are the same as desired.
The green, yellow, orange and red highlights show all else is correct. The problem is hours 0100 ~ 23:00h and only affects the BarShift related cells.
I have shown the full 24h period plus last and first bar of the previous and subsequent days. The symmetry is always the same i.e. I have not "cherry picked" an untypical day.
Have I erred or am I trying to do something intrinsically not do-able?
TIA for any critique and/or corrections.
This part :
Time[i+1] in the ,iBarShift(NULL,PERIOD_D1,Time[i+1]) will get a daily bar shift of previous bar, not a previous day bar
Re: Coding Help
Posted: Sun Jul 09, 2017 4:45 pm
by Newton51
I'm sure you're right but I added the "1" because when it was simply "i" the "previous day open" was actually this day's open.
Thanks for your help and support. It is appreciated. It looks like I am trying to achieve something that is too complex. I'll abandon the project now since only manual intervention/data manipulation will work and I was trying to avoid that,
Re: Coding Help
Posted: Sun Jul 09, 2017 6:46 pm
by mladen
Newton51 wrote: Sun Jul 09, 2017 4:45 pm
I'm sure you're right but I added the "1" because when it was simply "i" the "previous day open" was actually this day's open.
Thanks for your help and support. It is appreciated. It looks like I am trying to achieve something that is too complex. I'll abandon the project now since only manual intervention/data manipulation will work and I was trying to avoid that,
If you want previous day data then use something like this
iOpen(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time
)+1)
(or iClose(), iHigh(), iLow() and the rest)