ForexTester uses Borland Delphi time format for its functions like Time(), iTime() and others. So, if you use C++ compilers you should convert this time to C++ format.
Delphi format (TDateTime):
Delphi TDateTime is equals to double value. The integral part of a Delphi TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed.
Following are some examples of TDateTime values and their corresponding dates and times:
0 12/30/1899 12:00 am
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
C++ format (Unix format):
C++ time is an integer value that shows how many seconds passed sinse 01/01/1970.
Is there a way to select only those values for indicators like MACD as well as Ask(), Bid prices, etc, in each invocation of GetSingleTick() which correspond to the times shown on the graph for the timeframe set in the FT GUI?
I'm developing a MACD strategy, which works, but there are what appear to be false buy and sell signals which cause some problems. I think these are occuring due to jitter around MACD zero at the tick level, since GetSingleTick() seems to be called for each tick (is that correct?), rather than once every simulated 15 minutes (say) if I have my timeframe set to 15 minutes.
So, in my code, I'm looking for MACD changing from negative to positive in GetSingleTick(), to signal a buy, and I'm not always seeing all of those buy signals in the MACD graph. I think this is because the graph is set to a 15 minute timeframe, so the signals are smoothed out, compared to what's happening at the tick-level. I really want my code to respond only to the signals shown on the graph, for the selected timeframe.
I think what I'd like ideally is a GetTimeframeInterval() (or similar) to be called once every simulated 15 minutes, or whatever the timeframe is set to, synchronised with the graph, but I guess that's not currently possible?
What's the best way to synchronize your code in GetSingleTick() to make sure it selects only data for the same times as the graph is showing, for any given timeframe?
Posted: Sun Jul 14, 2013 8:29 am
by amberwine
I think I've worked out how to do this now, thanks.
I'm calling TimeCurrent() in GetSingleTick(), then using this value to work out the next expected time of interest based on the selected time-frame. So I ignore all the ticks apart from the ones that come through approx every 15 minutes, if the time-frame is set to 15 minutes. I hope this makes sense and is reasonable. If not, please let me know.
Re: How to work with time
Posted: Wed Dec 23, 2015 11:52 pm
by alpente
The function "HourOf" is not in FT2 API, nevertheless this function is used in more than one Example code in "Scripts API", and so, I think "HarriForexTester" is right. The function "HourOf" must be added to library.
HourOf is a Delphi function (*1). The type of input of the HourOf function is TDateTime that really is a double type value (*2). In VisualC++ is there the type COleDateTime that stores date and time the same way TDateTime does (*2)(*3)(*4). The function COleDateTime::GetHour is the VisualC++ equivalent for HourOf (*5).
// This is the function that does the job int HourOf(TDateTime time) // TDateTime is the same as double { COleDateTime t = COleDateTime((DATE)time); int hour = t.GetHour() return hour; }
OMG. If I ever have to convert a Delphi date to a C based Unix date again...
So, none of the presented solutions worked for me. The ATL based solution (COleDateTime) is not available in the Express editions of MSVC++.
gmtime() did not work for me. gmtime() was off by 426 days, sometimes, and other times 427 days! Was driving me nuts. Finally found the right way to do this:
#define MSecsPerDay 86400000 #define MSecsPerSec 1000 #define UnixDateDelta 25569 // Days between TDateTime basis (12/31/1899) and Unix time_t basis (1/1/1970) #define DateDelta 693594 // Days between 1/1/0001 and 12/31/1899
const float FMSecsPerDay = MSecsPerDay; const int IMSecsPerDay = MSecsPerDay;
struct TTimeStamp { int Time; // Number of milliseconds since midnight int Date; // One plus number of days since 1/1/0001 };
Terranin wrote:ForexTester uses Borland Delphi time format for its functions like Time(), iTime() and others. So, if you use C++ compilers you should convert this time to C++ format.
Delphi format (TDateTime):
Delphi TDateTime is equals to double value. The integral part of a Delphi TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed.
Following are some examples of TDateTime values and their corresponding dates and times:
0 12/30/1899 12:00 am 2.75 1/1/1900 6:00 pm -1.25 12/29/1899 6:00 am 35065 1/1/1996 12:00 am
C++ format (Unix format):
C++ time is an integer value that shows how many seconds passed sinse 01/01/1970.