ClosedProfit() function
-
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;
} -
No mate because you would have gotten it on your 1st post, (you did get help on that post), call people like @roar without the need to duplicate threads. I am quite interested to see if we can use custom functions here, I don't think we can. As I said you can get all the needed info from pink blocks.
-
@RajVoCash you have a block "For each closed position", very simple to get the closed profit using that block and "modify variables". No need to use custom code.
Technically its possible to use custom functions by either
- Making a custom block in the studio
- Taking the inside part of the function (the stuff within {}) and putting that to custom mql block, and finally putting the result (that would normally be the "return" statement) into a standard fxdreema variable.
These 2 methods will be 50x more difficult than using the standard blocks, but youre welcome to try if you like making things difficult lol