How to start with MQL5 - page 31

 

New Project 'Andromeda Nebula' is already running (version 1.002).

 
Vladimir Karputov #:

New Project 'Andromeda Nebula'

How to join the project

In MetaEditor, in the "Tools" window, go to the "Public Projects" tab, in the "Name" column on the "AlligatorAndStochastic" project, right click and select the "Join" item


Thanks a million. I eventually found a way around it focusing on Equity drawdown as my variable. I really appreciate your assistance and will not hesitate to engage you, or any other available programmer in case you were extremely busy when required, for paid project if/when I have anyone I cannot code by myself.

 

Check: is it allowed to use 'Close By' on the symbol or is it forbidden?

Code: 'Check SYMBOL_ORDER_MODE.mq5'

This script can be modified and leave only the lines you need.

//+------------------------------------------------------------------+
//|                                      Check SYMBOL_ORDER_MODE.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
//---
int symboll_order_types[7]= {SYMBOL_ORDER_MARKET,
                             SYMBOL_ORDER_LIMIT,
                             SYMBOL_ORDER_STOP,
                             SYMBOL_ORDER_STOP_LIMIT,
                             SYMBOL_ORDER_SL,
                             SYMBOL_ORDER_TP,
                             SYMBOL_ORDER_CLOSEBY
                            };
string symboll_order_description[7]= {"Market orders",
                                      "Limit orders",
                                      "Stop orders",
                                      "Stop-limit orders",
                                      "Stop Loss",
                                      "Take Profit",
                                      "Close By operations"
                                     };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int i=0; i<7; i++)
     {
      if(IsOrderTypesAllowed(Symbol(),symboll_order_types[i]))
         Print(Symbol()," ",symboll_order_description[i]," allowed");
      else
         Print(Symbol()," ",symboll_order_description[i]," prohibited");
     }
  }
//+------------------------------------------------------------------+
//| Check if a order types is allowed                                |
//+------------------------------------------------------------------+
bool IsOrderTypesAllowed(string symbol,int order_type)
  {
//--- receive the value of the property describing allowed order types
   int symbol_order_mode=(int)SymbolInfoInteger(symbol,SYMBOL_ORDER_MODE);
//--- return 'true' if the order_type is allowed
   return((symbol_order_mode&order_type)==order_type);
  }
//+------------------------------------------------------------------+

Here is an example of launching on two symbols: on one symbol all order types are allowed,

        EURUSD Market orders allowed
        EURUSD Limit orders allowed
        EURUSD Stop orders allowed
        EURUSD Stop-limit orders allowed
        EURUSD Stop Loss allowed
        EURUSD Take Profit allowed
        EURUSD Close By operations allowed

but on the other 'Close By' is prohibited:

        EURUSD_closeby Market orders allowed
        EURUSD_closeby Limit orders allowed
        EURUSD_closeby Stop orders allowed
        EURUSD_closeby Stop-limit orders allowed
        EURUSD_closeby Stop Loss allowed
        EURUSD_closeby Take Profit allowed
        EURUSD_closeby Close By operations prohibited
 

if you please how to calculate order commision with profit to be like this

" Profit += profit + swap + commision "

 
diamondiptv # :

if you please how to calculate order commision with profit to be like this

" Profit += profit + swap + commision "

Example for positions:

//+------------------------------------------------------------------+
//| Profit all positions                                             |
//+------------------------------------------------------------------+
double ProfitAllPositions(void)
  {
   double profit=0.0;
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
            profit+=m_position.Commission()+m_position.Swap()+m_position.Profit();
//---
   return(profit);
  }

CPositionInfo Trade class used  

Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo
Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo
  • www.mql5.com
CPositionInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

Example for positions:

CPositionInfo Trade class used  

i used this class everything is ok except commission

can you check my code please

double SymbolProfit()
  {
   double ProfitSymbol = 0.0;
     for(int i=PositionsTotal()-1; i>=0; i--)
        {
         string CurrencySymbol = PositionGetSymbol(i);
      
         if(Symbol() == CurrencySymbol)
           {
            double PosProfit = MyPosition.Profit();
            double PosSwap = MyPosition.Swap();
            double PosCommision = MyPosition.Commission();
         
            ProfitSymbol += PosProfit + PosSwap + PosCommision;
           } 
        }   
   return ProfitSymbol;     
  }

note: my broker count commision at tow side one when open and other when close

 
diamondiptv # :

i used this class everything is ok except commission

can you check my code please

note: my broker count commision at tow side one when open and other when close

In this case, you need to work with trade history - you need to make a request for historical trades. Please note: until the position is closed, you will not know the full commission.

For example like this:

//+------------------------------------------------------------------+
//| Profit for the period                                            |
//+------------------------------------------------------------------+
double ProfitForPeriod(const datetime from_date,const datetime to_date)
  {
   double result=0.0;
//--- request trade history
   HistorySelect(from_date,to_date);
//---
   uint     total=HistoryDealsTotal();
   ulong    ticket=0;
   long     position_id=0;
//--- for all deals
   for(uint i=0; i<total; i++) // for(uint i=0;i<total;i++) => i #0 - 2016, i #1045 - 2017
     {
      //--- try to get deals ticket
      if((ticket=HistoryDealGetTicket(i))>0)
        {
         //--- get deals properties
         long deal_type          =HistoryDealGetInteger(ticket,DEAL_TYPE);
         long deal_entry         =HistoryDealGetInteger(ticket,DEAL_ENTRY);
         long deal_magic         =HistoryDealGetInteger(ticket,DEAL_MAGIC);
         double deal_commission  =HistoryDealGetDouble(ticket,DEAL_COMMISSION);
         double deal_swap        =HistoryDealGetDouble(ticket,DEAL_SWAP);
         double deal_profit      =HistoryDealGetDouble(ticket,DEAL_PROFIT);
         string deal_symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
         //--- only for current symbol and magic
         if(deal_magic==InpMagic && deal_symbol==m_symbol.Name())
               if(ENUM_DEAL_TYPE(deal_type)==DEAL_TYPE_BUY || ENUM_DEAL_TYPE(deal_type)==DEAL_TYPE_SELL)
                  result+=(deal_commission+deal_swap+deal_profit);
        }
     }
//---
   return(result);
  }
 
Vladimir Karputov #:

In this case, you need to work with trade history - you need to make a request for historical trades. Please note: until the position is closed, you will not know the full commission.

For example like this:

i really appreciate your help thank you

i will explane an example and correct me if i am wrong

i opened an order at EURUSD with 1 Lot first commision at opening is 2.32$ after close the same commision 2.32$ so now total commision is 4.64$

when i code profit counting can i make commision * 2 or not ?

and use this

ProfitSymbol += PosProfit + PosSwap + PosCommision*2;

instead of use history

 
diamondiptv # :

i really appreciate your help thank you

i will explane an example and correct me if i am wrong

i opened an order at EURUSD with 1 Lot first commision at opening is 2.32$ after close the same commision 2.32$ so now total commision is 4.64$

when i code profit counting can i make commision * 2 or not ?

and use this

instead of use history

Show the "trade" tab of your terminal - I'm interested in what you write in the "Commission" column.

 
Vladimir Karputov #:

Show the "trade" tab of your terminal - I'm interested in what you write in the "Commission" column.

Here is my screenshot example for GBPUSD every position total charges 0.10 at opening 0.05 and after close another 0.05