Questions from Beginners MQL5 MT5 MetaTrader 5 - page 453

 
pusheax:
Bullshit
Well, it's about 50/50.
 
Alexey Solomin:

Sorry, didn't specify the platform, I have mql4,"POSITION_PROFIT" is not in the help, could it be " OrderProfit" ?

(Please insert a picture this way:forum: how to insert picture. - OK)
Yes, it is " OrderProfit" !
 

Hello ! I found one code in kodobase and a question to it I can't find the answer to ,

at the beginning of the code

#define  MAGIC_NUMBER 12937

#define  DEV 20
#define  RISK 0.0
#define  BASELOT 0.1
#define  SL 100
#define  TP 700
#define  DELTA 30

Why do I use macro expansion (#define)? These variables are not available in the settings

and how to make it possible to check them with optimization

https://www.mql5.com/ru/code/viewcode/244/53730/grr-al__3.mq5

 
Alexander Antoshkin:

Hello ! I found one code in kodobase and a question to it I can't find the answer to ,

at the beginning of the code

Why do I use macro expansion (#define)? These variables are not available in the settings

and how to make it possible to check them with optimization

https://www.mql5.com/ru/code/viewcode/244/53730/grr-al__3.mq5

Make them input variables.
 
Tapochun:
Make them input variables.

in the sense of

#inputMAGIC_NUMBER 12937; so

input  DEV 20;
input  RISK 0.0;
input  BASELOT 0.1;
input  SL 100;
input  TP 700;
input  DELTA 30;
или input uint  MAGIC_NUMBER 12937;
 
Alexander Antoshkin:
input uint  MAGIC_NUMBER=12937;
 
Karputov Vladimir:
That's what I did, the compiler gave me an error, ok thanks for now, I'll get back to my computer, I'll keep going.
 
Alexander Antoshkin:

in the sense of

#inputMAGIC_NUMBER 12937; so

Modifier input, placed in front of the variable type, means that the variable will be available in the list of input parameters of the Expert Advisor.

In the specific case of magik, it is better to put the modifier sinput in front of it. It means that the variable will also be available in the list of input parameters, it will participate in the optimization but its value cannot be optimized.

In general, there is documentation. In the compiler select word input and press F1. There are examples there.

 

Wrote my first crooked EA on slips. Tell me why it doesn't send orders?

//+------------------------------------------------------------------+
//|                                                 Первый робот.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input int TakeProfit = 1500;
input int StopLoss = 500;
int muving_handle_1;
int muving_handle_2;
double ma1[];
double ma2[];

int OnInit()
  {
 int MA_1_PERIOD = 20;
 int MA_2_PERIOD = 10;
 muving_handle_1 = iMA(_Symbol,_Period,MA_1_PERIOD,0,MODE_SMA,PRICE_CLOSE);
 muving_handle_2 = iMA(_Symbol,_Period,MA_2_PERIOD,0,MODE_SMA,PRICE_CLOSE);
 return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  int signal; 
 
 if(CopyBuffer(muving_handle_1,0,0,3,ma1)<0)
 { 
      Alert("Ошибка копирования буферов индикатора MA 10 - номер ошибки:",GetLastError()); 
      return; 
 } 
 
if(CopyBuffer(muving_handle_1,0,0,3,ma2)<0)
 { 
      Alert("Ошибка копирования буферов индикатора MA 20 - номер ошибки:",GetLastError()); 
      return; 
 } 

signal=CheckTradeSignal(); 
PositionOpen(signal);
   
  }
//+------------------------------------------------------------------+
  
int CheckTradeSignal() 
  { 
   int TradeSignal=0; 
   if((ma2[2]>ma1[2]) && (ma2[1]<ma1[1])) 
      TradeSignal=1; // Buy signal   
   if((ma2[2]<ma1[2]) && (ma2[1]>ma1[1])) 
      TradeSignal=2; // Sell signal 
   return TradeSignal; 
  } 
  
  bool PositionOpen(int tradeSignal) 
  { 
   int InpTP=500,InpSL=150; 

   if(tradeSignal>0) // Signal 
     { 
      //--- 1. Создать запрос 
      MqlTradeRequest Trade_reqst={0};            // Инициализация структуры торгового запроса 
      Trade_reqst.action=TRADE_ACTION_DEAL;       // Тип: немедленное совершение сделки 
      Trade_reqst.symbol=_Symbol;                 // Инструмент: текущий 
      Trade_reqst.volume=1;                    // Лотаж 
      Trade_reqst.type_filling=ORDER_FILLING_FOK; // Политика исполнения: Fill Or Kill 
      double sl,tp; 
      if(tradeSignal==1) // Buy signal   
        { 
         Trade_reqst.type=ORDER_TYPE_BUY;            // Тип ордера: на покупку 
         sl=SymbolInfoDouble(_Symbol,SYMBOL_BID)-InpSL*_Point; 
         tp=SymbolInfoDouble(_Symbol,SYMBOL_BID)+InpTP*_Point; 
        } 
      else 
        { 
         Trade_reqst.type=ORDER_TYPE_SELL;           // Тип ордера: на продажу 
         sl=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+InpSL*_Point; 
         tp=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-InpTP*_Point; 
        } 
      Trade_reqst.sl=sl; 
      Trade_reqst.tp=tp; 
      //--- 2. Отправить торговый приказ 
      MqlTradeResult Trade_reslt_m={0};             // Инициализация структуры результата торгового запроса 
      if(!OrderSend(Trade_reqst,Trade_reslt_m))     // Отправка торгового запроса на сервер 
         return false; 
      else 
         return true; 
     } 
   else             // No signal 
     { 
      return false; 
     } 
  }  
Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Tell me why in debugging EA I can check values of variables and functions that are only in OneInit()? Let's say I want to check a bar or tick processing condition in OneTick() how can I do that?
Reason: