Questions from a "dummy" - page 243

 
paladin800:
Do ArrayResize(Buf, rates_total);

Also do this, then at least there will be no error.

int start=10;

And it will draw a straight line=0,014 on Euro M1.

 

Good afternoon.

There is a code that for some reason doesn't work.

Price in m_symbol.Ask() method returns 0.

Judge the code harshly. I am just learning. Ready to listen to any adequate criticism.

While for the purpose was the fact of opening of a position. Qty not interesting yet(Easy to implement).

//+------------------------------------------------------------------+
//|                                                        probe.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input int    perMA1=3;
input int    perMA2=7;
input double DifMANeed=0;
input double InpLots=0.1;
double DifMAN=0;

CTrade m_trade;
CSymbolInfo m_symbol;

class MATest{
private:
   int MA1;    //First MA
   int MA2;    //Two MA
   
public:
   double DifMA;  //Diference of MA
   bool TradeAllowed();     
};
bool MATest::TradeAllowed(){
   MA1=iMA(NULL,0,perMA1,0,MODE_SMA,PRICE_CLOSE);
   MA2=iMA(NULL,0,perMA2,0,MODE_SMA,PRICE_CLOSE);
   double price=m_symbol.Ask();
   m_trade.SetDeviationInPoints(5);
   DifMA=MathAbs(MA1-MA2);
   Print(price);
   if(DifMA>DifMAN){
      if(MA1>MA2){
        if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,InpLots,m_symbol.Ask(),0,0)){
            Print("Open Sell");
        }
        else Print("Cant not open Sell");
      }
      if(MA1<MA2){
        if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,m_symbol.Bid(),0,0)){
            Print("Open Buy");
        }
        else Print("Cant not open Buy",m_symbol.Name(),m_symbol.Bid());
      
      }
      return(true);
   }
   else return(false);
};

MATest g_trade;

int OnInit()
  {
//---
   string symb=Symbol();
   m_symbol.Name(symb);
   
   Alert(m_symbol.Name()," ",NormalizeDouble(m_symbol.Bid(),m_symbol.Digits()));
   double close_array[];
      CopyClose(NULL,0,1,200,close_array);
   double high_array[];
      CopyHigh(NULL,0,1,200,high_array);
   double low_array[];
      CopyLow(NULL,0,1,200,low_array);
   double volant;
   for(int i=ArraySize(close_array);i<0;i--){
         volant+=(close_array[i]+high_array[i]+low_array[i])/3;
         volant=volant/ArraySize(close_array);
      }
   if(DifMANeed==0||DifMANeed>volant){
      DifMAN=volant;
   }
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(g_trade.TradeAllowed())Comment(g_trade.DifMA,"  Trade Allowed");
   else Comment(g_trade.DifMA," Trade Not Allowed");
  }
//+------------------------------------------------------------------+
 
panker:

Good afternoon.

There is a code that for some reason doesn't work.

Price in m_symbol.Ask() method returns 0.

Judge the code harshly. I am just learning. Ready to listen to any adequate criticism.

While for the purpose was the fact of opening of a position. Qty not interesting yet(Easy to implement).

Maybe you're missing a function, something like SymbolSelect.

In this case, it is a command Name

https://www.mql5.com/ru/docs/standardlibrary/tradeclasses/csymbolinfo/csymbolinfoask - see note

Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / Ask
Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / Ask
  • www.mql5.com
Стандартная библиотека / Торговые классы / CSymbolInfo / Ask - Документация по MQL5
 
Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / RefreshRates
Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / RefreshRates
  • www.mql5.com
Стандартная библиотека / Торговые классы / CSymbolInfo / RefreshRates - Документация по MQL5
 
panker: There's code that doesn't work for some reason. Price in m_symbol.Ask() method returns 0.
Look at the library implementation itself. The Ask() method stupidly returns m_tick.ask value. The RefreshRates() method is used to refresh m_tick values.)
 

Can someone please give a code example.

How to create a "decimal ScrollBar"?

I used MQL5 class CScroll.https://www.mql5.com/en/docs/standardlibrary/controls/cscroll

Documentation on MQL5: Standard Library / Classes for Control Panels and Dialogs / CScroll
Documentation on MQL5: Standard Library / Classes for Control Panels and Dialogs / CScroll
  • www.mql5.com
Standard Library / Classes for Control Panels and Dialogs / CScroll - Documentation on MQL5
 
If I remember correctly, the OnDeinit() function has 2.5 seconds to execute. Question 1: if not all indicator handles are free during this time, what happens? Question 2: Is there a time limit for OnInit()?
 
paladin800:

If I remember correctly, the OnDeinit() function needs 2.5 seconds to execute.

Question 1: if all indicator handles are not released during this time, what happens?

Indicator handles are a separate topic in MT5, because their release is controlled not so much by the Expert Advisor itself (it can only send a command that it does not need them and reset the handle value), as by the terminal itself (which makes the final decision to completely delete the entire indicator handle).


Question 2: is there a time limit for OnInit()?

no
 

Can you tell me what the "profit corridor" should be per year? (в %%)

Files:
12.png  45 kb
 
I'm writing a multi-currency Expert Advisor where in the input parameters I set the instrument name, such as string Symbol0="EURUSD". If I write the wrong name, the trade does not go. Question: Is there such a function that would compare instrument names with instruments offered by broker?
Документация по MQL5: Основы языка / Типы данных / Тип string
Документация по MQL5: Основы языка / Типы данных / Тип string
  • www.mql5.com
Основы языка / Типы данных / Тип string - Документация по MQL5