Not logged in
Viewing 7 posts - 1 through 7 (of 7 total)

Forums>AlgoWizard / EA Wizard>Application Support>Referencing long & short closed trades together

  • #203095 |
    Participant
    16 Posts

    Hello, thank you for such an excellent program.

     

    I want to obtain total profit from last x-number of trades, long and short combined.

    If I separate the longs and the shorts with magic numbers, won’t that give me totals for last x long trades and last x short trades, which is not the same as last x trades combined?

    If I use zero as magic number, won’t that include trades of other EAs of the same currency pair running on the platform?

    How do I solve this? I have other problems related to this type of issue, this is one example of the problem.

    #203217
    tomas262
    Administrator
    1826 Posts

    Hello,

    in EA Wizard you can use Sum Of Closed PL to check longs only / shorts only having the same magics for all longs or all shorts. If you use magic = 0 it will count orders across all pairs traded not only one you place your EA on

    #203230
    Participant
    16 Posts

    Hi Thomas,

    Thanks for your reply.

    So to confirm: I simply cannot derive profit/loss over a certain number of trades, regardless of trade direction??

    This would seem an unfortunate limitation. As I mention above, this question is one example of a bigger issue. If magic = 0 cannot contain itself to only the EA in question, then surely we need a function that allows

    magicLong AND magicShort or magicLong OR magicShort?

    #203403
    tomas262
    Administrator
    1826 Posts

    To obtain total profits of # of historical trades you can do this function (place at the end of EAWizard \ code \ CustomFunction.mq4)

    int sqGetTotalPL(int numberOfLastOrders) {
    double pl = 0;
    int count = 0;
    int profits = 0;

    for(int i=OrdersHistoryTotal(); i>=0; i–) {
    if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true && OrderSymbol() == Symbol()) {

    count++;

    if(OrderType() == OP_BUY) {
    pl = (OrderClosePrice() – OrderOpenPrice());
    } else {
    pl = (OrderOpenPrice() – OrderClosePrice());
    }

    if(pl > 0) {
    profits++;
    }

    if(count >= numberOfLastOrders) break;
    }
    }

    return(profits);
    }

    You can then reference it using Custom Function functionality in EA Wizard using call “sqGetTotalPL(3)” to obtain P/L for last 3 trades on a selected symbol

    #203693
    Participant
    16 Posts

    Hi Tomas,

     

    Thank you very for that – I appreciate the time it must take. As I read through the code (keeping in mind that I can’t read code), will this give me a result only for the EA it is included in, and not all results for the pair (OrderSymbol) in the MT4 history?  I am trying to isolate the profit/loss over a number of trades within a specific EA, even though other EAs are running on the same pair on the same platform.

     

    Thanks again for your help.

     

    #203816
    tomas262
    Administrator
    1826 Posts

    Hello,

    this statement in the code OrderSymbol() == Symbol() ensures that it will give you results only for the symbol you run your EA on for example EURUSD

    #217747
    Participant
    16 Posts

    Thanks Tomas!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.