How to start with MQL5 - page 25

 
Ahmad861 :

Hey Vladimir, you have been helping me create my EA from the very beginning and asking for nothing in return and i want to thank you from the bottom of my heart. There is this one last thing i need help with, I trade multi timeframes, M5, M15, M30, H1. Im currently running the multi timeframes on a loop, what i need is that if i have a setup in M5, i want to know that the M15 has also formed a new candle, in other words open of M5 should be equal to open of M15. I've tried a lot on how to go about this but now i need professional help

Just define the following event: a new candle was born on the M15. This automatically means: the 'M15' candlestick was born and the 'M5' candlestick was born.


Verification:

//+------------------------------------------------------------------+
//|                                        Two Candles Open Time.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.00"
//--- input parameters
input int      Input1=9;
//---
datetime m_prev_bars_m5             = 0;        // "0" -> D'1970.01.01 00:00';
datetime m_prev_bars_m15            = 0;        // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   datetime time_m5_0=iTime(Symbol(),PERIOD_M5,0);
   if(time_m5_0!=m_prev_bars_m5)
     {
      Print("new M5, ",TimeToString(time_m5_0,TIME_DATE|TIME_MINUTES));
      m_prev_bars_m5=time_m5_0;
     }
   datetime time_m15_0=iTime(Symbol(),PERIOD_M15,0);
   if(time_m15_0!=m_prev_bars_m15)
     {
      Print("new M15, ",TimeToString(time_m15_0,TIME_DATE|TIME_MINUTES));
      m_prev_bars_m15=time_m15_0;
     }
  }
//+------------------------------------------------------------------+


Result:

2021.05.21 17:14:20.229 2021.04.16 00:35:00   new M5, 2021.04.16 00:35
2021.05.21 17:14:20.474 2021.04.16 00:40:00   new M5, 2021.04.16 00:40
2021.05.21 17:14:20.618 2021.04.16 00:45:00   new M5, 2021.04.16 00:45
2021.05.21 17:14:20.618 2021.04.16 00:45:00   new M15, 2021.04.16 00:45
 
Vladimir Karputov:

Just define the following event: a new candle was born on the M15. This automatically means: the 'M15' candlestick was born and the 'M5' candlestick was born.


Verification:


Result:

Thanks 

 

Example: how to calculate the number of BUY and SELL trades for each Magic number for the current day

The code: 'Total transactions today by Magic number.mq5'

//+------------------------------------------------------------------+
//|                     Total transactions today by Magic number.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.000"
//+------------------------------------------------------------------+
//| Structure History Deals                                          |
//+------------------------------------------------------------------+
struct STRUCT_HISTORY_DEALS
  {
   long              magic;                  // Magic number
   int               count_buy;              // Number of Buy deals
   int               count_sell;             // Number of Sell deals
   //--- Constructor
                     STRUCT_HISTORY_DEALS()
     {
      magic                      = 0;
      count_buy                  = 0;
      count_sell                 = 0;
     }
  };
STRUCT_HISTORY_DEALS SHistoryDeals[];
//--- input parameters
input int      Input1=9;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   RequestTradeHistory(SHistoryDeals);
   int size=ArraySize(SHistoryDeals);
   for(int i=0; i<size; i++)
     {
      Print(IntegerToString(SHistoryDeals[i].magic),
            ", BUY: ",IntegerToString(SHistoryDeals[i].count_buy),
            ", SELL: ",IntegerToString(SHistoryDeals[i].count_sell));
     }
  }
//+------------------------------------------------------------------+
//| Request trade history                                            |
//+------------------------------------------------------------------+
void RequestTradeHistory(STRUCT_HISTORY_DEALS &history_deals[])
  {
//--- request trade history
   datetime from_date=iTime(Symbol(),PERIOD_D1,0);
   datetime to_date=TimeCurrent()+86400;
   HistorySelect(from_date,to_date);
   uint total_deals=HistoryDealsTotal();
   ulong ticket_history_deal=0;
   if(total_deals>0)
     {
      ArrayFree(history_deals);
      //--- for all deals
      for(uint i=0; i<total_deals; i++)
        {
         //--- try to get deals ticket_history_deal
         if((ticket_history_deal=HistoryDealGetTicket(i))>0)
           {
            long     deal_ticket       = HistoryDealGetInteger(ticket_history_deal,DEAL_TICKET);
            long     deal_type         = HistoryDealGetInteger(ticket_history_deal,DEAL_TYPE);
            if(deal_type==DEAL_TYPE_BUY || deal_type==DEAL_TYPE_SELL)
              {
               long     deal_entry        = HistoryDealGetInteger(ticket_history_deal,DEAL_ENTRY);
               if(deal_entry==DEAL_ENTRY_IN)
                 {
                  long     deal_magic        = HistoryDealGetInteger(ticket_history_deal,DEAL_MAGIC);
                  //---
                  int size=ArraySize(history_deals);
                  bool find=false;
                  for(int j=0; j<size; j++)
                    {
                     if(history_deals[j].magic==deal_magic)
                       {
                        if(deal_type==DEAL_TYPE_BUY)
                           history_deals[j].count_buy=history_deals[j].count_buy+1;
                        if(deal_type==DEAL_TYPE_SELL)
                           history_deals[j].count_sell=history_deals[j].count_sell+1;
                        continue;
                       }
                    }
                  if(!find)
                    {
                     ArrayResize(history_deals,size+1);
                     history_deals[size].magic=deal_magic;
                     if(deal_type==DEAL_TYPE_BUY)
                        history_deals[size].count_buy=1;
                     if(deal_type==DEAL_TYPE_SELL)
                        history_deals[size].count_sell=1;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
 

hello Vladimir,

I am new to robot development or strategy automation.

indeed, I have coded a trading strategy based on stochastic. only, I would like to increase the size of my lots after a loss and after two gains (profits), I really do not know how to insert this code in my code source.



here is my bot

Files:
 
lo1988 :

hello Vladimir,

I am new to robot development or strategy automation.

indeed, I have coded a trading strategy based on stochastic. only, I would like to increase the size of my lots after a loss and after two gains (profits), I really do not know how to insert this code in my code source.

here is my bot

You cheated a little - you didn’t write anything and you didn’t develop anything on your own: you just generated an Expert Advisor in the MQL5 Wizard. The MQL5 Wizard generates simple strategies and there is no Martingale in these strategies.

You need:

  • or master the MQL5 language on your own
  • or use the search on CodeBase
  • or create a paid job in the Freelance service
 
lo1988 :

bonjour Vladimir,

je suis débutant dans le développement de robot ou l'automatisation de stratégies.

en effet, j'ai code une stratégie de trading base sur le stochastic .seulement, je voudrais, augmenter la taille de mes lots après une perte et après deux gains (profits), je ne sais vraiment pas comment insérer ce code dans mon code la source.



voici mon bot

I would like if you will allow me, to also ask if it is possible to imitate the transactions by day, and by level of profit.

how to do if so?

 
lo1988:

I would like if you will allow me, to also ask if it is possible to imitate the transactions by day, and by level of profit.

how to do if so?

I edited your posts to be in English.
So, you should write in English here (it is the English language forum).
 
Sergey Golubev:
J'ai modifié vos messages pour qu'ils soient en anglais.
Donc, vous devriez écrire en anglais ici (c'est le forum en anglais).

ok, thanks for the information and your help

 
lo1988:

I would like if you will allow me, to also ask if it is possible to imitate the transactions by day, and by level of profit.

how to do if so?

hello Vladimir, I am new to robot development or strategy automation. indeed, I have coded a trading strategy based on the stochastic. only, I would like to increase the size of my lots after a loss and after two gains (profits), I really do not know how to insert this code in my code source.

Files:
 
lo1988:

hello Vladimir, I am new to robot development or strategy automation. indeed, I have coded a trading strategy based on the stochastic. only, I would like to increase the size of my lots after a loss and after two gains (profits), I really do not know how to insert this code in my code source.

He has already answered you in his post. You will have to learn to code yourself or hire someone to do it for you!

Forum on trading, automated trading systems and testing trading strategies

How to start with MQL5

Vladimir Karputov, 2021.05.23 16:11

You cheated a little - you didn’t write anything and you didn’t develop anything on your own: you just generated an Expert Advisor in the MQL5 Wizard. The MQL5 Wizard generates simple strategies and there is no Martingale in these strategies.

You need:

  • or master the MQL5 language on your own
  • or use the search on CodeBase
  • or create a paid job in the Freelance service