Not logged in
Viewing 2 posts - 1 through 2 (of 2 total)
  • #266917 |
    Participant
    1 Posts

    I want to interrupt the orders when the ea reaches a certain profit and I saw the code below in another message on the forum:

    double sqGetPLInPipsToday() {
    string todayTime = TimeToStr( TimeCurrent(), TIME_DATE);
    double plToday = 0;

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

    if(OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) {
    // skip pending orders
    continue;
    }

    if(TimeToStr( OrderOpenTime(), TIME_DATE) == todayTime) {
    Log(“Comparing “, TimeToStr( OrderOpenTime(), TIME_DATE), ” = “, todayTime);
    if(OrderType() == OP_BUY) {
    plToday += OrderClosePrice() – OrderOpenPrice();
    } else {
    plToday += OrderOpenPrice() – OrderClosePrice();
    }
    }
    }
    }

    for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
    if (OrderSelect(cc, SELECT_BY_POS) && OrderSymbol() == Symbol()) {

    if(OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) {
    // skip pending orders
    continue;
    }

    if(TimeToStr( OrderOpenTime(), TIME_DATE) == todayTime) {
    if(OrderType() == OP_BUY) {
    plToday += sqGetBid(OrderSymbol()) – OrderOpenPrice();
    } else {
    plToday += OrderOpenPrice() – sqGetAsk(OrderSymbol());
    }
    }
    }
    }

    return (plToday*gPointPow);
    }

    However, when I try to insert the code below in the line of codes generated in AlgoWizard, I get the following error message:

    ‘gPointPow’ – undeclared identifier

    How do I fix this error? Do I need to add anything?

    #267302
    tomas262
    Administrator
    1822 Posts

    Hello,

    do you try to get Daily P/L values? It can obtained easily by subtracting AccountEquity() minus previous day’s AccountEquity() or if you run mutliple EAs using different magic number you can use this code

    double Total_profit= NULL;int cnt = NULL;
    for(cnt=0;cnt<=OrdersTotal();cnt++){
    OrderSelect(cnt,SELECT_BY_POS);
    if(OrderSymbol() == Symbol() && OrderMagicNumber()==magic)
    {if( OrderType() == OP_BUY || OrderType() == OP_SELL )
    {Total_profit= Total_profit+ OrderProfit() + OrderSwap() + OrderCommission();}
    }
    }

    Let me know if you need any help with this

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

You must be logged in to reply to this topic.