Page 1 of 2 12 LastLast
Results 1 to 10 of 13
 0 Attachment(s)    

Thread: How to count all open trades for specific pair with magicnumber?

  1. #1

    Default How to count all open trades for specific pair with magicnumber?

    Hi Funyoo,

    Can you teach me the code if I want to count all open trades for a specific pair with specific Magic number?

    Thanks much
    Jidonk

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

    Default

    void CloseAllOrders()
    {

    bo=0;so=0;
    for(cnt=OrdersTotal();cnt>=0;cnt--)
    {
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    if (OrderSymbol()==Symbol() && OrderMagicNumber()== Reference)
    {
    if (OrderType()==OP_BUY )
    bo++;

    if (OrderType()==OP_SELL )

    so++;

    }

    }
    }
    }

  3. #3

    Default To COUNT not to Close

    Hi Perky_Z,

    Thanks for your help. But what I need is to COUNT all open trade not to Close all trades.

    I'm using:

    AllMyOrder = OrdersTotal();

    but it seems to count all open trades regardless the the pair/magic.


    Thanks
    Last edited by jidonk; 03-18-2009 at 20:11.

  4. #4

    Default

    Quote Originally Posted by jidonk View Post
    Hi Perky_Z,

    Thanks for your help. But what I need is to COUNT all open trade not to Close all trades.

    I'm using:

    AllMyOrder = OrdersTotal();

    but it seems to count all open trades regardless the the pair/magic.


    Thanks
    CloseAllOrders() is just the name that the function has been called (it's probably been cut'n'pasted from elsewhere), rather than what it actually does. You can rename it if you wish.

    The function will return a count of both open buy (this is the value bo) and open sell (this is the value so) orders.
    Last edited by jezzer1961; 03-18-2009 at 20:28.

  5. #5

    Default

    Thanks Jezzer,

    Will try...

    Rgds

  6. #6

    Default

    No problem. but bear in mind that, because it's been set out as a function as it has, you will need to call it somehow. Unless there's a need for it to be set out in that way, you may as well scrap the name together with the first left brace and the last right brace.

  7. #7

    Default

    Jezzer,

    I just can't make it works....

    Below is my code...

    on top:

    extern int Magic = 123;
    extern string SpecificPairs="EURUSD";
    extern double Lots = 0.1;
    extern int MaxTrade = 2;
    extern bool IncreaseLot = TRUE;

    then I put this:


    int order_total = 0;
    order_total = OrdersTotal();
    double addlot = 0;
    if (IncreaseLot) {
    if (order_total == 0) addlot = 0.0;
    if (order_total == 1) addlot = 0.1;
    if (order_total == 2) addlot = 0.2;

    then on OrderSend function I put Lots + addlot as the volume
    myticket = OrderSend(Symbol(), OP_SELL, Lots + addlot, Bid, 2,....etc


    Now, how can I change the code to works only with specific pair and magic?

    Thanks

  8. #8

    Default

    Quote Originally Posted by jidonk View Post
    Jezzer,

    Now, how can I change the code to works only with specific pair and magic?

    Thanks
    You aren't selecting any orders with your code. You need to follow Perky's instructions.

    Code:
    int order_total=0;
    for(int cnt=0;cnt<OrdersTotal();cnt++)
    {
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    if ((OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()== Magic) 
    {order_total++;}
    
    }
    That will return a count for order_total. You then just continue with the rest of your code.

  9. #9

    Default

    Awesome......problem solved!

    Thank you very much Jezzer

    Rgds

  10. #10

    Default Adding position after some floating loss

    Hi Jezzer,

    Hopefully you don't mind teaching me another one:

    for the EA to open another position ONLY when the previous position(s) are in a floating loss condition? I'm referring to dollar value of the loss, not based on pip step. (and still based on the specific pairs and magic)

    For example,
    if trade 1 is in -$10, then open trade 2
    if trade 1 & 2 are in -$30, then open trade 3, .....


    Thanks & Regards
    Last edited by jidonk; 03-19-2009 at 07:26.

Similar Threads

  1. Count trades on a certain bar
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 08-20-2014, 15:21
  2. Count historical trades on a certain bar
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 08-20-2014, 15:20
  3. Count all trades function
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 08-20-2014, 14:41
  4. I need an EA to open trades at a specific time
    By Johntrader in forum Scripts and other tools
    Replies: 0
    Last Post: 07-27-2012, 14:51
  5. Setting SL of all Trades on specific pairs
    By ixbone in forum MQL programming
    Replies: 9
    Last Post: 03-15-2009, 09:58

Tags for this Thread

change, eurusd, funyoo, how to, magic, magic number, 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
  •