Getting date and time

Questions about MultiCharts and user contributed studies.
lois77
Posts: 23
Joined: 05 Aug 2012
Has thanked: 7 times

Getting date and time

Postby lois77 » 27 Sep 2012

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.

User avatar
Henry MultiСharts
Posts: 8521
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: Getting date and time

Postby Henry MultiСharts » 28 Sep 2012

Hello lois77,

You can reference N bars ago. Plot the closing price of two bars ago:

Code: Select all

Plot1(Close[2], "Close 2 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.

lois77
Posts: 23
Joined: 05 Aug 2012
Has thanked: 7 times

Re: Getting date and time

Postby lois77 » 29 Sep 2012

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.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: Getting date and time

Postby bowlesj3 » 30 Sep 2012

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

lois77
Posts: 23
Joined: 05 Aug 2012
Has thanked: 7 times

Re: Getting date and time

Postby lois77 » 30 Sep 2012

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.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: Getting date and time

Postby bowlesj3 » 30 Sep 2012

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.

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.
viewtopic.php?f=16&t=10397
These users thanked the author bowlesj3 for the post:
lois77

lois77
Posts: 23
Joined: 05 Aug 2012
Has thanked: 7 times

Re: Getting date and time

Postby lois77 » 01 Oct 2012

Hi.

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

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: Getting date and time

Postby bowlesj3 » 01 Oct 2012

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.


Return to “MultiCharts”