Results 1 to 4 of 4
 1 Attachment(s)    

Thread: How can i control MAXPIPS between next open trade ??

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    9

    Default How can i control MAXPIPS between next open trade ??

    hello funyoo

    first i`m enthused of your work here because i`m a beginner of programming MT4 and your forum helps very well to check some mt4 code .....thanks for this ...

    now i `have a problem and i hope you or anyone can help me :

    how can i program a for - loop(i think it`S the solution) to identify different pips of open orders and for next order ....
    example what my Ea should doing :

    i have added a indicator which only allowed example long trades (it`s the major trend ) now a second indicator open the first trade example at 1.3300 now if the trade go down and after it the second indicator switch to long the ea should be only open new trades example 20 pips before or behind 1.3300 (in this example 1.3280 or 1.3320)
    is this possible with a modul or function call??

    thanks for help

    best regards and thanks for your work here

    begu

  2. #2
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by begu View Post
    hello funyoo

    first i`m enthused of your work here because i`m a beginner of programming MT4 and your forum helps very well to check some mt4 code .....thanks for this ...

    now i `have a problem and i hope you or anyone can help me :

    how can i program a for - loop(i think it`S the solution) to identify different pips of open orders and for next order ....
    example what my Ea should doing :

    i have added a indicator which only allowed example long trades (it`s the major trend ) now a second indicator open the first trade example at 1.3300 now if the trade go down and after it the second indicator switch to long the ea should be only open new trades example 20 pips before or behind 1.3300 (in this example 1.3280 or 1.3320)
    is this possible with a modul or function call??

    thanks for help

    best regards and thanks for your work here

    begu
    Hi begu,

    In the functions, add :

    Code:
    //|---------count orders
    
    int CountOrders(int Type,int Magic)
    {
       int _CountOrd;
       _CountOrd=0;
       for(int i=0;i<OrdersTotal();i++)
       {
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderSymbol()==Symbol())
          {
             if((OrderType()==Type&&(OrderMagicNumber()==Magic)||Magic==0))_CountOrd++;
          }
       }
       return(_CountOrd);
    }
    In the short signal conditions, add :

    Code:
     && ((CountOrders(OP_SELL,Magic)==0) || (CountOrders(OP_SELL,Magic)>0 && ((Bid<=(LastSellOpenPrice-MarginPips*Point))||(Bid>=(LastSellOpenPrice+MarginPips*Point)))))
    In the long signal conditions, add :

    Code:
     && ((CountOrders(OP_BUY,Magic)==0) || (CountOrders(OP_BUY,Magic)>0 && ((Ask>=(LastBuyOpenPrice+MarginPips*Point))||(Ask<=(LastBuyOpenPrice-MarginPips*Point)))))
    Before the signal conditions, add :

    Code:
          double LastBuyOpenPrice=0;
          double LastSellOpenPrice=0;
          int BuyOpenPosition=0;
          int SellOpenPosition=0;
          int TotalOpenPosition=0;
          int cnt=0;
    
          for(cnt=0;cnt<OrdersTotal();cnt++) 
          {
             OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
             if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic&&OrderCloseTime()==0) 
             {
                TotalOpenPosition++;
                if(OrderType()==OP_BUY) 
                {
                   BuyOpenPosition++;
                   LastBuyOpenPrice=OrderOpenPrice();
                }
                if(OrderType()==OP_SELL) 
                {
                   SellOpenPosition++;
                   LastSellOpenPrice=OrderOpenPrice();
                }
             }
          }
    In the extern parameters, add :

    Code:
    extern double MarginPips=10;

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    9

    Default

    hello funyoo

    thanks for your quick answer und help ......

    it`s perfect ..

    best regards

    begu

  4. #4

    Default

    Hi Funyoo,

    Attached is a simple EA I made for learning sake, mostly got the codes (copy & paste) from this forum. Thanks to you and Jezzer for that.

    First, could you pls check the EA and make corrections if any?

    Secondly, I tried to add this "MAXPIPS" code on this thread to my EA, but seems to screw up everything. So could you please inserting them to my EA? A little bit different than Begu request, I want it to open BUY only when the Ask price is below lastbuyopenprice (NOT when the price is higher).

    Thanks a lot

    Regards,
    Jdk
    Attached Files Attached Files
    Last edited by jidonk; 04-04-2009 at 23:44. Reason: wrong attachement

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2011, 21:22
  2. Replies: 0
    Last Post: 10-02-2010, 10:10
  3. Open trade on arrow
    By altoronto in forum MQL programming
    Replies: 3
    Last Post: 08-11-2009, 15:22
  4. Busy open trade
    By przem81621 in forum MQL programming
    Replies: 0
    Last Post: 05-08-2009, 22:24
  5. Open Trade Question
    By altoronto in forum MQL programming
    Replies: 4
    Last Post: 04-14-2009, 21:54

Tags for this Thread

beginner, copy, indicator, magic, mt4, pips, programming, request, signal, simple, trend

Posting Permissions

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