[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 61

 

Dear experts, please answer the question:

MetaEditor has text files of programme creation templates. They are used by the wizard when creating a programme. In the template text the parameters of the type of the created program file are specified. There are tags between them parameters that are not displayed in the code text. But the terminal recognizes them somehow. If an Expert Advisor is created, the Start function is launched after the next tick. If an indicator is created, the Start function is launched without a tick. Where do tags and everything in them go?

 

I did two more tests to see where it all comes from:


1. I read from ini not into array of strings, but into separate variables. The result is as expected, i.e. the copying is not a value but a reference:

int    numCross=0;

string Cross_1="-", Cross_2="-", Cross_3="-";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
  string sectionName = "common";
  
  numCross = ReadIniInteger( config_path, sectionName, "numCross", 0);
  ArrayResize( CrossName, numCross);
  for (int i=0; i<numCross; i++) CrossName[i] = "-";
  
  sectionName = "cross1";
  Cross_1 = ReadIniString( config_path, sectionName, "name", "-");
  Print("init.1: Cross_1=", Cross_1);
  sectionName = "cross2";
  Cross_2 = ReadIniString( config_path, sectionName, "name", "-");
  Print("init.1: Cross_2=", Cross_2);
  sectionName = "cross3";
  Cross_3 = ReadIniString( config_path, sectionName, "name", "-");
  Print("init.1: Cross_3=", Cross_3);
  Print("init.1: read complete");

  Print("init.2: Cross_1=", Cross_1);
  Print("init.2: Cross_2=", Cross_2);
  Print("init.2: Cross_3=", Cross_3);
  Print("-------------------------------");
  
  sectionName = "cross1";
  Cross_1 = StringSubstr( ReadIniString( config_path, sectionName, "name", "-"), 0, 0);
  Print("init.3: Cross_1=", Cross_1);
  sectionName = "cross2";
  Cross_2 = StringSubstr( ReadIniString( config_path, sectionName, "name", "-"), 0, 0);
  Print("init.3: Cross_2=", Cross_2);
  sectionName = "cross3";
  Cross_3 = StringSubstr( ReadIniString( config_path, sectionName, "name", "-"), 0, 0);
  Print("init.3: Cross_3=", Cross_3);
  Print("init.3: read complete");

  Print("init.4: Cross_1=", Cross_1);
  Print("init.4: Cross_2=", Cross_2);
  Print("init.4: Cross_3=", Cross_3);

  return(0);
}


the obtained result:

2009.04.10 14:31:42 example AUDUSD,H4: init.4: Cross_3=USDJPY
2009.04.10 14:31:42 example AUDUSD,H4: init.4: Cross_2=GBPUSD
2009.04.10 14:31:42 example AUDUSD,H4: init.4: Cross_1=EURUSD
2009.04.10 14:31:42 example AUDUSD,H4: init.3: read complete
2009.04.10 14:31:42 example AUDUSD,H4: init.3: Cross_3=USDJPY
2009.04.10 14:31:42 example AUDUSD,H4: init.3: Cross_2=GBPUSD
2009.04.10 14:31:42 example AUDUSD,H4: init.3: Cross_1=EURUSD
2009.04.10 14:31:42 example AUDUSD,H4: -------------------------------
2009.04.10 14:31:42 example AUDUSD,H4: init.2: Cross_3=USDJPY
2009.04.10 14:31:42 example AUDUSD,H4: init.2: Cross_2=USDJPY
2009.04.10 14:31:42 example AUDUSD,H4: init.2: Cross_1=USDJPY

2009.04.10 14:31:42 example AUDUSD,H4: init.1: read complete
2009.04.10 14:31:42 example AUDUSD,H4: init.1: Cross_3=USDJPY
2009.04.10 14:31:42 example AUDUSD,H4: init.1: Cross_2=GBPUSD
2009.04.10 14:31:42 example AUDUSD,H4: init.1: Cross_1=EURUSD


2. returned the array of string, but instead of the function reading from the ini string values

string ReadIniString(string FileName, string SectionName, string KeyName, 
                     string Default = "")
  {
   string ReturnedString = "";
   int nValue = GetPrivateProfileStringA( SectionName, KeyName, Default, 
                                          ReturnedString, 255, FileName);
   if( nValue > 0)
       return( ReturnedString);
   else 
       return( Default);
  }

used a test function, which doesn't call anything from win api

string CrossName[];
int    numCross=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
  string sectionName = "common";
  
  numCross = ReadIniInteger( config_path, sectionName, "numCross", 0);
  ArrayResize( CrossName, numCross);
  for (int i=0; i<numCross; i++) CrossName[i] = "-";
  
  for (int i=0; i< numCross; i++)
  {
    sectionName = StringConcatenate("cross", i+1);
    CrossName[ i] = someFunc( i+1);
    Print("init.1: CrossName[", ( i+1), "]=", CrossName[ i]);
  }
  Print("init.1: read complete");
  
  for ( i=0; i< numCross; i++)
  {
    Print("init.2: CrossName[", ( i+1), "]=", CrossName[ i]);
  }
  

  Print("-------------------------------");
  for ( i=0; i< numCross; i++)
  {
    sectionName = StringConcatenate("cross", i+1);
    CrossName[ i] = StringSubstr( someFunc( i+1), 0, 0);
    Print("init.3: CrossName[", ( i+1), "]=", CrossName[ i]);
  }
  Print("init.3: read complete");
  
  for ( i=0; i< numCross; i++)
  {
    Print("init.4: CrossName[", ( i+1), "]=", CrossName[ i]);
  }

  return(0);
}
//+------------------------------------------------------------------+
string someFunc(int val)
{
  string ReturnedString = "CROSS_"+ val;
  return( ReturnedString);
}
//+------------------------------------------------------------------+

result

2009.04.10 14:41:12 example AUDUSD,H4: init.4: CrossName[3]=CROSS_3
2009.04.10 14:41:12 example AUDUSD,H4: init.4: CrossName[2]=CROSS_2
2009.04.10 14:41:12 example AUDUSD,H4: init.4: CrossName[1]=CROSS_1
2009.04.10 14:41:12 example AUDUSD,H4: init.3: read complete
2009.04.10 14:41:12 example AUDUSD,H4: init.3: CrossName[3]=CROSS_3
2009.04.10 14:41:12 example AUDUSD,H4: init.3: CrossName[2]=CROSS_2
2009.04.10 14:41:12 example AUDUSD,H4: init.3: CrossName[1]=CROSS_1
2009.04.10 14:41:12 example AUDUSD,H4: -------------------------------

2009.04.10 14:41:12 example AUDUSD,H4: init.2: CrossName[3]=CROSS_3
2009.04.10 14:41:12 example AUDUSD,H4: init.2: CrossName[2]=CROSS_2
2009.04.10 14:41:12 example AUDUSD,H4: init.2: CrossName[1]=CROSS_1
2009.04.10 14:41:12 example AUDUSD,H4: init.1: read complete
2009.04.10 14:41:12 example AUDUSD,H4: init.1: CrossName[3]=CROSS_3
2009.04.10 14:41:12 example AUDUSD,H4: init.1: CrossName[2]=CROSS_2
2009.04.10 14:41:12 example AUDUSD,H4: init.1: CrossName[1]=CROSS_1

has shown that the problem seems to be in the conversion of

LPTSTR lpReturnedString [out] A pointer to the buffer that receives the retrieved string win api of GetPrivateProfileString fi  to mql4 string.
 
xruss >> :

How should it be? Logically I was thinking to determine the ORDtype before the signal is formed. otherwise how will it be taken into account in the trading criteria. and another snag - positions are not opened even with an empty history((

Answered you in private - I think it will be more productive this way.

 
Reshetov >> :

It is much easier, not to re-invent the wheel, and take one of the ready-made Expert Advisors, trading on the martingale and see how it is already implemented.


For example, Universum 3.0.


Thank you, I completely agree-everything was invented a long time ago

 

Execution of init() function when testing EA in tester.


I want to normalize some extern variables in the init() function of the EA

and use these normalized values to call the indicator from start().

I don't want to include this normalization in start().

Will the init() function be executed every time an external variable is changed during optimization of the EA in the strategy tester?
 
begemot61 писал(а) >>

Execution of init() function when testing EA in tester.


I want to normalize some extern variables in the init() function of the EA

and use these normalized (new) values for calling the indicator from start().

I don't want to include this normalization in start().

Will the init() function be executed every time an external variable is changed during optimization of the EA in the strategy tester?

Yes, it will be

 

int start()
{
if (OrdersTotal() == 0
&& TimeDayOfWeek(TimeCurrent()) == 5
&& TimeHour(TimeCurrent()) == 12
&& TimeMinute(TimeCurrent()) == 30
&& TimeSeconds(TimeCurrent()) >= 00)
{
Alert("Тра ляля");
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"sell",999999,0,Red);
}


Can anyone tell me why an order doesn't open here? What am I doing wrong?
 
Dimoncheg писал(а) >>
Anybody have any idea why an order isn't opening here? What am I doing wrong?

Okay, this one... Gotta wait till Friday, if there's a tick within that minute, it should open.

 
Roger >> :

Okay, this one... Got to wait till Friday, if there's a tick within that minute, it should open.

>> That's the thing, I do it on Friday or any other day of the week and the alert works and the order doesn't open at all.

Reason: