How to start with MQL5 - page 41

 
Vladimir Karputov #:

Example of creating an indicator based on iATR. Part 5.

code: xSuperTrend.mq5

Until this moment, we performed preparatory operations. Now it is time to write the indicator logic.

To avoid unnecessary calculations, we always work in the 'prev_calculated' variable


Remember that the indicator already has all arrays by the current character (ope, high, low, close, and others) - they are transferred through OnCalculate.


Save the version number 1.005


The end.

Hello thank you for your work but after wroting that i become array out of range for the atrbuffer
 
Vladimir Karputov #:

Example: catching a Take Profit trigger

The code: Last Deal Take Profit activation.mq5


An example of online work (via OnTradeTransaction).

  • We catch the transaction 'TRADE_TRANSACTION_DEAL_ADD' (adding a deal to history)
  • We are trying to find the deal (which generated this transaction) in the trading history
  • If the deal type is BUY or SELL ('DEAL_TYPE_BUY' || 'DEAL_TYPE_SELL')
  • If this trade is a market exit trade ('DEAL_ENTRY_OUT')
  • If this deal occurred as a result of Take Profit ('DEAL_REASON_TP')
  • We get in the trade history all deals belonging to the position and print out a little information on each deal


'm_deal' - undeclared identifier. Does not work.

 
Vladimir Karputov #:
m_deal.InfoInteger(DEAL_REASON,deal_reason)
m_deal.InfoInteger(DEAL_REASON,deal_reason)

returns a boolean, so your comparison is incorrect.

 
HenZen #:

'm_deal' - undeclared identifier. Does not work.

ignore.

 
Dear Mr Karputov,

thank you for posting very usefull code , i am learning a lot.

I have a question. Would you consider these two functions adequate to count pending orders and open positions by magic and symbol  ? 

Thank you for your time and patience. Hope you are well and life is treating you good.

//+------------------------------------------------------------------+
//|Count pending orders on this symbol and magic                     |
//+------------------------------------------------------------------+
int CountOrdersBySymbolAndMagic( string symbol,int magic)
  {
   int Orders   =  0;
   if (OrdersTotal()>0)
      for(int i=OrdersTotal()-1; i>=0; i--) 
      { 
         string   order_symbol; 
         long     order_magic; 
         if(m_order.SelectByIndex(i))
           { 
            order_symbol  =OrderGetString(ORDER_SYMBOL); 
            order_magic   =OrderGetInteger(ORDER_MAGIC); 
            if(order_symbol==symbol && order_magic==magic))
             {
             Orders++;
             }
           } 
       }
    return(Orders);
  }
//+------------------------------------------------------------------+
//| count positions on this symbol and magic                         |
//+------------------------------------------------------------------+
int CountPositionsByMagicAndSymbol( string symbol,int magic)
  {
   int positions = 0;
   if (PositionsTotal() > 0)
      for(int i=PositionsTotal()-1; i>=0; i--)
      {
         string position_symbol=PositionGetString(POSITION_SYMBOL); 
         ulong  position_magic=PositionGetInteger(POSITION_MAGIC); 
         if(m_position.SelectByIndex(i))
            { 
              position_symbol=PositionGetString(POSITION_SYMBOL); 
              position_magic=PositionGetInteger(POSITION_MAGIC); 
             if(position_symbol==symbol && position_magic==magic))
             {
              positions++;
             }
            }
      }
//---
   return(positions);
  }
 

Learn Why and How to Design Your Algorithmic Trading System

The main objective of this article is to guide beginners to learn how to design their algorithmic trading system in MQL5 through learning some of the basics of MQL5 for a simple trading system idea which will be coded step by step through this article after explaining some of the MQL5 basics. We'll code them by scripts then we'll present the result after code execution. To enhance your understanding, I advise you to apply and code what you’ll read here by yourself as this will help you to understand concepts of mentioned codes deeply. And be noted that all created codes, programs, and trading strategies in this article are designed for educational purposes only, not for anything else. And be noted that we'll use MQL5 to write codes.
Learn Why and How to Design Your Algorithmic Trading System
Learn Why and How to Design Your Algorithmic Trading System
  • www.mql5.com
This article shows the basics of MQL for beginners to design their Algorithmic trading system (Expert Advisor) through designing a simple algorithmic trading system after mentioning some basics of MQL5
 

Learn how to deal with date and time in MQL5

It is not hidden by anyone in the financial market field, the importance of time, and how it can affect trading decisions and results. MQL5 (MetaQuotes Language 5) offers an amazing solution to deal with date and time effectively and this is what we will learn in this article because we will see how we can deal with this important topic through many applications that can be coded as a part of our trading system after understanding the most important aspects of this topic in the MQL5 programming language.
Learn how to deal with date and time in MQL5
Learn how to deal with date and time in MQL5
  • www.mql5.com
A new article about a new important topic which is dealing with date and time. As traders or programmers of trading tools, it is very crucial to understand how to deal with these two aspects date and time very well and effectively. So, I will share some important information about how we can deal with date and time to create effective trading tools smoothly and simply without any complicity as much as I can.
 

Advanced Variables and Data Types in MQL5

MQL5 is the programming language of the MetaTrader 5 which is considered the most popular trading platform and it is very rich in tools and concepts that can be used to create any trading system from its simple to complex. Our objective as developers is to understand how to use these tools and concepts to achieve our development objective.

In this article, we will mention and dive deeper to learn more about variables and data types in MQL5 and how they can be useful when creating or building MQL5 trading software. We will learn more about some advanced concepts of variables and data types ...
Advanced Variables and Data Types in MQL5
Advanced Variables and Data Types in MQL5
  • www.mql5.com
Variables and data types are very important topics not only in MQL5 programming but also in any programming language. MQL5 variables and data types can be categorized as simple and advanced ones. In this article, we will identify and learn about advanced ones because we already mentioned simple ones in a previous article.
 
Introduction to MQL5 (Part 1): A Beginner's Guide into Algorithmic Trading

Introduction to MQL5 (Part 1): A Beginner's Guide into Algorithmic Trading

Without any prior programming experience, learning MQL5 can be difficult but not impossible. Understanding MQL5, a specialized language created for algorithmic trading, necessitates having both programming and financial market expertise.

In this article, we will cover the following topics:

  • Introduction to Programming
  • Types of MQL5 Programs
  • MetaEditor IDE
  • MQL5 Language Basics
 

Introduction to MQL5 (Part 2): Navigating Predefined Variables, Common Functions, and Control Flow Statements 

Welcome back to our MQL5 journey! In Part One, we embarked on the adventure of algorithmic trading, breaking down the complexities of MQL5  for beginners without prior programming experience. As we step into Part Two, the excitement continues as we delve even deeper into the essential building blocks of MQL5. Our goal is simple yet profound: to ensure everyone, regardless of their programming background, feels the embrace of understanding. Feel free to ask any questions, and let's unravel the intricacies of MQL5 together. Let's forge a community where every voice is heard and every journey in algorithmic trading is shared.