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

Thread: Basket Profit/Loss Bug

  1. #1
    Member
    Join Date
    Jan 2009
    Posts
    97

    Question Basket Profit/Loss Bug

    Hi! I was testing the Basket Profit/Loss function and I found a bug.

    Example:

    Profit=10
    Loss=5

    When one of the those levels is reached the EA doesn't close all the traders, if you know how to correct it, please let me know, above you can check the code that I am using.

    extern bool UseProfitLoss=true;
    extern int BasketProfit=50;
    extern int BasketLoss=100;

    //Basket Profit/Loss
    if(UseProfitLoss)
    {
    CurrentBasket=AccountEquity()-AccountBalance();
    if(CurrentBasket >= BasketProfit || CurrentBasket <= (BasketLoss*(-1)))
    {
    NewOrders=false;
    CloseSellOrders(Magic);
    CloseBuyOrders(Magic);
    return(0);
    }
    }

    Thanks in advance!

  2. #2
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Without seeing what happens inside the CloseSellOrders() and CloseBuyOrders() functions, it is impossible to see what exactly is wrong.

    You must ensure that these two function close all open orders before passing control back to the originating function. If they return control back before everything is closed, then the close conditions will no longer be met and the EA will have no reason to close any of the remaining orders.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    97

    Smile

    Quote Originally Posted by jezzer1961 View Post
    Without seeing what happens inside the CloseSellOrders() and CloseBuyOrders() functions, it is impossible to see what exactly is wrong.

    You must ensure that these two function close all open orders before passing control back to the originating function. If they return control back before everything is closed, then the close conditions will no longer be met and the EA will have no reason to close any of the remaining orders.
    Thanks for reply and help! I found a very good Basket Profit/Loss code and , I am attaching an "EA" without any signal condition just for the people who need this function can take look at the code.

    Copyrights: I got the code of this "EA" from here and the Basket code here: Multi-purpose trade management ea @ Forex Factory *- I just changed very small things in the code.

    *I don't know if I can post a link from another forum, but if the admin doesn't allow it, please remove it.
    Attached Files

+ Reply to Thread

Similar Threads

  1. Best expert advisor with STOP LOSS
    By 823 in forum Expert advisors backtesting
    Replies: 7
    Last Post: 08-25-2011, 13:49
  2. Stopping the EA if the daily profit/loss reached
    By szmvscla in forum Ideas for expert advisors
    Replies: 0
    Last Post: 06-07-2009, 09:00
  3. Replies: 2
    Last Post: 05-25-2009, 16:59
  4. Stop Loss EA
    By delcor in forum Ideas for expert advisors
    Replies: 0
    Last Post: 05-15-2009, 15:25
  5. Add take profit and stop loss
    By funyoo in forum MQL programming
    Replies: 0
    Last Post: 09-23-2008, 10:32

Posting Permissions

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