Initial commit: MQL5 Scripts Collection (MetaTrader 5)

This commit is contained in:
GeneralTradingSarl
2025-06-24 00:33:04 +01:00
commit 60a549d89c
1959 changed files with 31907 additions and 0 deletions
@@ -0,0 +1,20 @@
# 🚀 Unlock the Power of Trading!
Welcome to this open-source trading project. Here you will find powerful tools to enhance your trading journey. If you find this project useful, please consider starring ⭐, sharing, or donating to support further development!
---
**Support the project:**
- Star this repository on GitHub
- Share it with your trading friends
- [Donate here](https://www.paypal.com/donate/?hosted_button_id=YOUR_BUTTON_ID) to help us grow!
---
![Screenshot](library.png)
![Screenshot](script.png)
## Source Files
- `get_last_history.mq5`
---
> Made with ❤️ for the trading community.
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1,89 @@
//+------------------------------------------------------------------+
//| Get Last History.mq5 |
//| Developed by Donald Reeves Sihombing |
//| https://www.mql5.com/en/users/dspro |
//| 20200925 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.00"
input ulong m_magic = 0; // Magic Number
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
long dtype;
double dprofit;
GetLastHistory(dtype,dprofit);
}
//+------------------------------------------------------------------+
void GetLastHistory(long& dtype, double& dprofit)
{
//get the history data
if(!HistorySelect(0,TimeCurrent()))
{
Print("__FUNCTION__ "+__FUNCTION__+", Failed to select History");
return;
}
uint total = HistoryDealsTotal();
ulong dticket = 0;
datetime dtime = 0;
string dsymbol;
double dprice = 0;
double dfee=0, dswap=0, dcommission=0;
long dealentry;
ulong dmagic = 0;
string dealtype = "";
for(uint i=total-1; i>=0; i--) //start from the last history
{
dticket = HistoryDealGetTicket(i);
if(dticket<=0)
continue;
//check the symbol
dsymbol = HistoryDealGetString(dticket,DEAL_SYMBOL);
if(dsymbol!=Symbol())
continue;
//check deal entry
dealentry = HistoryDealGetInteger(dticket,DEAL_ENTRY);
if(dealentry!=DEAL_ENTRY_OUT) //position closed
continue;
//check magic number
dmagic = HistoryDealGetInteger(dticket,DEAL_MAGIC);
if(dmagic!=m_magic)
continue;
//deal type must be buy or sell
dtype = HistoryDealGetInteger(dticket,DEAL_TYPE);
if(dtype!=DEAL_TYPE_BUY && dtype!=DEAL_TYPE_SELL)
continue;
dealtype = "Buy";
if(dtype==DEAL_TYPE_BUY) //if a position closed by Buy, then the original is Sell
dealtype = "Sell";
dprice = HistoryDealGetDouble(dticket,DEAL_PRICE); //close price, because we get the DEAL_ENTRY_OUT
dprofit = HistoryDealGetDouble(dticket,DEAL_PROFIT);
dfee = HistoryDealGetDouble(dticket,DEAL_FEE);
dswap = HistoryDealGetDouble(dticket,DEAL_SWAP);
dcommission = HistoryDealGetDouble(dticket,DEAL_COMMISSION);
dtime = (datetime)HistoryDealGetInteger(dticket,DEAL_TIME); //close time
break; //after get the last history, exit the loop
}
Comment("tot hist = ",total,
"\nticket = ",dticket,
"\nprice = ",dprice,
"\nprofit = ",dprofit,
"\nfee = ",dfee,
"\nswap = ",dswap,
"\ncommission = ",dcommission,
"\nsymbol = ",dsymbol,
"\ntype = ",dealtype,
"\ntime = ",dtime);
}
//+------------------------------------------------------------------+
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB