Display Orders

We are going to learn how to put input options, validate option values, create some user-defined functions and call it from OnTick() special function.

EA Name : My2ndEA

Here is the code:

Input parameters

//--- input parameters
input bool DisplayTrade = true;
input bool DisplayHistory = false;

Special function to initialization variables/parameters

int OnInit()
{
//---
if (DisplayHistory==true && DisplayTrade==true)
Alert ("Only one can be TRUE");

if (DisplayHistory==false && DisplayTrade==false)
Alert ("No Information is displayed");
//---
return(INIT_SUCCEEDED);
}

Expert Tick Function

void OnTick()
{
//---
if (DisplayTrade==true && DisplayHistory==false) ReadTradingOrders();
if (DisplayHistory==true && DisplayTrade==false) ReadHistoryOrders();
}

User-defined function to read orders on trade or history

void ReadTradingOrders(){
static bool isPrint = false;
if (!isPrint){
string str = "";
int tOrders = OrdersTotal();
for (int i = 0; i

User-defined function to get order type name in string format

string GetOPType(int orderType){
string OPType = "";

switch (orderType){
case OP_BUY : OPType = "BUY"; break;
case OP_SELL : OPType = "SELL"; break;
case OP_BUYLIMIT : OPType = "BUY LIMIT"; break;
case OP_SELLLIMIT : OPType = "SELL LIMIT"; break;
case OP_BUYSTOP : OPType = "BUY STOP"; break;
case OP_SELLSTOP : OPType = "SELL STOP"; break;

}
return (OPType);
}

Complete Code



//+------------------------------------------------------------------+
//| My2ndEA.mq4 |
//| Copyright 2018, AutoBotFx |
//| https://AutoBotFx.pro |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AutoBotFx"
#property link "https://AutoBotFx.pro"
#property version "1.00"
#property strict

//--- input parameters
input bool DisplayTrade = true;
input bool DisplayHistory = false;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if (DisplayHistory==true && DisplayTrade==true)
Alert ("Hanya boleh salah satu yang true");

if (DisplayHistory==false && DisplayTrade==false)
Alert ("Tidak ada Informasi yang ditampilkan");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if (DisplayTrade==true && DisplayHistory==false) ReadTradingOrders();
if (DisplayHistory==true && DisplayTrade==false) ReadHistoryOrders();
}
//+------------------------------------------------------------------+

void ReadTradingOrders(){
static bool isPrint = false;
if (!isPrint){
string str = "";
int tOrders = OrdersTotal();
for (int i = 0; i

About the Author

Leave Comment

Your email address will not be published. Required fields are marked *