Passing integer variables as indicator parameters

How to create strategies and indicators
Message
Author
User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

Passing integer variables as indicator parameters

#1 Postby Tantalus » Wed Oct 17, 2007 1:06 pm

I'm trying to call an indicator (which I wrote and works fine) for use in a strategy, but I can't figure out how to call CreateIndicator using a variable for a parameter. The strategy uses period1 as an external parameter from the user, then obtains the LSMA with that period. Here's what I've tried:

Code: Select all

hLSMA1 := CreateIndicator(Currency, TimeFrame, 'LSMA', 'period1');


hLSMA1 := CreateIndicator(Currency, TimeFrame, 'LSMA', string(period1));


In the first case, I just put the variable name in as the parameter, but it said "wrong option value". In the second one, I tried to cast the integer as a string, but it gave me an access violation.

Sooo... does anyone know how to do this? All the examples show the parameters passed as numerical values, but I don't want to hardcode them in.. I want the user to be able to change the values, just like in the SMAStrategy that comes with FTPro..

Thanks.

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

#2 Postby Tantalus » Wed Oct 17, 2007 3:50 pm

Never mind... I found the answer online (strange that I couldn't find it in the Delphi help file)

IntToStr(period1)

Easy as that!!

:D

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

#3 Postby Terranin » Thu Oct 18, 2007 10:11 pm

Tantalus wrote:Never mind... I found the answer online (strange that I couldn't find it in the Delphi help file)

IntToStr(period1)

Easy as that!!

:D


It is even more easy to use format function, for example this call:
format('%.4f;%.2f;%d;%s', [var1, var2, var3, var4])

will return
1.2456;1.25;-54;asdfgh

if
var1 = 1.2456 (double)
var2 = 1.2456 (double)
var3 = -54 (integer)
var4 = asdfgh (string)

%.4f - will return float with 4 numbers after point
%d - decimal
%s - string
Hasta la vista
Mike


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 5 guests