Let me know how to use the TimeCurrent() function

Indicators coded by community members
Message
Author
Atsushi
Posts: 4
Joined: Mon Apr 23, 2012 3:11 am

Let me know how to use the TimeCurrent() function

#1 Postby Atsushi » Mon Apr 23, 2012 6:09 am

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: Select all

  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: Select all

  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)
Attachments
ScrenShot.jpg
Error Popup Message
ScrenShot.jpg (227.68 KiB) Viewed 22187 times

Atsushi
Posts: 4
Joined: Mon Apr 23, 2012 3:11 am

#2 Postby Atsushi » Sun Apr 29, 2012 12:54 am

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

Stonev
Posts: 204
Joined: Thu Jan 28, 2010 2:20 pm

#3 Postby Stonev » Sun Apr 29, 2012 1:05 am

Hi,
not sure about C++
I use TimeToStr function in Delphi to show time variable value:

Code: Select all

  Print ('Current Time: '+TimeToStr (TimeCurrent()));
Coding & Converting

Atsushi
Posts: 4
Joined: Mon Apr 23, 2012 3:11 am

#4 Postby Atsushi » Sun Apr 29, 2012 5:20 am

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

Stonev
Posts: 204
Joined: Thu Jan 28, 2010 2:20 pm

#5 Postby Stonev » Sun Apr 29, 2012 8:27 am

uses you mean?

Code: Select all

uses
  SysUtils,
  classes,
  graphics,
  IndicatorInterfaceUnit,
  TechnicalFunctions;
Coding & Converting

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#6 Postby KelvinHand » Wed May 09, 2012 9:23 pm

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: Select all

//---------------------------------------------------------------------------
// 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
   }
}


Atsushi
Posts: 4
Joined: Mon Apr 23, 2012 3:11 am

#7 Postby Atsushi » Tue May 15, 2012 9:33 pm

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: Select all

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);
}

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#8 Postby KelvinHand » Wed May 16, 2012 10:43 am

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.

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#9 Postby FT Support » Fri May 18, 2012 8:19 am

Guys,

Thank you for your notes, i think that it should be changed to:

Code: Select all

TDateTime TimeCurrent()
{
  if (IntrfProcsRec.TimeCurrent == NULL) return 0;
  return IntrfProcsRec.TimeCurrent(IntrfProcsRec.pTimeCurrent);
}



(i replaced "=" with "==")
Check our other product here:
http://www.forexcopier.com

Robopip
Posts: 26
Joined: Thu Jun 21, 2012 12:03 am

#10 Postby Robopip » Sun Sep 23, 2012 6:22 pm

This is still not fixed in version 2.9.3. :oops:

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);
}

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#11 Postby Terranin » Thu Oct 11, 2012 2:34 pm

What is wrong with this code?
Hasta la vista
Mike

Robopip
Posts: 26
Joined: Thu Jun 21, 2012 12:03 am

#12 Postby Robopip » Thu Oct 11, 2012 4:15 pm

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

Steven Smith
Posts: 7
Joined: Thu Jan 17, 2013 1:50 am
Location: USA

#13 Postby Steven Smith » Thu Jan 17, 2013 2:02 am

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.


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 20 guests