Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Where is error ?

  1. #1

    Default Where is error ?

    I try this cod:

    { 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);

    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

    Default Not sure if this will work

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


  3. #3


    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.

Similar Threads

  1. Ex4 write error
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 12-04-2015, 18:47
  2. OrderClose error 138
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 02-11-2015, 20:39
  3. OrderSend error 134
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 02-11-2015, 20:39
  4. Error in checktime()?
    By Clearpaper in forum MQL programming
    Replies: 3
    Last Post: 08-19-2010, 16:32
  5. Error code 129
    By italiangoose in forum Scripts and other tools
    Replies: 1
    Last Post: 02-10-2010, 11:08

Tags for this Thread

color, profit

Posting Permissions

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