Download MetaTrader 5

Problem with variables not created

To add comments, please log in or register
Frenchytrader
408
Frenchytrader  
Hello,



Please help me to correct the error.

EA doesn't create variables called:

GV_xAPI_Long_
         GlobalVariableSet("GV_xAPI_Long_"+name,StringToDouble(longps));

It prints Outlook has been refresh!... but I don't see them.

Also it prints: Function is not confirmed.

What function? I don't know.



So far... Only the void isn't working properly:

void CreateGVs()


Please find attach the EA




Thank you
Files:
honest_knave
Moderator
2326
honest_knave  
Frenchytrader:

EA doesn't create variables called:

GV_xAPI_Long_
         GlobalVariableSet("GV_xAPI_Long_"+name,StringToDouble(longps)); 

Have you pressed F3 to check the list of Global Variables?

Frenchytrader:

It prints Outlook has been refresh!... but I don't see them.

You need to put a print statement in the block above, to make sure the code that sets the GVs is being called e.g.

      if(GetPersent(name,longps,shortps,sData))
         {
         Print("Setting global variables");
         GlobalVariableSet("GV_xAPI_Long_"+name,StringToDouble(longps));
         GlobalVariableSet("GV_xAPI_Short_"+name,StringToDouble(shortps));
         }    
Frenchytrader
408
Frenchytrader  
Hi,


Yes I'm checking with F3.



Indeed... I have added your print test... and it doesn't print "Setting global var"

So it means the function isn't working:



//Read long/short ratio
bool GetPersent(string s,string&longps,string&shortps,string sData)
   {
   int Pair, start_, stop;
   // -------------------------------------------------
   // Parse the XML file looking for an event to report
   // -------------------------------------------------
   Pair = 0;
   Pair = StringFind(sData, s, Pair);
   if (Pair == -1)
   {
      longps = "";
      shortps = "";
      return false;  
   }    
   start_ = StringFind(sData, "<shortPercentage>", Pair);      
   start_ += 17;        
   stop = StringFind(sData, "</shortPercentage>", start_);
   shortps = StringSubstr(sData, start_, stop - start_);
  
   start_ = StringFind(sData, "<longPercentage>", Pair);        
   start_ += 16;        
   stop = StringFind(sData, "</longPercentage>", start_);
   longps = StringSubstr(sData, start_, stop - start_);  
   return true;
   }

What to do?
honest_knave
Moderator
2326
honest_knave  

Frenchytrader:


 

What to do?

Track down if GetPersent() is even called (if "limit" is 0, it won't be): 

   int limit=ArraySize(sym);
   printf("limit = %i", limit);
   for(int i=0;i<limit;i++)

If it is, track down why GetPersent() is returning false, which can only be in here:

Pair = StringFind(sData, s, Pair);

i.e. "s" is not found in "sData" 

Frenchytrader
408
Frenchytrader  
It says 28... as I should get value for 28 pairs listed:


bool GetPersent(string s,string&longps,string&shortps,string sData)
   {
   int Pair, start_, stop;
  
   int limit=ArraySize(sym);
   printf("limit = %i", limit);
   for(int i=0;i<limit;i++)
  
   // -------------------------------------------------
   // Parse the XML file looking for an event to report
   // -------------------------------------------------
   Pair = 0;
   Pair = StringFind(sData, s, Pair);
   if (Pair == -1)
   {
      longps = "";
      shortps = "";
      return false;  
   }    
   start_ = StringFind(sData, "<shortPercentage>", Pair);      
   start_ += 17;        
   stop = StringFind(sData, "</shortPercentage>", start_);
   shortps = StringSubstr(sData, start_, stop - start_);
  
   start_ = StringFind(sData, "<longPercentage>", Pair);        
   start_ += 16;        
   stop = StringFind(sData, "</longPercentage>", start_);
   longps = StringSubstr(sData, start_, stop - start_);  
   return true;
   }


Pair = external parameter:

string  pair                 =  "AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY";
honest_knave
Moderator
2326
honest_knave  
Frenchytrader:
It says 28... as I should get value for 28 pairs listed:

So as I said in my previous post, the problem is probably that "s" is not found in "sData". 

The same process as before (i.e. standard debugging...)

Print your variables and check they make sense.

Pair = 0;
Print(sData);
Print(s);

Pair = StringFind(sData, s, Pair);
Print(Pair);
honest_knave
Moderator
2326
honest_knave  
Frenchytrader:

Pair = external parameter:

string  pair                 =  "AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY";

Pair != pair

You are setting Pair = 0.. 

Frenchytrader
408
Frenchytrader  
Hi,



thank you for helping.
It's hard for me to degub something I haven't created:


I have performed the following test:

Pair = 0;
Print("sData=",sData);
Print("s",s);
Pair = StringFind(sData, s, Pair);
Print("Pair=",Pair);



Apparently: sData is empty:

2017.02.14 12:32:18.769    My-Indicator_EA_v5 EURUSD,H1: Pair=-1
2017.02.14 12:32:18.769    My-Indicator_EA_v5 EURUSD,H1: sAUDCAD
2017.02.14 12:32:18.769    My-Indicator_EA_v5 EURUSD,H1: sData=


sData comes from GrabWeb()


string URL = "http://www.
myfxbook.com/api/get-community-outlook.xml?session=XEzQS9XQ0OLAOfl56uEC144836";


string GrabWeb()
{
   string cookie=NULL,headers;
   char post[],result[];
   int res;
   ResetLastError();
   res=WebRequest("GET",URL,cookie,NULL,5000,post,0,result,headers);
   if(res==-1)Print(ErrorDescription(GetLastError()));
   return(CharArrayToString(result));
}

void CreateGVs()
   {
   //-
   string sData=GrabWeb();
   int limit=ArraySize(sym);
   for(int i=0;i<limit;i++)
      {
      string name=sym[i].name;
      string longps,shortps;
      if(GetPersent(name,longps,shortps,sData))
         {
         Print("Setting global variables");
         GlobalVariableSet("GV_xAPI_Long_"+name,StringToDouble(longps));
         GlobalVariableSet("GV_xAPI_Short_"+name,StringToDouble(shortps));
         }    
      }
    Print("Outlook has been refreshed!");
   }


I have already paremeter this way: picture attached:
Files:
honest_knave
Moderator
2326
honest_knave  

Frenchytrader:

It's hard for me to degub something I haven't created:

OK, I did wonder if you had written the original code!

No problem.

Same deal again - figure out why GrabWeb() is returning an empty string.

Are there any messages in the Experts log?

res=WebRequest("GET",URL,cookie,NULL,5000,post,0,result,headers);
if(res==-1)Print(ErrorDescription(GetLastError()));
Also, are you trying this in Strategy Tester?
honest_knave
Moderator
2326
honest_knave  

You should also adjust your code to get rid of the warnings when you compile:

void OnTick()
   {
   long Login_Verified = AccountInfoInteger(ACCOUNT_LOGIN);

 

void GVIndex_Last()
   {
datetime GV_xAPI_Index_Long_AUD_Last = GlobalVariableSet("GV_xAPI_Index_Long_AUD_Last",GlobalVariableGet("GV_xAPI_Index_Long_AUD"));
datetime GV_xAPI_Index_Long_CAD_Last = GlobalVariableSet("GV_xAPI_Index_Long_CAD_Last",GlobalVariableGet("GV_xAPI_Index_Long_CAD"));
datetime GV_xAPI_Index_Long_CHF_Last = GlobalVariableSet("GV_xAPI_Index_Long_CHF_Last",GlobalVariableGet("GV_xAPI_Index_Long_CHF"));
datetime GV_xAPI_Index_Long_EUR_Last = GlobalVariableSet("GV_xAPI_Index_Long_EUR_Last",GlobalVariableGet("GV_xAPI_Index_Long_EUR"));
datetime GV_xAPI_Index_Long_GBP_Last = GlobalVariableSet("GV_xAPI_Index_Long_GBP_Last",GlobalVariableGet("GV_xAPI_Index_Long_GBP"));
datetime GV_xAPI_Index_Long_JPY_Last = GlobalVariableSet("GV_xAPI_Index_Long_JPY_Last",GlobalVariableGet("GV_xAPI_Index_Long_JPY"));
datetime GV_xAPI_Index_Long_USD_Last = GlobalVariableSet("GV_xAPI_Index_Long_USD_Last",GlobalVariableGet("GV_xAPI_Index_Long_USD"));
datetime GV_xAPI_Index_Long_NZD_Last = GlobalVariableSet("GV_xAPI_Index_Long_NZD_Last",GlobalVariableGet("GV_xAPI_Index_Long_NZD"));
   }


 

Frenchytrader
408
Frenchytrader  
No I don't use this into Strategy tester because it's live data only.



This Print doesn't print anything.

I don't see any message into logs.



Also this code works with my laptop at home???



Why datetime? it's should be value... so double???
12
To add comments, please log in or register