Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
5 registered members (Dico, AndrewAMD, TipmyPip, NewbieZorro, Grant), 15,791 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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,024
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,024
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,024
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,024
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