How to have varying Currencies through external parameters.

How to create strategies and indicators
Message
Author
forextek
Posts: 4
Joined: Sun May 29, 2016 3:33 pm

How to have varying Currencies through external parameters.

#1 Postby forextek » Tue May 31, 2016 8:34 pm

Hi,

I'm having some difficulty dealing with the pointer associated with the external parameter for currency. I'm able to easily hardcode a specific currency into the code; however, when I attempt to replace it with an external user specified currency I'm unsure how to do it. The code below is basically an extract of the code generated by your tool with an addition of the SetCurrencyAndTimeframe function I require to set the currency for the rest of the code. How can I replace the 'EURUSD" with the externally chosen currency? I've tried putting in the pointer but it doesn't compile. I've tried to substitute with a string but the internally defined currency variable is a pointer. Seems to be a very basic requirement to have code generically written to work with any currency pair, but the solution somehow still eludes me. :)

I'm currently recompiling the exact same code but changing the hardcoding for the currency each time to accommodate different currencies.

Please help. Thanks in advance.

var
// External parameters
Currency: PChar = nil;

procedure InitStrategy; stdcall;

begin
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD'); // EURUSD HARDCODED each time.
SetCurrencyAndTimeframe(Currency, PERIOD_D1);
end;

Thanks,

Tek

FX Helper
Posts: 957
Joined: Mon Apr 01, 2013 3:55 am

Re: How to have varying Currencies through external parameters.

#2 Postby FX Helper » Tue Jun 07, 2016 8:42 am

Hello

Please try to change
Currency: PChar = nil;
with
Currency: PAnsiChar = nil;

Does it help?

forextek
Posts: 4
Joined: Sun May 29, 2016 3:33 pm

Re: How to have varying Currencies through external parameters.

#3 Postby forextek » Tue Jun 07, 2016 8:49 pm

Hi,

I replaced it but I get a bunch of warnings from the compiler stating "Unsafe type for both Currency and PAnsiChar. Also when I try to run it in ForexTester2 it fails to run the program and states there is an access violation at some address.

I don't understand how this would work anyway as the ReplaceStr(Currency, 'EURUSD') is still hardcoding the currency in. I would like to use the external parameters to pick the currency. How do I do that?

Thanks,

Tek

FX Helper
Posts: 957
Joined: Mon Apr 01, 2013 3:55 am

Re: How to have varying Currencies through external parameters.

#4 Postby FX Helper » Fri Jun 10, 2016 8:47 am

Hello

Our programmer says that maybe the problem is that SetCurrencyAndTimeframe(Currency, PERIOD_D1); is placed in the InitStrategy procedure.

Please try to move SetCurrencyAndTimeframe into GetSingleTick procedure.

forextek
Posts: 4
Joined: Sun May 29, 2016 3:33 pm

Re: How to have varying Currencies through external parameters.

#5 Postby forextek » Sat Jun 11, 2016 10:41 pm

Awesome! That was it! :) Thanks for your help!


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 1 guest