Hi, Just thought that my question would complete the lessons for the future users
the delphi strategy in FT2 has similar structure of that in MT4.
FT2's delphi strategy has generally four parts:
Init, Done, Reset, and 'GetSingleTick',
MT4's strategy has 3 parts: init(), deinit(), and start().
now the question:
Where to declare the variables that are used all through the library? or in other words, where to define/declare the 'global' variables? Should a user define them immediately following the 'external' variables or inside 'GetSingleTick'?
this question would be complement to the Lesson 1's contents.
Lesson X - Where to Declare 'Global Variable's?
-
- Posts: 52
- Joined: Tue Dec 04, 2012 1:15 pm
-
- Posts: 103
- Joined: Sun Jan 02, 2011 6:05 pm
Re: Lesson X - Where to Declare 'Global Variable's?
charvo wrote:Hi, Just thought that my question would complete the lessons for the future users
the delphi strategy in FT2 has similar structure of that in MT4.
FT2's delphi strategy has generally four parts:
Init, Done, Reset, and 'GetSingleTick',
MT4's strategy has 3 parts: init(), deinit(), and start().
now the question:
Where to declare the variables that are used all through the library? or in other words, where to define/declare the 'global' variables? Should a user define them immediately following the 'external' variables or inside 'GetSingleTick'?
this question would be complement to the Lesson 1's contents.
//--- Code Sample ----
library YourAnswer;
uses
SysUtils, Classes, StrategyInterfaceUnit,
//You can create your global variables in another file and compile to .dcu can be uses by many files here
Your_Global_Variable_In_DCU;
var
//---- From Here :Your Global Variables for this file ---
// External parameters
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
period1: integer;
period2: integer;
// custom variables
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
//----To here : Your Global Variables any place you like ----
'Global' variables above all procedures and functions in your current file. can only see in the current file.
{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
end;
{-----Done strategy---------------------------------------------------------}
procedure DoneStrategy; stdcall;
begin
end;
//This global variables here only seen by procedures /functions below it, not the above
var
z: integer;
{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;
begin
end;
{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
//inside 'GetSingleTick' is global variables inside the 'GetSingleTick.
begin
procedure x;
begin
end;
function y(): integer;
begin
end;
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Re: Alex
Alex123 wrote:I have tried different time functions, but am just not able to open an order after a certain number of hours have passed after the previous order has closed. Could anyone please help?
Code: Select all
var
// global vars
tm: TDateTime;
handle: integer;
// initialize variables in ResetStrategy
tm := 0;
handle := 0;
...
// track that order is closed and store close time
if handle <> 0 then
if not(GetOrderInfo(handle, info)) then
begin
handle := 0;
tm := TimeCurrent;
end;
// if order is closed (handle = 0) check time difference
// OneHour = 1/24
if (handle = 0) and (time <> 0) then
if (TimeCurrent - tm) > OneHour*X then
begin
// open new order here and store its handle
end;
Hasta la vista
Mike
Mike
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 13 guests