Can anyone help me build this function into my strategy. And how can this be done? It would be nice to find an example. I know that there are custom blocks or custom functions, but it’s not clear how to use them.
double ClosedProfit()
{
uint totalNumberOfDeals = HistoryDealsTotal();
long orderType, dealEntry;
ulong tickerNumber =0;
double orderProfit =0;
double orderSwap =0;
double PositionHistoryProfit =0;
double CurrencyPairHistoryProfit =0;
string mySymbol ="";
string positionDirection ="";
string myResult ="";
HistorySelect(0,TimeCurrent());
for(uint i=0; i < totalNumberOfDeals; i++)
{
if((tickerNumber = HistoryDealGetTicket(i))>0)
{
if((tickerNumber = HistoryDealGetTicket(i))>0)
{
orderProfit = HistoryDealGetDouble(tickerNumber,DEAL_PROFIT);
orderSwap = HistoryDealGetDouble(tickerNumber,DEAL_SWAP);
orderType = HistoryDealGetInteger(tickerNumber,DEAL_TYPE);
mySymbol = HistoryDealGetString(tickerNumber,DEAL_SYMBOL);
dealEntry = HistoryDealGetInteger(tickerNumber,DEAL_ENTRY);
if(mySymbol == _Symbol)
if(orderType == ORDER_TYPE_BUY || orderType == ORDER_TYPE_SELL)
if(dealEntry == 1)
{
if(orderType == ORDER_TYPE_BUY)
positionDirection = "SELL";
if(orderType == ORDER_TYPE_SELL)
positionDirection = "BUY";
PositionHistoryProfit = orderProfit + orderSwap;
CurrencyPairHistoryProfit = NormalizeDouble(CurrencyPairHistoryProfit + PositionHistoryProfit, _Digits);
}
}
}
return CurrencyPairHistoryProfit;
}