Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1374

 
Andrey Sokolov:

is it a forex broker or something?

It is a BANK.
 
MakarFX:
This is BANK.

It's not clear, but okay.

They write that this is available onthe MICEX (FORTS), and Alpari also said that they have it on competitive accounts.

Perhaps with the expressions "only", "always". "never", "no one but" and the like should be more careful.

Can you tell me, in regular trading accounts, whena broker closesan open positionand then reopens it?
 
Andrey Sokolov:

It's not clear, but okay.

They write that this is available onthe MICEX (FORTS), and Alpari also said that they have it on competitive accounts.

Perhaps with the expressions "only", "always". "never", "no one but" and the like should be more careful.

Can you tell me ifthere is a situation on a regular trading account wherethe broker has closedthe open positionsand opened them again?
It is an individual situation, in Ukraine banks are required by law to close transactions in the foreign exchange market during the current day (for reporting purposes).
 
Dear Professionals. We need some help. For example we have a MACD indicator. Its structure is iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0). How can I change NULL to get calculations not for this currency pair but for another one on the same currency pair chart? I put iMACD("USDJPY",0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0), but it brings me nowhere. All calculations are null. What's wrong with it?
 
Michail_David:
Dear Professionals. I need some help. For example, we have a MACD indicator. Its structure is iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0). How can I change NULL to get calculations not for this currency pair but for another one on the same currency pair chart? I put iMACD("USDJPY",0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0), but it brings me nowhere. All calculations are null. What's wrong with it?

Is there a "USDJPY" symbol in the market overview?

 
Michail_David:
Dear Professionals. I need your help. For example, we have a MACD indicator. Its structure is iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0). How can I change NULL to get calculations not for this currency pair but for another one on the same currency pair chart? I put iMACD("USDJPY",0,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,0), but it brings me nowhere. All calculations are null. What's wrong with it?

And if you cheat like this

GBPJPYH4

//+------------------------------------------------------------------+
//|                                                 ExamplesMACD.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2020, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Moving Average Convergence/Divergence"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_color1  Silver
#property indicator_color2  Red
#property indicator_width1  2
#property indicator_width2  1
#property indicator_label1  "Examples MACD"
#property indicator_label2  "Examples Signal"
//--- input parameters
input string             InpPara="USDJPY";            // Para
input int                InpFastEMA=12;               // Fast EMA period
input int                InpSlowEMA=26;               // Slow EMA period
input int                InpSignalSMA=9;              // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];

int    ExtFastMaHandle;
int    ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for indicator subwindow label
   string short_name=StringFormat("ExamplesMACD(%d,%d,%d)",InpFastEMA,InpSlowEMA,InpSignalSMA);
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- get MA handles
   ExtFastMaHandle=iMA(InpPara,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(InpPara,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(rates_total<InpSignalSMA)
      return(0);
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtFastMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated," bars). Error ",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtSlowMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated," bars). Error ",GetLastError());
      return(0);
     }
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0)
      to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0)
         to_copy++;
     }
//--- get Fast EMA buffer
   if(IsStopped()) // checking for stop flag
      return(0);
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error ",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer
   if(IsStopped()) // checking for stop flag
      return(0);
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error ",GetLastError());
      return(0);
     }
//---
   int start;
   if(prev_calculated==0)
      start=0;
   else
      start=prev_calculated-1;
//--- calculate MACD
   for(int i=start; i<rates_total && !IsStopped(); i++)
      ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate Signal
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Alexey Viktorov:

Is the symbol "USDJPY" present in the market overview?

Yes. It is, Victor.

 
SanAlex:

and if you cheat like this.

Alex, it won't work. The indicator is supposed to draw two MACDs simultaneously for two currency pairs. However, with this code it is getting impossibly bloated. I also want to add calculation of correlation. But thanks for the tip on how the currency pair should be specified.

 

If I understand correctly, the currency pair should be specified as "EURUSD" in any indicator. In this regard, my question is


void OnInit()

  {
input string Currency = "JPY"; //Выбор валютной пары
input string Major_pair = "USD"; // Выбор валюты для корреляции
input bool Direct_correlation = true; // Выбор прямой и обратной корреляции
string Major_currpair = Symbol();
string two_pair;
//--------------------------------------------------------------------
int position =StringFind(Major_currpair,Major_pair,0);
   if(position == -1)
      Print("Не верно указана валюта корреляции");
   if(Direct_correlation == true)
      two_pair =StringConcatenate(Currency,Major_pair);
   else
      two_pair =StringConcatenate(Major_pair,Currency);
   Print("Two_pair = ", two_pair);
   Print("Major_currpair = ",Major_currpair);
}

How can I insert the symbol " in string? Because the currency pair is printed in the journal as USDJPY, not "USDJPY".

 
Michail_David:

How can I insert the " symbol in the line? As the currency pair in the magazine is printed as USDJPY instead of "USDJPY".

https://www.mql5.com/ru/docs/basis/types/stringconst

https://www.mql5.com/ru/docs/basis/types/integer/symbolconstants

Reason: