| View previous topic :: View next topic |
| Author |
Message |
Atsushi
Joined: 23 Apr 2012 Posts: 4
|
Posted: Mon Apr 23, 2012 11:09 am Post subject: Let me know how to use the TimeCurrent() function |
|
|
Hi,
I have to create a indicator by C++ Language.
I have been troubled for execution error occurs when using the TimeCurrent() function.
I was testing with the following sample code.
Result of checking the logs from Print() function, I'm sure that Time() function is executed without any problems.
And Pop-up message is displayed when executed the TimeCurrent() function.
Please check the following sample code and Screen Shot.
Let me know how to use the TimeCurrent() function.
Do I need to obtain the latest version of the "IndicatorInterfaceUnit.h"?
| Code: | EXPORT void __stdcall Calculate(int pIndex) {
char WorkText[100];
if (pIndex == 0) {
sprintf(WorkText, "Time(pIndex)=%f", Time(pIndex));
Print(WorkText);
sprintf(WorkText, "TimeCurrent()=%f", TimeCurrent());
Print(WorkText);
}
} |
[My development environment]
Windows 7 Home Edition Premiun (Service Pack 1) 64Bit
Microsoft Visual C++ 2010 Express (Version 10.0.40219.1 SP1Rel)
[Forex Tester environment(C++)]
TechnicalFunctions.h (2011/02/10 23:23)
IndicatorInterfaceUnit.h (2011/08/27 09:02)
| Code: | I was fixing the bug in IndicatorInterfaceUnit.h.
###Before###
1678: //-----Delete all objects------------------------------------------------------
1679: void ObjectsDeleteAll(int window = 0, TObjectType ObjType = obj_AnyObject)
###After###
1678: //-----Delete all objects------------------------------------------------------
1679: void ObjectsDeleteAll(int window, TObjectType ObjType) |
| Description: |
|
| Filesize: |
227.68 KB |
| Viewed: |
6786 Time(s) |

|
|
|
| Back to top |
|
 |
Atsushi
Joined: 23 Apr 2012 Posts: 4
|
Posted: Sun Apr 29, 2012 5:54 am Post subject: |
|
|
Please help me who have programming skills.
Could you show me your sample code.
I think I should move to "Programming lessons Forum" this question.
But, I couldn't find operation for "Forum change".
Atsushi
|
|
| Back to top |
|
 |
Stonev
Joined: 28 Jan 2010 Posts: 103
|
Posted: Sun Apr 29, 2012 6:05 am Post subject: |
|
|
Hi,
not sure about C++
I use TimeToStr function in Delphi to show time variable value:
| Code: | | Print ('Current Time: '+TimeToStr (TimeCurrent())); |
_________________ Coding & Converting |
|
| Back to top |
|
 |
Atsushi
Joined: 23 Apr 2012 Posts: 4
|
Posted: Sun Apr 29, 2012 10:20 am Post subject: |
|
|
Hi, Stonev.
Thank you for your reply.
I was able to understand that you can use the TimeCurrent() function in Delphi.
I believe TimeCurrent() function is also available in C++.
I think there is some problem in my environment(Include files).
However, I can create the indicator that don't use the TimeCurrent() function.
Anyone,
Please show me your "Include Files" and "C++ Sample Code".
Atsushi
|
|
| Back to top |
|
 |
Stonev
Joined: 28 Jan 2010 Posts: 103
|
Posted: Sun Apr 29, 2012 1:27 pm Post subject: |
|
|
uses you mean?
| Code: | uses
SysUtils,
classes,
graphics,
IndicatorInterfaceUnit,
TechnicalFunctions; |
_________________ Coding & Converting |
|
| Back to top |
|
 |
KelvinHand
Joined: 02 Jan 2011 Posts: 91
|
Posted: Thu May 10, 2012 2:23 am Post subject: |
|
|
| Atsushi wrote: | Please help me who have programming skills.
Could you show me your sample code.
I think I should move to "Programming lessons Forum" this question.
But, I couldn't find operation for "Forum change".
Atsushi |
I don't see any crash problem both release n debug builds in MS VC 2010 express.
Only issue i had is i dont see any Print() out.
Sample Code.
| Code: |
//---------------------------------------------------------------------------
// Forex Tester 2 Inside Bar C++ Example Provided by Wessel
//---------------------------------------------------------------------------
#include <windows.h>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"
#define EMPTY_VALUE 0
// External variables
int insideBarSymbol = 225,
insideBarX = 0,
insideBarY = -10;
// Buffers
TIndexBuffer insideBarIndex;
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
EXPORT void __stdcall Init()
{
// define properties
IndicatorShortName("Inside Bar");
SetOutputWindow(ow_ChartWindow);
SetEmptyValue(EMPTY_VALUE);
// register options
AddSeparator("Inside Bar, Coded by WesseldR v1.0 Feb2011");
AddSeparator("Inside Bar Parameters");
RegOption("Inside Bar Symbol", ot_Integer, &insideBarSymbol);
SetOptionRange("Inside Bar Symbol", 1, 256);
RegOption("Inside Bar X-offset", ot_Integer, &insideBarX);
SetOptionRange("Inside Bar X-offset", -MaxInt, MaxInt);
RegOption("Inside Bar Y-offset", ot_Integer, &insideBarY);
SetOptionRange("Inside Bar Y-offset", -MaxInt, MaxInt);
// create buffers
insideBarIndex = CreateIndexBuffer();
IndicatorBuffers(1);
SetIndexBuffer(0, insideBarIndex);
SetIndexStyle(0, ds_Symbol, psSolid, 1, clYellow);
SetIndexSymbol(0, insideBarSymbol,insideBarX,insideBarY);
SetIndexLabel(0, "Inside Bar");
}
EXPORT void __stdcall OnParamsChange()
{
SetIndexSymbol(0,insideBarSymbol,insideBarX,insideBarY);
}
//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
EXPORT void __stdcall Calculate(int index)
{
char WorkText[100];
//if(index == 0) // We only pick completed bars
{
sprintf(WorkText, "Time(pIndex)=%f", Time(index));
Print(WorkText);
sprintf(WorkText, "TimeCurrent()=%f", TimeCurrent());
Print(WorkText);
//return;
}
double myLow = Low( index );
double myHigh = High( index );
if( Low(index+1) < myLow && High(index+1) > myHigh){
insideBarIndex[ index ] = myLow;
} else {
insideBarIndex[ index ] = EMPTY_VALUE; // We do this in case we want tick by tick indication
}
}
|
|
|
| Back to top |
|
 |
Atsushi
Joined: 23 Apr 2012 Posts: 4
|
Posted: Wed May 16, 2012 2:33 am Post subject: |
|
|
Hi KelvinHand.
Thanks your Sample Code.
And You gave me the big hint about this problem.
I was sure that there is some problem in "IndicatorInterfaceUnit.h".
Because I hear that You were not able to perform the TimeCurrent() & Print().
I found the problem in "IndicatorInterfaceUnit.h".
| Code: |
I was fixing the bug in IndicatorInterfaceUnit.h.
###Before###
//-----Get current time-------------------------------------------------------
TDateTime TimeCurrent()
{
if (IntrfProcsRec.TimeCurrent = NULL) return 0;
return IntrfProcsRec.TimeCurrent(IntrfProcsRec.pTimeCurrent);
}
###After###
//-----Get current time-------------------------------------------------------
TDateTime TimeCurrent()
{
//if (IntrfProcsRec.TimeCurrent = NULL) return 0;
return IntrfProcsRec.TimeCurrent(IntrfProcsRec.pTimeCurrent);
}
|
|
|
| Back to top |
|
 |
KelvinHand
Joined: 02 Jan 2011 Posts: 91
|
Posted: Wed May 16, 2012 3:43 pm Post subject: |
|
|
| Atsushi wrote: | Hi KelvinHand.
Thanks your Sample Code.
And You gave me the big hint about this problem.
I was sure that there is some problem in "IndicatorInterfaceUnit.h".
Because I hear that You were not able to perform the TimeCurrent() & Print().
I found the problem in "IndicatorInterfaceUnit.h".
|
Fantastic !!! You found bugs in FT2.
Salute You.
|
|
| Back to top |
|
 |
FT Support
Joined: 11 Jul 2009 Posts: 902
|
Posted: Fri May 18, 2012 1:19 pm Post subject: |
|
|
Guys,
Thank you for your notes, i think that it should be changed to:
| Code: |
TDateTime TimeCurrent()
{
if (IntrfProcsRec.TimeCurrent == NULL) return 0;
return IntrfProcsRec.TimeCurrent(IntrfProcsRec.pTimeCurrent);
}
|
(i replaced "=" with "==")
_________________ Check our other products here:
www.fx-metropolis.com
www.forexcopier.com |
|
| Back to top |
|
 |
Robopip
Joined: 21 Jun 2012 Posts: 24
|
Posted: Sun Sep 23, 2012 11:22 pm Post subject: |
|
|
This is still not fixed in version 2.9.3.
These changes needs also to be done in strategyinterfaceunit.h
EXPORT void __stdcall ReplaceStr(PChar& dest, PChar source)
{
free((void *)dest);
dest = (PChar)malloc(strlen((char*)source) + 1);
strcpy(dest, source);
Change to:
strcpy_s(dest, strlen((char*)source) + 1, source);
}
int CreateIndicator(PChar Symbol, int TimeFrame, PChar IndicatorName, PChar parameters)
{
if (IntrfProcsRec.pCreateIndicator == NULL) return 0;
PChar IndicatorNameEx = (PChar)malloc(strlen(IndicatorName) + 4 + 1);
strcpy(IndicatorNameEx, IndicatorName);
strcat(IndicatorNameEx, ".dll");
Change to:
strcpy_s(IndicatorNameEx, strlen(IndicatorName) + 4 + 1, IndicatorName);
strcat_s(IndicatorNameEx, strlen(IndicatorName) + 4 + 1, ".dll");
return rec.CreateIndicator(rec.pCreateIndicator, Symbol, TimeFrame,
IndicatorNameEx, parameters);
free(IndicatorNameEx);
}
|
|
| Back to top |
|
 |
Terranin Site Admin

Joined: 21 Oct 2006 Posts: 831
|
Posted: Thu Oct 11, 2012 7:34 pm Post subject: |
|
|
What is wrong with this code?
_________________ Hasta la vista
Mike |
|
| Back to top |
|
 |
Robopip
Joined: 21 Jun 2012 Posts: 24
|
Posted: Thu Oct 11, 2012 9:15 pm Post subject: |
|
|
| Terranin wrote: | | What is wrong with this code? |
If you mean "strcpy", you will get a warning when compiling in Visual Studio.
By changing strcpy to strcpy_s (="safe"), you will suppress warnings.
If you mean "if (IntrfProcsRec.TimeCurrent = NULL) return 0; "
It means that IntrfProcsRec.TimeCurrent is always set to NULL.
By changing to "if (IntrfProcsRec.TimeCurrent == NULL) return 0; "
It means that if IntrfProcsRec.TimeCurrent is NULL then return 0
|
|
| Back to top |
|
 |
Steven Smith
Joined: 17 Jan 2013 Posts: 7 Location: USA
|
Posted: Thu Jan 17, 2013 7:02 am Post subject: |
|
|
I agree and i was able to understand that you can use the TimeCurrent() function in Delphi.
I believe TimeCurrent() function is also available in C++.
You should be try it once.
|
|
| Back to top |
|
 |
|