Hi,
I am having trouble on how to get the date and time of a certain bar and so I would like to ask MC or someone who wants to share its knowledge, if is possible to get the Date and Time of the last bar that closed at a certain price. I don't know if I am making myself clear, but the last bar is not necessarily the real last bar.
Kind regards.
Getting date and time
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Getting date and time
Hello lois77,
You can reference N bars ago. Plot the closing price of two bars ago:
You can also use barnumber function to reference certain bar number.
If you want to get the Date and Time of the last bar that closed at a certain price you need to search for all bars that met the price condition, write their barnumbers into an array, then get the bar with the highest barnumer from the array.
You can reference N bars ago. Plot the closing price of two bars ago:
Code: Select all
Plot1(Close[2], "Close 2 bars ago");
If you want to get the Date and Time of the last bar that closed at a certain price you need to search for all bars that met the price condition, write their barnumbers into an array, then get the bar with the highest barnumer from the array.
Re: Getting date and time
Hi Henry,
Thanks for the reply.
I have a function somehow similar to Zig-Zag points that gives me the pivot points after the occurrence of some retracement on a closing basis. So, in almost instances, I only know the pivot price after some bars. I have all the pivot points stored in an array.
After registering all the bars closing prices in another array, how can I know the index of the array that corresponds to the price I want? Is there any way to search for it?
Kind regards.
Thanks for the reply.
I have a function somehow similar to Zig-Zag points that gives me the pivot points after the occurrence of some retracement on a closing basis. So, in almost instances, I only know the pivot price after some bars. I have all the pivot points stored in an array.
After registering all the bars closing prices in another array, how can I know the index of the array that corresponds to the price I want? Is there any way to search for it?
Kind regards.
Re: Getting date and time
You would use a "for loop" to search either an array or search back bar by bar for whatever the condition you are looking for. As you read all the manual (front to back as all people really should do) it will become clear as you see the examples throughout the manual. You could most likely use a "while loop" as well.
You can also search the forum for these commands. I was looking for something specific but found this.
viewtopic.php?f=1&t=10523&hilit=for+loop
You can also search the forum for these commands. I was looking for something specific but found this.
viewtopic.php?f=1&t=10523&hilit=for+loop
Re: Getting date and time
Hi Bowlesj3.
Thanks for the reply.
I think I have tried all the loops and got nothing. Maybe the code wasn't correct, which is not surprising as I am not an experienced programmer. I will try again and let you know if I achieved what I want.
Kind regards.
Thanks for the reply.
I think I have tried all the loops and got nothing. Maybe the code wasn't correct, which is not surprising as I am not an experienced programmer. I will try again and let you know if I achieved what I want.
Kind regards.
Re: Getting date and time
You need to be pretty thorough to program. Read all the manual and also read some of the tips in this thread for debugging code. You end up asking yourself "is this code doing what I think it should be doing then you put in the debugging code to find out". it is a process of elimination basically. To give you an idea, it took me 3 weeks full time to figure out one bug. I just kept debugging things to find out if it was actually doing what I thought it should be doing. At that time I had been programming about 29 years if I remember.Maybe the code wasn't correct, which is not surprising as I am not an experienced programmer. I will try again and let you know if I achieved what I want.
viewtopic.php?f=16&t=10397
Re: Getting date and time
Hi.
Finally I made some progress.
I used the "for" loop to count the bars back until the Close Bar = Pivot Price is found.
I checked the results and everything is OK. Now I will do the same for the Date.
I need to work on the "for k = 1 to 300", I guess 300 should be replaced for some variable.
Once again, thanks for your help.
Kind regards.
Finally I made some progress.
I used the "for" loop to count the bars back until the Close Bar = Pivot Price is found.
Code: Select all
arrays:
Pivpoint[](0), // this array stores all the pivot point prices
Pivtime[](0); // this array stores all the pivot point times
Value1 = LF_Pivots(RetraceTicks, SwingPrice, SwingMode); //calling custom function
if SwingMode <> SwingMode[1] then // if there is a new pivot, it will search for the
begin // bar that matches the pivot value
for k = 1 to 300
begin
if Close[k] = Pivpoint[maxindex] then
begin
y = y + 1;
array_setmaxindex(Pivtime, y);
Pivtime[y] = Time[k]; //Stores the time of the bar[k]
maxy = array_getmaxindex(Pivtime);
end;
end;
end;
plot1(Pivtime[maxy]); //to check the results
I need to work on the "for k = 1 to 300", I guess 300 should be replaced for some variable.
Once again, thanks for your help.
Kind regards.
Re: Getting date and time
Glad you got it to work. Also, I like the way you indent the code (putting the begin and end in line with the IF statement). You would put your "else" in line as well. It isn't bad when one gets use to the idea. It solves the weakness that EL has.