+ Reply to Thread
Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Where is error ?

  1. #1
    Member
    Join Date
    Nov 2008
    Posts
    257

    Default Where is error ?

    I try this cod:


    if(usemnoznik)
    { prof=0;
    for(int i=0; i < OrdersTotal(); i++)
    {OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

    if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
    prof += OrderProfit();l=OrderLots();
    if (prof>myprofit || prof<(endloss*(-1))){CloseAll();}
    }

    if (prof<(startloss*(-1))) Lots=mnoznik*l;else Lots=startlot;


    }


    ......


    void CloseAll()
    {
    for(int cc=0;cc<OrdersTotal();cc++)
    {
    if(OrderType()==OP_BUY || OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
    {
    OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),10,CLR_NONE);
    return(0);
    }
    }
    }


    but it isn't close my open orders.
    I want close all open trades in that ea after profit > A or loss < B.But that part of code not working.
    if last open trade is in loss, next should be open with lot*mnoznik and this ok.
    can somebody look at this and advice ?
    as i see it close only last trade,not all
    how to do it ?
    Last edited by przem81621; 06-18-2009 at 12:33.

  2. #2
    Member
    Join Date
    Jun 2009
    Posts
    81

    Default Not sure if this will work

    The only thing I see that might cause problems is the logic in your 'if' statement:
    Code:
    if(OrderType()==OP_BUY || OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
    I would add parenthesis around the two OrderType() statements like this:
    Code:
    if((OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
    See if that helps.

    Paul

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Your problem is with the return(0); line in the CloseAll() function.

    It will return control back to the calling function after the first order has been closed. When it next loops around the calling function, the open profit will have changed because one of the orders will have been closed and the condition to close further orders will not be met.

    The Close() function is a void function which means that it returns zero anyway.

    I think you need to use the / key. It is the best key on the entire keyboard.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

+ Reply to Thread

Similar Threads

  1. Getting Error ')' Parameter expected
    By anand1268 in forum MQL programming
    Replies: 4
    Last Post: 05-16-2009, 07:33
  2. Change lots/multiplier to lots=0.01 gives OrderSend error 130?
    By sleepypipsCDN in forum MQL programming
    Replies: 7
    Last Post: 04-12-2009, 08:17
  3. Error for the EA that trade in the same hours everyday
    By alexlsy in forum MQL programming
    Replies: 1
    Last Post: 03-12-2009, 17:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts