Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 10/15/26 08:28
Alternative to Stooq for Zorro S
by Petra. 10/14/26 07:04
Stooq now requires an API key
by cwford. 10/08/26 23:27
Purchase A8 full licence version
by jcl. 10/05/26 12:12
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (Quad, VoroneTZ), 15,518 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
JimSimons, julienp, julienper, KelleyAbbey, Yopachi
19246 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Setting up strategy parameters from a .ini file #412423
11/27/12 09:54
11/27/12 09:54
Joined: Jul 2000
Posts: 28,140
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,140
Frankfurt
Sometimes you want your strategy to read variables out of an external file. Use the file_content and sscanf functions for that:

Code:
// helper function - read a variable from a string
// with a format like "name = 12.34"
var readVar(string str,string name)
{
  float f = 0; // sscanf needs float
  string s = strstr(str,name);
  if(s) s = strstr(s,"=");
  if(s) sscanf(s+1,"%f",&f);
  return f;
}
 
function run()
{
  static var Parameter1 = 0, Parameter2 = 0;
  if(is(INITRUN)) { // read the parameters only in the first run
    string setup = file_content("Strategy\\mysetup.ini");
    if(setup) {
      Parameter1 = readVar(setup,"Parameter1");
      Parameter2 = readVar(setup,"Parameter2");
  }
}


mysetup.ini is a plain text file that contains the values of the variables, in a format like this:
Code:
Parameter1 = 123
Parameter2 = 456


Re: Setting up strategy parameters from a .ini file [Re: jcl] #412430
11/27/12 11:56
11/27/12 11:56
Joined: Feb 2012
Posts: 37
S
stevegee58 Offline
Newbie
stevegee58  Offline
Newbie
S

Joined: Feb 2012
Posts: 37
Is file_content new? I remember asking about reading files back when I was trying to write a data conversion script.

Re: Setting up strategy parameters from a .ini file [Re: stevegee58] #412434
11/27/12 12:56
11/27/12 12:56
Joined: Jul 2000
Posts: 28,140
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,140
Frankfurt
I believe it was implemented in version 0.99.


Moderated by  Petra 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1