Help to upgrade to MetaTrader 5 without loss - page 15

 
Valmars:

...

Valery, tell me what this code section in calc.mq5 means:

...

if(StringSubstr(Symbol(), 3, 3)=="CAD") { xxx=1.2175;   }
if(StringSubstr(Symbol(), 3, 3)=="JPY") { xxx=91.425;   }
if(StringSubstr(Symbol(), 3, 3)=="CHF") { xxx=1.1631;   }
if(StringSubstr(Symbol(), 3, 3)=="AUD") { xxx=1/0.6800; }
if(StringSubstr(Symbol(), 3, 3)=="NZD") { xxx=1/0.54;   }
if(StringSubstr(Symbol(), 3, 3)=="GPB") { xxx=1/1.49;   }
if(StringSubstr(Symbol(), 3, 3)=="EUR") { xxx=1/1.3015; }

...

That is, why is the xxx variable assigned fixed values?

---

And another question. The help contains incomplete information on profit calculation for Forex, isn't it? It means that only the formula for the reverse quotes(XXXUSD) is given to calculate the profit.

Identifier

Description

Formula

SYMBOL_CALC_MODE_FOREX

Forex mode - profit and margin calculation for Forex

Margin: Lots*Contract_Size/Leverage

Profit: (close_price-open_price)*Contract_Size*Lots

Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте - Документация по MQL5
 
tol64:

And another question. It turns out that the help is incomplete with information about profit calculation for Forex? It means that the formula for profit calculation is only presented for inverse quotes(XXXUSD).

Yes, it seems that you are right. For now you can read about profit calculation in the article "The ABCs of Currency Trading".
Азбука торговли валютами - Статьи по MQL4
  • www.mql5.com
Азбука торговли валютами - Статьи по MQL4: особенности автоматических торговых стратегий
 
Rosh:
Yes, you seem to be right. For now you can read about profit calculation in the article "The ABCs of Currency Trading".

Thank you. This article should definitely be bookmarked as a cheat sheet, because I can't keep everything in my head. Better yet, if the table is added to the help, so that everything is centralized. :)

---

And fixed values (on a fresh head it is necessary to look :) ) so I have understood for a case if there was no data. But these values should be corrected all the time, depending on exchange rates. That's why it's better to output the message, that there is no data, instead of wrong values.

 
tol64: And I understood the fixed values (when fresh in the head :) ) in case there was no data. But these values should be corrected all the time depending on rate of one or another currency. That's why it's better to display a message that there is no data, rather than incorrect values.

Yes, you're absolutely right. I did as the author did, I was too lazy, I didn't have time... For cross rates in MT4 you have to explicitly select in the 'Market Watch' window the symbols for both currencies expressed in USD, i.e. For example, for NZDJPY you have to select USDJPY and NZDUSD. The author has a disclaimer on this point in the preamble:

"For XXXYYY crosses the corresponding

USDYYY or XXXUSD major pairs (for example for GPBJPY in market review window should be open

USDJPY must be open)."

In MT5 it is better to leave this to the indicator itself.

 

Piligrim:

Valery (Valmars), do you think it makes sense in terms of complexity of repackaging to offer you to re-do this indicator in MQL5 as well? The previous one, translated by you, works very well!

You cannot modify this indicator for MT5, because MT5 has no (and will never have) standalone charts. How does the indicator work in MT4? It creates a stand-alone chart with a non-standard period, with the coming of a new quote it saves it in the .hst file of this non-standard period. And then you open this chart. On every tick, the indicator updates (redraws) it with the help of the indicator dll. As a result you see a chart with a non-standard period updated in real time.

In MT5 even the format of files PERIOD.hc (on which charts for the standard periods are built) hasn't been opened by developers, probably, because they can't build "left-handed" charts. You can see the controversy about graphs with an arbitrary period here.

 
Valmars:

Yes, you're absolutely right. I did as the author did, I was too lazy, I didn't have time... For cross rates in MT4 you have to explicitly select in the 'Market Watch' window the symbols for both currencies expressed in USD, i.e. For example, for NZDJPY you have to select USDJPY and NZDUSD. The author has a disclaimer about this in the preamble:

"For XXXYYY crosses, the corresponding

major pairs USDYYY or XXXUSD (for example for GPBJPY in Market Watch window must

be open USDJPY)".

In MT5 it is better to leave this to the indicator itself.

So, instead of that list with fixed values this code would do? :

bool flgExit=false;
string arrSymbols[7]={ "CAD","JPY","CHF","AUD","NZD","GBP","EUR" };
//---
for(int i=ArraySize(arrSymbols)-1; i>=0; i--)
  {
   if(flgExit) { break; }
   //---
   if(StringSubstr(Symbol(),3,3)==arrSymbols[i])
     {
      for(int j=SymbolsTotal(false)-1; j>=0; j--)
        {
         if(SymbolName(j,false)=="USD"+arrSymbols[i]+"")
           {
            SymbolSelect("USD"+arrSymbols[i]+"",true);
            //---
            if((xxx=SymbolInfoDouble(SymbolName(j,true),SYMBOL_BID))<=0)
              {
               Comment("Ошибка ("+IntegerToString(GetLastError())+") при получении данных по символу "+SymbolName(j,true)+""); return(0);
              }
            else { flgExit=true; break; }
           }
       }
   }
}
 
Valmars:

This indicator cannot be converted to MT5, as MT5 does not (and will not) have autonomous charts. How does the indicator work in MT4? It creates a stand-alone chart with a non-standard period, with the coming of a new quote it saves it in the .hst file of this non-standard period. And then you open this chart. On every tick, the indicator updates (redraws) it with the help of the indicator dll. As a result, you will see a chart with a non-standard period updated in real time.

In MT5 even the format of PERIOD.hc files (charts for standard periods are built using) was not even disclosed by developers, probably because they don't allow making any "left-handed" charts. You can see the controversy about graphs with an arbitrary period here.

In any case thanks, Valery! For me, as a non-programmer, an understandable professional consultation is much more preferable in terms of finding possible solutions to some problem beyond my competence.

 
tol64:

So, instead of that fixed-value list, this code would work fine? :

Yes, just execute it for the second character of the cross as well and put it in the inite.

 
Valmars:
Yes, just do this for the second cross character as well and put it in the inite.

Valery, if you have a spare moment, take a look at the revised version. Is it done correctly now with everything discussed above in mind? Thank you.


Files:
 
tol64:

...

Updated the file above(calcriskprofit.mq5). Corrected the typo. Instead of GBP it was GPB. :)
Reason: