Results 1 to 6 of 6
 0 Attachment(s)    

Thread: How can I let the EA doesn't open a new positon in the same pair?

  1. #1

    Question How can I let the EA doesn't open a new positon in the same pair?

    Hi! I would like to know how I can let the EA doesn't open a new position in the same pair after it already traded the pair.

    Example:

    EA sold EU - SL = 30 - TP = 20 - If the TP or SL is hit - The EA will not open a new position for the pair until a new restart/loading of the MT4 platform.

    Thanks a lot for any help!

  2. #2

    Default Use a startup section

    If I have code that needs to run in the main start() routine but I only want it to run once I use a boolean variable that I set in init(). For example:

    Code:
    bool startup;
    
    int init(){
       startup=true;
    }
    
    int start(){
       if(startup){
    
          //open your trade here.
    
          startup=false;
       }
    }
    startup will only run once when MQL4 is initiated. Does that help??

    Paul

  3. #3

    Question

    Quote Originally Posted by ppentz View Post
    If I have code that needs to run in the main start() routine but I only want it to run once I use a boolean variable that I set in init(). For example:

    Code:
    bool startup;
    
    int init(){
       startup=true;
    }
    
    int start(){
       if(startup){
    
          //open your trade here.
    
          startup=false;
       }
    }
    startup will only run once when MQL4 is initiated. Does that help??

    Paul
    Thanks a lot, just one question, do I need to write the whole code in the StartUp function?

  4. #4

    Default

    Honestly I'm not sure. I've never tried to open a trade in init(), but I think it has to be in start(). You can always try it in init() and if it doesn't work, move it to start!

  5. #5

    Default

    One approach would be to log a date/time stamp on initialisation.

    At the top of the start() function you would count the orders in both the history pool and the trades pool.

    Then, if the order count from the history pool >=1 and the order open time was later than your timestamp and the order count from the trades pool = 0, you get the EA to return(0).

    When you restart the EA, the timestamp would be newer than it was when the EA was last run and the open time of all the history orders would be prior to that time so it would then open new trades.

  6. #6
    Junior Member
    Join Date
    Mar 2009
    Posts
    3

    Default

    Quote Originally Posted by szmvscla View Post
    Hi! I would like to know how I can let the EA doesn't open a new position in the same pair after it already traded the pair.

    Example:

    EA sold EU - SL = 30 - TP = 20 - If the TP or SL is hit - The EA will not open a new position for the pair until a new restart/loading of the MT4 platform.

    Thanks a lot for any help!


    I got around this with an EA that I wrote, but putting a time out feature of 360 minutes in my EA.

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2011, 21:22
  2. Replies: 1
    Last Post: 03-05-2011, 20:03
  3. Replies: 0
    Last Post: 02-23-2011, 13:56
  4. Expert doesn't open orders
    By jolimoney in forum MQL programming
    Replies: 0
    Last Post: 01-18-2010, 10:46
  5. Replies: 12
    Last Post: 03-19-2009, 19:28

Tags for this Thread

main, mql, mt4, time

Posting Permissions

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