Error in code 'MarketInfo' - illegal switch expression type

 
#property copyright "EquityHedgeGraph - by transcendreamer - origins from Xupypr"
// building two equity graphs, one vs another, to seek hedge opportunities visually
// each graph may represent a single instrument or a lot-adusted basket
// spreads and swaps are not counted
// Total = Side_A - Side_B

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_level1 0

extern datetime Time_Open=D'2012.01.01 00:00';  // Âðåìÿ îäíîâðåìåííîãî îòêðûòèÿ ïîçèöèé
extern datetime Time_Close=D'2019.12.31 00:00'; // Âðåìÿ îäíîâðåìåííîãî çàêðûòèÿ ïîçèöèé
extern bool     General_Line=false; // Èñïîëüçîâàòü ãðàô.îáúåêòû - ëèíèè äëÿ óñòàíîâêè âðåìåíè îòêðûòèÿ/çàêðûòèÿ
extern double   Default_Lot=0.01;    // Ðàçìåð ëîòà ïî óìîë÷àíèþ, åñëè îí íå óêàçàí äîïîëíèòåëüíî â ïåðå÷íå ñèìâîëîâ
//--- Ïåðå÷íè ñèìâîëîâ, êîòîðûå óñëîâíî îòêðûâàþòñÿ â buy èëè â sell
//--- "Íà õâîñò" ñèìâîëó ìîæåò äîïèñûâàòüñÿ ðàçìåð ëîòà
//--- Åñëè ðàçìåð ëîòà íå äîïèñàí, ïðèìåíÿåòñÿ ëîò ïî óìîë÷àíèþ
//--- Êîëè÷åñòâî ñèìâîëîâ â ïàêåòå ïðîèçâîëüíîå
extern string   Symbols_Side_A="GBPUSD+1 GBPJPY+1";
extern string   Symbols_Side_B="EURUSD+1 EURJPY+1";
extern bool     Show_Side_A=true;   // Îòîáðàæàòü ýêâèòè ïîçèöèé ãðóïïû À
extern bool     Show_Side_B=true;  // Îòîáðàæàòü ýêâèòè ïîçèöèé ãðóïïû Á
extern bool     Show_Total=false;  // Îòîáðàæàòü ñóììàðíîå ýêâèòè

int      Total;
bool     First;
double   TotalEquity[],Equity_A[],Equity_B[];
string   ShortName;

int      OpenBar;      // íîìåð áàðà îòêðûòèÿ
int      CloseBar;     // Íîìåð áàðà çàêðûòèÿ
int      Type[];       // òèï îïåðàöèè
string   Instrument[]; // èíñòðóìåíò
double   Lots[];       // êîëè÷åñòâî ëîòîâ
double   OpenPrice[];  // öåíà îòêðûòèÿ

//+----------------------------------------------------------------------------+
//|  Custom indicator initialization function                                  |
//+----------------------------------------------------------------------------+
int init()
{
 SetIndexBuffer(0,TotalEquity);
 SetIndexLabel(0,"Total");
 SetIndexStyle(0,DRAW_LINE);
 SetIndexBuffer(1,Equity_A);
 SetIndexLabel(1,"Side A");
 SetIndexStyle(1,DRAW_LINE);
 SetIndexBuffer(2,Equity_B);
 SetIndexLabel(2,"Side B");
 SetIndexStyle(2,DRAW_LINE);
 ShortName="Equity Hedge Graph";
 //if (Show_Total) ShortName=StringConcatenate(ShortName," Total");
 //if (Show_Side_A)   ShortName=StringConcatenate(ShortName," Side A");
 //if (Show_Side_B)  ShortName=StringConcatenate(ShortName," Side B");
 IndicatorShortName(ShortName);
 //
 int Window=WindowFind(ShortName);
 ObjectCreate("EquityA",OBJ_LABEL,Window,0,0);
 ObjectSet("EquityA",OBJPROP_XDISTANCE,5);
 ObjectSet("EquityA",OBJPROP_YDISTANCE,15);
 ObjectSet("EquityA",OBJPROP_CORNER,0);
 ObjectSetText("EquityA",Symbols_Side_A,7,"Tahoma",indicator_color2);
 //
 ObjectCreate("EquityB",OBJ_LABEL,Window,0,0);
 ObjectSet("EquityB",OBJPROP_XDISTANCE,5);
 ObjectSet("EquityB",OBJPROP_YDISTANCE,25);
 ObjectSet("EquityB",OBJPROP_CORNER,0);
 ObjectSetText("EquityB",Symbols_Side_B,7,"Tahoma",indicator_color3);
 //
 IndicatorDigits(2);
 First=true;
 return(0);
}
//+----------------------------------------------------------------------------+
//|  Custom indicator iteration function                                       |
//+----------------------------------------------------------------------------+
int start()
{
 static string minfosymbols="";
 double A_profitloss,B_profitloss,lotsize;
 int bar,i,j;
/*
 if (!IsConnected())
 {
  Print("Ñâÿçü ñ ñåðâåðîì îòñóòñòâóåò èëè ïðåðâàíà");
  return(0);
 }
*/
 if (General_Line)
 {
  if (ObjectFind("openall")==-1) ObjectCreate("openall",OBJ_VLINE,0,Time_Open,0);
  if (ObjectFind("closeall")==-1) ObjectCreate("closeall",OBJ_VLINE,0,Time_Close,0);
  if (ObjectGet("openall",OBJPROP_TIME1)!=Time_Open || ObjectGet("closeall",OBJPROP_TIME1)!=Time_Close)
  {
   First=true;
   Time_Open=ObjectGet("openall",OBJPROP_TIME1);
   Time_Close=ObjectGet("closeall",OBJPROP_TIME1);
   ArrayInitialize(TotalEquity,EMPTY_VALUE);
   ArrayInitialize(Equity_A,EMPTY_VALUE);
   ArrayInitialize(Equity_B,EMPTY_VALUE);
  }
 }
 OpenBar=iBarShift(NULL,0,Time_Open);
 CloseBar=iBarShift(NULL,0,Time_Close,true);
 if (First)
 {
  First=false;
  Total=0;
  SetOrder(Symbols_Side_A,OP_BUY);
  SetOrder(Symbols_Side_B,OP_SELL);
  if (Total==0)
  {
   Alert("Íè îäíîãî ñèìâîëà íå çàäàíî!");
   return(0);
  }
 }
 else
 {
  if (Total==0) return(0);
  if (CloseBar>=0) return(0);
  else
  {
   OpenBar=1;
   CloseBar=0;
  }
 }
 for (i=OpenBar;i>=CloseBar;i--)
 {
  A_profitloss=0.0;
  B_profitloss=0.0;
  for (j=0;j<Total;j++)
  {
   if (MarketInfo(Instrument[j],MODE_POINT)==0)
   {
    if (StringFind(minfosymbols,Instrument[j])==-1)
    {
     Alert("Â îáçîðå ðûíêà íå õâàòàåò "+Instrument[j]);
     minfosymbols=StringConcatenate(minfosymbols," ",Instrument[j]);
    }
    continue;
   }
   bar=iBarShift(Instrument[j],0,Time[i]);
   lotsize=LotSize(Instrument[j],Time[i]);
   if (Type[j]==OP_BUY) A_profitloss+=(iClose(Instrument[j],0,bar)-OpenPrice[j])*Lots[j]*lotsize;
   else
   {
    //spread=MarketInfo(Instrument[j],MODE_POINT)*MarketInfo(Instrument[j],MODE_SPREAD);
    //B_profitloss+=(OpenPrice[j]-iClose(Instrument[j],0,bar)-spread)*Lots[j]*lotsize;
    B_profitloss+=(iClose(Instrument[j],0,bar)-OpenPrice[j])*Lots[j]*lotsize;
   }
  }
  if (Show_Total) TotalEquity[i]=NormalizeDouble(A_profitloss-B_profitloss,2);
  if (Show_Side_A) Equity_A[i]=NormalizeDouble(A_profitloss,2);
  if (Show_Side_B) Equity_B[i]=NormalizeDouble(B_profitloss,2);
 }
  return(0);
}
//+----------------------------------------------------------------------------+
//|  Îïðåäåëåíèå ðàçìåðà êîíòðàêòà                                             |
//+----------------------------------------------------------------------------+
double LotSize(string symbol, datetime tbar)
{
 double size;
 string BQ,currency=AccountCurrency();
 switch (MarketInfo(symbol,MODE_PROFITCALCMODE))
 {
  case 0:
  {
   int sbar=iBarShift(symbol,0,tbar);
   size=MarketInfo(symbol,MODE_LOTSIZE);
   if (StringSubstr(symbol,3,3)=="USD") break;
   if (StringSubstr(symbol,0,3)=="USD") size=size/iClose(symbol,0,sbar);
   else
   {
    BQ=StringSubstr(symbol,0,3)+"USD";
    if (iClose(BQ,0,0)==0) BQ="USD"+StringSubstr(symbol,0,3);
    if (iClose(BQ,0,0)==0) break;
    int BQbar=iBarShift(BQ,0,tbar);
    if (StringSubstr(BQ,0,3)=="USD") size=size/iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
    else size=size*iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
   }
  } break;
  case 1: size=MarketInfo(symbol,MODE_LOTSIZE); break;
  case 2: size=MarketInfo(symbol,MODE_TICKVALUE)/MarketInfo(symbol,MODE_TICKSIZE);
 }
 if (currency!="USD")
 {
  BQ=currency+"USD";
  if (iClose(BQ,0,0)==0)
  {
   BQ="USD"+currency;
   size*=iClose(BQ,0,iBarShift(BQ,0,tbar));
  }
  else size/=iClose(BQ,0,iBarShift(BQ,0,tbar));
 }
 return(size);
}
//+----------------------------------------------------------------------------+
//|  Óñòàíîâêà ïàðàìåòðîâ îðäåðà                                               |
//+----------------------------------------------------------------------------+
void SetOrder(string name, int cmd)
{
 int length,pos,end;
 
 length=StringLen(name);
 pos=0;
 while (pos<length)
 {
  Total++;
  ArrayResize(Type,Total);
  ArrayResize(Instrument,Total);
  ArrayResize(Lots,Total);
  ArrayResize(OpenPrice,Total);
  Type[Total-1]=cmd;
  Instrument[Total-1]=StringSubstr(name,pos,6);
  pos+=6;
  if (StringGetChar(name,pos)==32 || (length-1)<pos) Lots[Total-1]=Default_Lot;
  else
  {
   end=0;
   while(StringGetChar(name,pos+end)!=32)
   {
    if ((length-1)<pos+end) break;
    end++;
   }
   Lots[Total-1]=StrToDouble(StringSubstr(name,pos,pos+end));
   pos+=end;
  }
  pos++;
  OpenPrice[Total-1]=iOpen(Instrument[Total-1],0,iBarShift(Instrument[Total-1],0,Time_Open));
  //if (cmd==OP_BUY) OpenPrice[Total-1]+=MarketInfo(Instrument[Total-1],MODE_POINT)*MarketInfo(Instrument[Total-1],MODE_SPREAD);
 }
}
//+----------------------------------------------------------------------------+

Hi Dear Coders,

any one can please solve this error

'MarketInfo' - illegal switch expression type.

Files:
error.png  107 kb
 
ECURRENCY TEAM:

Dear Coders, this coding showing error

 'MarketInfo' - illegal switch expression type


please rectify this

You can try adding the (int) as switch() only works with integer type expressions

switch (MarketInfo(symbol,MODE_PROFITCALCMODE))
 {
switch ((int)MarketInfo(symbol,MODE_PROFITCALCMODE))
 {
 
 switch (MarketInfo(symbol,MODE_PROFITCALCMODE))
 {
  case 0:
  {
   int sbar=iBarShift(symbol,0,tbar);
   size=MarketInfo(symbol,MODE_LOTSIZE);
   if (StringSubstr(symbol,3,3)=="USD") break;
   if (StringSubstr(symbol,0,3)=="USD") size=size/iClose(symbol,0,sbar);
   else
   {
    BQ=StringSubstr(symbol,0,3)+"USD";
    if (iClose(BQ,0,0)==0) BQ="USD"+StringSubstr(symbol,0,3);
    if (iClose(BQ,0,0)==0) break;
    int BQbar=iBarShift(BQ,0,tbar);
    if (StringSubstr(BQ,0,3)=="USD") size=size/iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
    else size=size*iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
   }
  } break;
  case 1: size=MarketInfo(symbol,MODE_LOTSIZE); break;
  case 2: size=MarketInfo(symbol,MODE_TICKVALUE)/MarketInfo(symbol,MODE_TICKSIZE);
 }

Marketinfo returns a double.

 switch ((int)MarketInfo(symbol,MODE_PROFITCALCMODE))
 {
  case 0:
  {
   int sbar=iBarShift(symbol,0,tbar);
   size=MarketInfo(symbol,MODE_LOTSIZE);
   if (StringSubstr(symbol,3,3)=="USD") break;
   if (StringSubstr(symbol,0,3)=="USD") size=size/iClose(symbol,0,sbar);
   else
   {
    BQ=StringSubstr(symbol,0,3)+"USD";
    if (iClose(BQ,0,0)==0) BQ="USD"+StringSubstr(symbol,0,3);
    if (iClose(BQ,0,0)==0) break;
    int BQbar=iBarShift(BQ,0,tbar);
    if (StringSubstr(BQ,0,3)=="USD") size=size/iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
    else size=size*iClose(BQ,0,BQbar)/iClose(symbol,0,sbar);
   }
  } break;
  case 1: size=MarketInfo(symbol,MODE_LOTSIZE); break;
  case 2: size=MarketInfo(symbol,MODE_TICKVALUE)/MarketInfo(symbol,MODE_TICKSIZE);
 }
 
Thank you sir
 
ECURRENCY TEAM:

Why did you post this again when you had already been answered?

Double posting wastes peoples time. Do you think that Marco would have taken the time to reply if he knew that I had already given you the answer?

I will delete your other post and move the reply here.

 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. There is no MarketInfo in MT5.
              Market Info - Reference on algorithmic/automated trading language for MetaTrader 5

    Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

Reason: