Not logged in

Forums

Viewing 1 post (of 1 total)

Forums>EA Wizard>Strategy Samples>Sum Open Profit Long/Short for Specified Symbol

  • #117426 |
    Moderator
    2349 Posts

    If you need to get current open profit for specified symbol you can use the following function in EA WIzard

     

    1) add custom code into CustomFunction.mq4 placed in Wizard folder

    float sumOpenProfit(string direction, string symbolString) {
       float totalProfit = 0;
       for(int i=OrdersTotal()-1; i>=0; i--) {
          if (OrderSelect(i,SELECT_BY_POS)==true) {
             
             if (direction == "LONG" && symbolString != "" && OrderType() == OP_BUY && OrderSymbol() == symbolString) {
                totalProfit += OrderProfit();
             }
             
             else if (direction == "LONG" && symbolString == "" && OrderType() == OP_BUY) {
                totalProfit += OrderProfit();
             }
             else if (direction == "SHORT" && symbolString != "" && OrderType() == OP_SELL && OrderSymbol() == symbolString) {
                totalProfit += OrderProfit();
             }
             
             else if (direction == "SHORT" && symbolString == "" && OrderType() == OP_SELL) {
                totalProfit += OrderProfit();
             }
          }
       }
       return totalProfit;
    }
    

    2) add CustomAction like this in Wizard

     

    Get open P/L from longs in EURUSD

    sumOpenProfit("LONG", "EURUSD");
    

    or

     

    get open P/L for all shorts active

    sumOpenProfit("SHORT", "")
    

    example EA is attached

    Attachments in this forum are visible only for registered users.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.