MT5 Basics | Forex Factory

HeroPoker_HeroPoker扑克_HeroPoker德扑圈官网

Attachments: MT5 Basics

MT5 Basics

you can post here:
1) if are among my buddies
2) if are a high-rank member
3) if you are not under my ignore-list . .
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 12 KB



بسم الله الرحمن الرحيم
download mt5 platform form mql5 site:
https://download.mql5.com/cdn/web/me...paign=download

try this broker . . .
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 9 KB




some MT5 basics

Poistions/Orders numbers
you use one of 4 similar functions:
//
HistorySelect(0, TimeCurrent());
//
Print("OrdersTotal"+string(OrdersTotal()));
Print("PositionsTotal"+string(PositionsTotal()));
Print("HistoryDealsTotal"+string(HistoryDealsTotal()));
Print("HistoryOrdersTotal"+string(HistoryOrdersTotal()));

OrdersTotal
Returns the number of current orders. (pending orders)
Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal. An order is a request to conduct a transaction, while a position is a result of one or more deals.

PositionsTotal
Returns the number of open positions

HistoryDealsTotal
Returns the number of deal in history. Prior to calling HistoryDealsTotal(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function.
Do not confuse orders, deals and positions. Each deal is the result of the execution of an order, each position is the summary result of one or more deals.

HistoryOrdersTotal
Returns the number of orders in the history. Prior to calling HistoryOrdersTotal(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function.
Do not confuse orders of a trading history with current pending orders that appear on the "Trade" tab of the "Toolbox" bar. The list of orders that were canceled or have led to a transaction, can be viewed in the "History" tab of "Toolbox" of the client terminal.
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 58 KB

-
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (2)
Account Information
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 12 KB

-
we use this three functions:


AccountInfoDouble
Returns a value of double type of the corresponding account property
AccountInfoInteger
Returns a value of integer type (bool, int or long) of the corresponding account property
AccountInfoString
Returns a value string type corresponding account property


AccountInfoDouble
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 5 KB

all avialable account double proprties:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 38 KB

all avialable account integer proprties:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 34 KB

all avialable account string proprties:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 8 KB

-
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 51 KB
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 86 KB
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (3)
HANDLERS
int OnInit(void);
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 11 KB

=====
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 75 KB

-
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (4)
SELECTORS
there are 7 selectors for 1) orders, 2) postions 3) deals

Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 91 KB


\
How to use selector? and when?
NEXT
BUT now let us build our boxes (semi-dahboard) . . . just to display data on chart . .
at this early stage we will use only these habdlers:
OnInit
OnDenit
OnTimer
OnChartEvent
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
implant into you mind:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 2 KB

-
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 4 KB


-
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
difference b/w Order and Postion:
pending = order
open=position
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 87 KB

-
therefore if the ORDER is exeucted .. it becomes a POSITION
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (5)
PositionGetTicket(i)
you must use this function to pass through all positions . .

example:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 9 KB

output:

Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 83 KB

-
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
quiz: how to get the total open lots of any symbol?
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
quiz: how to get the total open lots of any symbol?
Inserted Code
      string symbol_name = "GBPUSD"; // for example
      double LotsBUYm=0;
      double LotsSELLm=0;
      double Net_Lotsm=0;
      for(int j=0; j<=PositionsTotal()-1; j++)
        {
         if(!PositionSelectByTicket(PositionGetTicket(j)))
           {
            continue;//nếu chọn ko được lệnh n鄌
           }
         if(StringFind(PositionGetString(POSITION_SYMBOL),symbol_name,0)>=0)
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
              {
               LotsBUYm = LotsBUYm + PositionGetDouble(POSITION_VOLUME);
              }
            else
               if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
                 {
                  LotsSELLm =  LotsSELLm + PositionGetDouble(POSITION_VOLUME);
                 }
           }
        }//End of for j
      Net_Lotsm = MathAbs(LotsBUYm - LotsSELLm);
{quote} string symbol_name = "GBPUSD"; // for example double LotsBUYm=0; double LotsSELLm=0; double Net_Lotsm=0; for(int j=0; j<=PositionsTotal()-1; j++) { if(!PositionSelectByTicket(PositionGetTicket(j))) { continue;//nếu chọn ko được lệnh n鄌 } if(StringFind(PositionGetString(POSITION_SYMBOL),symbol_name,0)>=0) { if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { LotsBUYm = LotsBUYm + PositionGetDouble(POSITION_VOLUME); } else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { LotsSELLm = LotsSELLm...

this is my code to calc lots for symbol - in this example to calc lot for full hedge :-)
using this classes - makes it easier to code
--
//Import inputal class
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\OrderInfo.mqh>
#include <Trade\DealInfo.mqh>
--

if (m_account.FreeMarginCheck(m_position.Symbol(), ORDER_TYPE_SELL, Lots, m_symbol.Bid()) < 0 || GetLastError() == 134 )
{
double sellLots = 0;
double buyLots = 0;
string tmpSymbol = m_position.Symbol();
long tmpMagic = m_position.Magic();

int count = PositionsTotal();

for (int i=count-1; i>=0; i--)
{
ResetLastError();

if (!m_position.SelectByIndex(i)) continue;

ulong ticket = m_position.Ticket();

if (ticket>0)
{
if( m_position.Symbol() == tmpSymbol
&&( m_position.PositionType() == POSITION_TYPE_SELL || m_position.PositionType() == POSITION_TYPE_SELL )
&&( m_position.Magic() == tmpMagic))
{
if( m_position.PositionType() == POSITION_TYPE_SELL )
{
buyLots = buyLots + m_position.Volume();
}
else
if( m_position.PositionType() == POSITION_TYPE_SELL )
{
sellLots = sellLots + m_position.Volume();
}
}
}
}

Lots = MathAbs(buyLots - sellLots);
{quote} this is my code to calc lots for symbol - in this example to calc lot for full hedge :-) using this classes - makes it easier to code -- //Import inputal class #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\AccountInfo.mqh> #include <Trade\OrderInfo.mqh> #include <Trade\DealInfo.mqh> -- if (m_account.FreeMarginCheck(m_position.Symbol(), ORDER_TYPE_SELL, Lots, m_symbol.Bid()) < 0 || GetLastError() == 134 ) { double sellLots = 0; double buyLots = 0; string tmpSymbol = m_position.Symbol();...
Thank you for sharing your code, Mucky.
I learned a lot.
{quote} string symbol_name = "GBPUSD"; // for example double LotsBUYm=0; double LotsSELLm=0; double Net_Lotsm=0; for(int j=0; j<=PositionsTotal()-1; j++) { if(!PositionSelectByTicket(PositionGetTicket(j))) { continue;//nếu chọn ko được lệnh n鄌 } if(StringFind(PositionGetString(POSITION_SYMBOL),symbol_name,0)>=0) { if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { LotsBUYm = LotsBUYm + PositionGetDouble(POSITION_VOLUME); } else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { LotsSELLm = LotsSELLm...
correct

therefore we emphasize : PositionGetTicket //// its counterprt in mt4 is OrderSelect (...., ....)
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 73 KB


what will happen if you do not use PositionGetTicket ?
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (6)
from phuclockbs code

you use to get lots:
PositionGetDouble(POSITION_VOLUME)
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 4 KB


you use to get order type: buy or sell:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 1 KB

then you comapred with plan balues:
and to get order symbol , you use:
PositionGetString
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 1 KB

---
therefore there are three finctions dealing with all order details, all start with word: POSITION
P0stionGetInteger
PositionGetDouble
PoistionGetString
question:
PositionSelectByTicket -- is it necessary?
?
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 2 KB
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
{quote} this is my code to calc lots for symbol - in this example to calc lot for full hedge :-) using this classes - makes it easier to code -- //Import inputal class #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\AccountInfo.mqh> #include <Trade\OrderInfo.mqh> #include <Trade\DealInfo.mqh> -- if (m_account.FreeMarginCheck(m_position.Symbol(), ORDER_TYPE_SELL, Lots, m_symbol.Bid()) < 0 || GetLastError() == 134 ) { double sellLots = 0; double buyLots = 0; string tmpSymbol = m_position.Symbol();...
yes
using OOP concepts make things better . .

i have compile your code "as it is" :

Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 35 KB

-
how to remove these errors ?
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
{quote} Thank you for sharing your code, Mucky. I learned a lot.
we had better make things simple (basics) . . . at this stage . .
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
MT5 basics (7)

mt5 order types . . . . there are 8 types ...
. . .

first let us build our buttons on teh chart --- to display output (instead of expert page)
here: mt4 and mt5 are the same !!
!
use this fuction:


Inserted Code
void Create_Button(string name,string text,  int X,   int Y,   int W,   int H,   int width,   color BackColor, color TextColor, color borderColor, string TOOL)
{
   ObjectDelete(0,name);
   ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,W);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,H);
   ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,X);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,Y);
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,width);
   ObjectSetString(0,name,OBJPROP_TOOLTIP,TOOL);
   ObjectSetInteger(0,  name,OBJPROP_BACK,false);
   ObjectSetInteger(0,  name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,  name,OBJPROP_SELECTED,false);
   ObjectSetInteger(0,  name,OBJPROP_BGCOLOR,BackColor);
   ObjectSetInteger(0,  name,OBJPROP_BORDER_COLOR,borderColor);
   ObjectSetInteger(0,  name,OBJPROP_COLOR,TextColor);
   ObjectSetString(0,   name,OBJPROP_TEXT,text);
}
to show something like this on the chart:
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 4 KB
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
Attached Image (click to enlarge)
Click to Enlarge

Name: screenshot.png
Size: 8 KB

try this broker ... easier to make demo accounts from terminal . .
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538
{quote} what will happen if you do not use PositionGetTicket ?
Do you mean PositionGetSymbol is another option?
Replacing:
Inserted Code
 if(!PositionSelectByTicket(PositionGetTicket(j)))
by
Inserted Code
if(PositionGetSymbol(j)=="")
then the new code is
Inserted Code
   string symbol_name = ChartSymbol(); // for example
   double LotsBUYm=0;
   double LotsSELLm=0;
   double Net_Lotsm=0;
   for(int j=0; j<=PositionsTotal()-1; j++)
     {
      /*
      if(!PositionSelectByTicket(PositionGetTicket(j)))
        {
         continue;//nếu chọn ko được lệnh n鄌
        }
      */
      
      if(PositionGetSymbol(j)=="")
        {
         continue;
        }
      
      if(StringFind(PositionGetString(POSITION_SYMBOL),symbol_name)>=0)
        {
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
           {
            LotsBUYm = LotsBUYm + PositionGetDouble(POSITION_VOLUME);
           }
         else
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
              {
               LotsSELLm =  LotsSELLm + PositionGetDouble(POSITION_VOLUME);
              }
        }
     }//End of for j
   Net_Lotsm = MathAbs(LotsBUYm - LotsSELLm);
   Print("Net_Lotsm = ", Net_Lotsm);
{quote} Do you mean PositionGetSymbol is another option? Replacing: if(!PositionSelectByTicket(PositionGetTicket(j))) by if(PositionGetSymbol(j)=="") then the new code is string symbol_name = ChartSymbol(); // for example double LotsBUYm=0; double LotsSELLm=0; double Net_Lotsm=0; for(int j=0; j<=PositionsTotal()-1; j++) { /* if(!PositionSelectByTicket(PositionGetTicket(j))) { continue;//nếu chọn ko được lệnh n鄌 } */ if(PositionGetSymbol(j)=="") { continue; } if(StringFind(PositionGetString(POSITION_SYMBOL),symbol_name)>=0)...
no
i mean can we or not dispense of first one in your code ?
or its presense is very important ?
?
each day 10%,,,, http://www.ojas-gujarat-gov-in.com/thread/1371538