Questions from Beginners MQL4 MT4 MetaTrader 4 - page 173

 

I encounter much more expression and negativity in this community every day, and no one reacts.

Anyway, that's the end of the question.

 
Nikolai Semko :

If you want to create your own keyboard and keyboard controls (CHART_MOUSE_SCROLL, CHART_KEYBOARD_CONTROL ...), you need to disable it.
But it is not possible.
The speed of But such an interface will of the BE are significantly higher than the base one's, since IT is not Possible to use asynchronous functions The very INHIBITED ChartGetInteger

Thank you very much again, Nikolai. I tried to convert your CanvasBar.mq5 to mt4, added some input options regarding widths / colours / ... (so it can be used for example "to simulate ninjatrader candle style")

Files:
CanvasBar.png  7 kb
CanvasBar.mq4  12 kb
 

Hello! I have a standard iEnvelopes indicator!
I can't get it to work the way I need it to!
Ie, the need to when the candle touched or crossed the line on the current candle UP, then opened BUY, and the candle touched or crossed the line on the current candle DOWN, then opened SELL..... and it happened once (the signal-hit and all, another signal-hit and all constantly)!

Inv_0_1 = iEnvelopes(_Symbol, time2_method, envel, envel_method, envelshag, envel_Price, envelproc, MODE_UPPER, 0); 
    Inv_0_11 = iEnvelopes(_Symbol, time2_method, envel, envel_method, envelshag, envel_Price, envelproc, MODE_UPPER, 1); 
     
    Inv_0_2 = iEnvelopes(_Symbol, time2_method, envel, envel_method, envelshag, envel_Price, envelproc, MODE_LOWER, 0); 
    Inv_0_21 = iEnvelopes(_Symbol, time2_method, envel, envel_method, envelshag, envel_Price, envelproc, MODE_LOWER, 1); 

    if(High[0] > Inv_0_2 && High[0] < Inv_0_21) 
      { 
      TP = NormalizeDouble(Bid - tpt * _Point, _Digits); 
         ticketZK = OpenOrder(_Symbol, OP_SELL, lot, Bid, slippage, 0, TP, comment, Magic, 0, clrRed); 
         if(ticketZK > 0) 
         Print("Ордер на SELL успешно открыт! "); 
         return; 
      }  
     
       
    if(Low[0] < Inv_0_1 && Low[0] > Inv_0_11) 
      { 
      TP = NormalizeDouble(Ask + tpt * _Point, _Digits); 
         ticketZK = OpenOrder(_Symbol, OP_BUY, lot, Ask, slippage, 0, TP, comment, Magic, 0, clrBlue); 
         if(ticketZK > 0) 
         Print("Ордер на BUY успешно открыт! "); 
         return; 
      }

Please help!

 
ponochka:

Hello! There is a standard indicator iEnvelopes!
I cannot make it work the way I want it to!
Ie, the need to when the candle touched or crossed the line on the current candle UP, then opened BUY, and the candle touched or crossed the line on the current candle DOWN, then opened SELL..... and it happened once (the signal-hit and all, another signal-hit and all constantly)!

Please help!

I need to add process understanding to the code :-)

As long as the candle hasn't closed, High[0] can only go up, Low[0] only go down, and the decompiled envelopes do whatever they want :-)

If the envelope is not taken from Open prices, you cannot look at an unclosed bar.

 
Maxim Kuznetsov:

you need to add process understanding to the code :-)

Until the candle closes, High[0] can only go up, Low[0] only go down, while the envelopes from the decompile behave as they want :-)

If the envelope is not taken from Open prices, you cannot look at the unclosed bar.

I.e., is it better to work with Open and Close? What is the check?
 

Help me understand how to calculate MA on an array.

I build MA by open-close, but from the graph it looks like it is calculated from right to left.

I usediMAOnArray andSimpleMAOnBuffer as tools, is there a better option?


//+------------------------------------------------------------------+
//|                                                        _null.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#include <MovingAverages.mqh>

#property indicator_buffers 4
#property indicator_plots   2
//--- plot OC
#property indicator_label1  "OC"
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  clrSteelBlue, clrRed,clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_label2  "MA1"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrBrown
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1


//--- indicator buffers
double   OC[], OC_color[], MA1_buf[];
input int MA1=2;

int OnInit()
  {
  
   IndicatorSetString(INDICATOR_SHORTNAME,"t1");
   
   SetIndexBuffer(0,OC,INDICATOR_DATA);
   SetIndexBuffer(1,OC_color,INDICATOR_COLOR_INDEX);
   
   SetIndexBuffer(2, MA1_buf,INDICATOR_DATA); 
   //PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,50);

     
//--- indicator buffers mapping

   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{

//--- Проверка количества доступных баров (1 - минимально, 4 - оптимально для большинства расчётов. Но всё "по месту"...)
   if(rates_total<4) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated; // 0 - пришел новый тик, новый бар формироваться не начал. 1 - пришел новый тик и начал формироваться новый бар.
   //if(limit>1) 
   
               // если вписать "limit>0", то на нулевом баре будет расчёт только нулевого бара, на каждом новом баре будет полный перерасчёт всей истории
               // если вписать "limit>1", то на нулевом баре будет расчёт только нулевого бара, на открытии нового бара - пересчёт первого и нулевого,
               // при подгрузке истории и на первом запуске - перерасчёт всей истории
     {
     limit=rates_total-1;
           // здесь должна быть инициализация всех используемых буферов индикатора необходимыми значениями (обычно EMPTY_VALUE и 0)
     }
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      // необходимые действия по расчёту индикатора
     
     OC[i]=fmax(open[i],close[i])-fmin(open[i],close[i]);
     if(OC[i]>0.001)
      {   OC_color[i]=1;
      }
      }  
   
 /*  for(int k=limit; k>=0 && !IsStopped(); k--)
     {
   
     MA1_buf[k]=iMAOnArray(OC,0,MA1,k,MODE_SMA,0);
     }
*/
      SimpleMAOnBuffer(rates_total,prev_calculated,0,MA1,OC,MA1_buf);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

Hello!!! I use this code to translate a link in a comment, but systematically once a day it gives me an error: web error 5203 (ERR_WEBREQUEST_REQUEST_FAILED. Error in the result of HTTP request)

Is there any way to fix it?

string Web(string url)
{
string headers, ret;
char post[], result[];
int res, timeout=5000;
res= WebRequest("GET",url,NULL,timeout,post,result,head ers);
if(d3 != 1 && res < 0)
{
MessageBox("4060 Добавите ссылку в доверенную зону (Сервис-Настройки-Советники-Разрешить URL)", "Внимание", MB_OK);
Print("Web-Error: ",GetLastError()," (4060 Добавите ссылку в доверенную зону (Сервис-Настройки-Советники-Разрешить URL");
ExpertRemove();
d3 = 1;
return("");
}
ret = CharArrayToString(result, 0, -1);
return(ret);
}
 

Can you please tell me how to make weighting coefficients for signals?

For example, I have three signals by scale: crossover, comparison1 (previous bar vs. previous bar) and comparison 2 (previous bar vs. previous bar on a higher TF).

I try to do it with MAKD build in MT, but it doesn't open deals. There is nothing in the log. I.e. the standard EA basis has not been touched, just the logics of position opening has been changed. So the triplet is the basis of the MT MAKD-advisor (normal)

Just don't swear for nubian code, I'm not a programmer


...
Вводимые параметры

input double TradeLevel_BUY = 1;

input double TradeLevel_SELL = -1;


input double w_S_MA_1 = 1;

input double w_S_MA_2 = 1;

input double w_S_MA_3 = 1;

input double w_S_MA_4 = 1;

input double w_S_MA_5 = 1;

input double w_S_MA_6 = 1;


...

----------------

...

void OnTick(void)

  {

   

   double MA_Fast_1,

          MA_Fast_2,

          MA_Slow_1,

          MA_Slow_2,

          MA_Fast_LargeTF_1,

          MA_Fast_LargeTF_2,

          MA_Slow_LargeTF_1,

          MA_Slow_LargeTF_2;

double S_MA_1,

       S_MA_2,

       S_MA_3,

...

   MA_Fast_1=iMA(NULL,0,MA_Fast_1_Period,MA_Fast_1_Shift,MODE_EMA,PRICE_CLOSE,1);
   MA_Fast_2=iMA(NULL,0,MA_Fast_2_Period,MA_Fast_2_Shift,MODE_EMA,PRICE_CLOSE,2);
   MA_Fast_LargeTF_1=iMA(NULL,MA_LargeTF,MA_Fast_LargeTF_1_Period,MA_Fast_LargeTF_1_Shift,MODE_EMA,PRICE_CLOSE,1);
   MA_Fast_LargeTF_2=iMA(NULL,MA_LargeTF,MA_Fast_LargeTF_2_Period,MA_Fast_LargeTF_2_Shift,MODE_EMA,PRICE_CLOSE,2);
   MA_Slow_1=iMA(NULL,0,MA_Slow_1_Period,MA_Slow_1_Shift,MODE_EMA,PRICE_CLOSE,1);
   MA_Slow_2=iMA(NULL,0,MA_Slow_2_Period,MA_Slow_2_Shift,MODE_EMA,PRICE_CLOSE,2);
   MA_Slow_LargeTF_1=iMA(NULL,0,MA_Slow_LargeTF_1_Period,MA_Slow_LargeTF_1_Shift,MODE_EMA,PRICE_CLOSE,1);

   MA_Slow_LargeTF_2=iMA(NULL,0,MA_Slow_LargeTF_2_Period,MA_Slow_LargeTF_2_Shift,MODE_EMA,PRICE_CLOSE,2);

...

 double Sum;

if (MA_Fast_1>MA_Slow_1)

      {

        S_MA_1=1*w_S_MA_1;

      }

   else

      {

        S_MA_1=0;

      }

   return;

   

   if (MA_Fast_1>MA_Fast_2)

      {

        S_MA_2=1*w_S_MA_2;

      }

   else

      {

        S_MA_2=0;

      }

   return;

   

   if (Open[1]<MA_Fast_LargeTF_1 && Close[1]>MA_Fast_LargeTF_1 || Open[1]>MA_Fast_LargeTF_1 && Close[1]>MA_Fast_LargeTF_1)

      {

        S_MA_3=1*w_S_MA_3;

      }

   else

      {

        S_MA_3=0;

      }

   return;

...

 if (MA_Fast_1<MA_Slow_1)

      {

        S_MA_4=-1*w_S_MA_4;

      }

   else

      {

        S_MA_4=0;

      }

   return;

   

   if (MA_Fast_1<MA_Fast_2)

      {

        S_MA_5=-1*w_S_MA_5;

      }

   else

      {

        S_MA_5=0;

      }

   return;

   

   if (Open[1]>MA_Fast_LargeTF_1 && Close[1]<MA_Fast_LargeTF_1 || Open[1]<MA_Fast_LargeTF_1 && Close[1]<MA_Fast_LargeTF_1)

      {

        S_MA_6=-1*w_S_MA_6;

      }

   else

      {

        S_MA_6=0;

      }

   return;


   Sum=S_MA_1+S_MA_2+S_MA_3+S_MA_4+S_MA_5+S_MA_6;

...

 if(Sum>TradeLevel_BUY)

        {

         ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Ask-SL*Point,Bid+TP*Point,"Optim",16384,0,Blue);

...


 if(Sum<=TradeLevel_SELL)

        {

         ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Bid+SL*Point,Ask-TP*Point,"Optim",16384,0,Red);

         if(ticket>0)

 

Good afternoon! How do I implement this function correctly (I think you'll understand what I want to do)?

         if(IsTesting())
            for(int i2=0; i2<fixweekBars; i2++)
               else
            for(int i2=fixweekBars; i2>0; i2--)
 

Hi. Need help with winApi user32.dll.

There is one Chart in the profile. Need a script to open two more Chatr's. All three Charts (was one and opened two more) to do the specified size in the set place.

No matter how I try - all no luck.

This script changes the size and position of the Chart on which I throw.

//+------------------------------------------------------------------+
//|                                                      posicion.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property script_show_inputs

#import "user32.dll"

int  SetWindowPos(int hWnd,int hWndInsertAfter,int X,int Y,int cx,int cy,int uFlags);
int  GetParent(int hWnd);
int  GetTopWindow(int hWnd);
int  GetWindow(int hWnd,int wCmd);
int  GetWindowDC(int h);
int  ShowWindow(int hWnd,int nCmdShow);
#import 

#define GW_HWNDNEXT        0x0002
#define SWP_NOSIZE         0x0001
#define SWP_NOMOVE         0x0002
#define SWP_NOZORDER       0x0004
#define SW_RESTORE 9
#define SWP_FRAMECHANGED   0x0020

int     gr2x1_P1  []    = {PERIOD_H4,PERIOD_D1,PERIOD_W1};        // Period of grafic 1 of 2x1
int     CXShift2x1[]    = {0,0,1040};             // Horizontal shift of grafic 1 of 2x1
int     CYShift2x1[]    = {0,268,0};           // Vertical shift of grafic 1 of 2x1
int     CXSize2x1 []    = {1040,1040,880};           // Width of grafic 1 of 2x1
int     CYSize2x1 []    = {500,500,1000};           // Height of grafic 1 of 2x1

input int xy = 0;//xy 0-2
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
   void OnStart()
  {

   int i,handle;
   int parent;

   handle=(int)ChartGetInteger(0,CHART_WINDOW_HANDLE);Print("ChartGetInteger(0,CHART_WINDOW_HANDLE)   ",handle); //возвращает дескриптор 2688738                                                                                                                   
   parent=GetParent(handle);Print("parent_0   ",parent);                                         //возвращает дескриптор 197188
   ShowWindow(parent,SW_RESTORE);

  
      i=xy;
      SetWindowPos(parent,0,CXShift2x1[i],CYShift2x1[i],CXSize2x1[i],CYSize2x1[i],0);
      //Sleep(5000);
  }
//+------------------------------------------------------------------+
Открыть Новые дополнительные Chart-ы 
Но как дальше изменить размер дополнительных Chart-ов, ни как не получается. 

int i;
   for(i=0; i<3; i++)
     {
     long h=ChartOpen("EURUSD",gr2x1_P1[i]);
     }
Reason: