Duplicate: Format of Date with use of AddColumn


TroughDate = Ref(Datenum(), -TroughBars(C,8,1)); 
Buy = cross( close, ema(close,9) ) ;  
Sell = cross( ema(close,9),close ) ; 

AddColumn( IIf( Buy,Trough(Close,8,1),Null),"Trough1",1.4, textColor = colorWhite, bkgndColor = colorred );
AddColumn(IIf(Buy, TroughDate,null),"Date") ;
//   The use of Trough(Close,8,1) within AddColumn as used here returns a DateNum to the Analysis Window
//   How can this code be changed so that the DateString replaces DateNum in the Analysis Window.
//   Example: 15/12/17 instead of 1171215

see this

AddColumn( DateTime(), "Date/Time", formatDateTime);

other formats can be achieved by
and AddTextColumn()

1 Like

//Thanks But this seems not to provide for a date as returned by the Trough command
.// The use of Trough(Close,8,1) within AddColumn as used here returns a DateNum to the Analysis Window
// I want to use the AddColumn feature to return the TroughDate as in the example below. not the date number
// Example: 15/12/17 instead of 1171215
// How can this code be changed so that the DateString appears in the Analaysis Window.

That was a pointer in that direction.
What is the code you used?

DateNum() and other DT functions are derived from DateTime() so I thought you'll change your approach.

Are you still Ref() the DateNum() ?

There are a couple of things you still need to get right.

Numeric DateNum() and string representation of them are very different types, so AddColumn, AddTextColumn() and the newer multi-text column() need to be used appropriately.

You won't be able to get a string in AddColumn(), its for Array types. The best it supports Is the Character but not string.

1 Like

I use a fairly large program which guide me regarding Buy AND Sell signals
The program itself works quite well but I am trying to refine it using various tests
One such test is to compare Buy signals against prior troughs AND peaks.
The Through Date is obtain using "TroughDate = Ref(Datenum(), -TroughBars(C,8,1))" which is then applied to "AddColumn(IIf(Buy, TroughDate,null),"Date") "
I run the program using Analysis AND then Explore hence the use of "AddColumn(IIf(Buy, TroughDate,null),"Date") ".
The resulting data is then pasted to Excel for further analysis.
But in doing this there are several problems.

  1. Excel cannot correctly interpret VBA DateNum.
    2.It would be much easier if the Date (dd-mm-yy) were displayed within the Analysis Window which becomes Data I use to paste into Excel
    It would be nice if this code can be made to work or must I use another way to achieve my requirement?

I've never had to use such a code but it seems to work for me.

I've tested with periodicity as Daily and running one Recent Bar of data.

dayBarsAgo = -3;
	DateTimeFormat("%d-%m-%y", LastValue( Ref( DateTime(), dayBarsAgo ))),
	"DT", 1.0, colorDefault, colorDefault,80);

Make sure dayBarsAgo gets the right number of TroughBars since the condition.

I'm assuming that date is D-M-Y


Listen, why do you again start new thread?!
This is now the 3rd thread related to same topic.

You haven't even responded here but just go on to "new" thread.

If you want DateTime then simply replace Datenum of upper post.

TroughDate = Ref(DateTime(), -TroughBars(C,8,1)); 
Buy = cross( close, ema(close,9) ) ;  
Sell = cross( ema(close,9),close ) ; 

Filter = Buy Or Sell;
//Filter = (Buy Or Sell) AND Status( "LastBarInRange" );
//Filter = Status( "LastBarInRange" );
// Or just 
//Filter = 1;

AddColumn(Trough(Close,8,1),"Trough1",1.4, textColor = colorWhite, bkgndColor = colorred );
AddColumn(TroughDate,"Date", formatDateTime) ;
1 Like

@fxshrat Man that's bad / double posting. I didn't see that one :frowning: Triple in fact :expressionless:

By the way, the code i'm trying with is to use "-" or "/", so figured its no more a number so used a string method.
As in D-M-Y or D/M/Y

1 Like

'Solved. Simply use AddtextColumn in lieu of AddColumn

Moderator comment: this is NOT a solution

That's what I Pointed to in the 2nd Post, and then again explained string vs Numeric in 4th post.

If you'll not be that attentive, ppl will not respond to you in future.

1 Like

//Thanks travick, I did read and use your suggestion. I'm just very slow to put code together and initially did not even realise AddTextCol existed. Thanks for your assistance


You are the first guy I put on ignore here. Actually you are the first guy I have ever put on ignore in any forum. Congratulations!

No response after help in three same threads but just consumption. Sorry, ignoring everything but just going on and just copy&pasting that's no go.



/* Well thanks, but you need to understand that I cannot respond to any suggestion other than with thanks without first trying it to gain whatever insight I can from it. Only then can I state my findings. Be aware than I am not proficient in programming of any language so for me it takes time to work with. Often, I go round in circles ignoring what might be obvious to others simply because I am not proficient. For the record, I am 78 years old, relatively new to this and my brain is very challenge. */

No worries mate, you're doing far better than many :slight_smile:

1 Like

It's okay @keithwt, take your time but @fxshrat 's comments above were more against the practice of starting multiple threads on same topic without responding to the solutions offered in the initial thread itself .
Infact it is a good advice in your particular case because it is more challenging and troublesome to brain if the Solutions and Discussions are scattered over multiple threads and brain struggles to process and compile scattered bits of information.

1 Like


Sorry, that's weak excuse. Age doesn't matter. Besides age is nothing bad to apologize for (and for the record everyone ages but not just you).

Also it is not about coding and whether you are new (I already know that you are new). It is about not responding and not listening to valuable advice given by me to you before.

After all you had time to start three threads with same topic (so obviously you are able use keyboard, mouse and PC in general) but you want to tell me that you can not respond to the other side of the fence in any of those threads? Also you used my response code in this new thread. So obviously it worked as in more than 90% when I post something (and remember you used DateNum() yourself in other thread!). Still, no response. The last code I posted works too as it outputs date format including several Filter options. Still, no single response. I am not stupid phone answering machine.

You want to tell me that at age 78 you are using forums for the first time (I don't believe that... See paragraph above)? And you want to tell me that at age 78 you have human interactions for the first time? I don't believe that too.


For what it is worth all posts suggesting AddTextColumn() are incorrect. Proper solution is just using DateTime() and formatDateTime in AddColumn. The one proposed already above

TroughDate = Ref(DateTime(), -TroughBars(C,8,1)); 
AddColumn( TroughDate , "Date of trough", formatDateTime );

or, instead of variable period Ref it is actually slightly faster to use ValueWhen:

TroughDate = ValueWhen( TroughBars(C,8,1) == 0, DateTime()); 
AddColumn( TroughDate , "Date of trough", formatDateTime );

As this thread is duplicate of duplicate I am closing it now.

1 Like