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

Thread: Max trade per bar

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

    Default Max trade per bar

    Here is the "max trade per bar" enhanced.

    Just after the extern parameters, add :

    Code:
    extern int MaxTradePerBar=1;
    
    datetime Time0;int TradePerBar=0;int BarCount=-1;
    Then just after, add this :

    Code:
    int init(){Time0=Time[0];return(0);}
    int deinit(){return(0);}
    Add in-line, following each condition (buy and sell) :

    Code:
    &&(TradePerBar<=MaxTradePerBar)
    Just after the conditions :

    Code:
    if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;}
    Before each OrderSend function :

    Code:
    if(Time0!=Time[0]){
    After each OrderSend function :

    Code:
    Time0=Time[0];if(ticket>0)TradePerBar++;
    Don't forget the } at the end.

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

    Default

    An alternative :

    At the end of the expert, add :

    Code:
    bool NewBar()
    {
    if(PreviousBarTime<Time[0])
    {
    PreviousBarTime = Time[0];
    return(true);
    }
    
    return(false); // in case if - else statement is not executed
    }
    In the conditions, add :

    Code:
    &&NewBar()
    And finally, after the extern parameters, add :

    Code:
    datetime PreviousBarTime;

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

    Default

    do you have an example ea with maxbartrade code in it?

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

    Default

    Quote Originally Posted by pjay72 View Post
    do you have an example ea with maxbartrade code in it?
    Hi pjay72 and welcome,

    Here it is : http://www.tradingsystemforex.com/1115-post9.html

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

    Default Thanx

    Good lookin out Funyoo

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

    Default trade per bar

    Hi,

    I looking for a code. When my option is once order per bar "false", multiple trade per bar is. That is ok. I like what lots decreased from first order to last order. Is it possible? Sorry, my english is very poor. Thanks for all. Thanks funyoo. You understand me?

    JP

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

    Default

    Quote Originally Posted by jpsaltuc View Post
    Hi,

    I looking for a code. When my option is once order per bar "false", multiple trade per bar is. That is ok. I like what lots decreased from first order to last order. Is it possible? Sorry, my english is very poor. Thanks for all. Thanks funyoo. You understand me?

    JP
    Hi jpsaltuc and welcome,

    In the functions, add :

    Code:
    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);
    }
    Before the Buy OrderSend function, add :

    Code:
    ILots=Lots-CountOrders(OP_BUY,Magic)*DecreaseLots;
    Before the Sell OrderSend function, add :

    Code:
    ILots=Lots-CountOrders(OP_SELL,Magic)*DecreaseLots;
    Inline in each OrderSend function replace :

    Code:
    Lots
    By :

    Code:
    ILots
    After the extern parameters, add :

    Code:
    double ILots;
    In the extern parameters, Add :

    Code:
    extern double DecreaseLots=0.01;
    Also replace Magic by your magic number's name.

  8. #8
    Junior Member
    Join Date
    Mar 2009
    Posts
    11

    Default

    Genius. Thank you very much funyoo. I intent change the code, then comment you later.
    JP

  9. #9
    Junior Member
    Join Date
    Mar 2009
    Posts
    11

    Default help!

    Funyoo, i can not modify the code by my self . Please, can you help me? thanks in advance funyoo.
    Attached Files Attached Files

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

    Default

    Quote Originally Posted by funyoo View Post
    Here is the "max trade per bar" enhanced.

    Just after the extern parameters, add :

    Code:
    extern int MaxTradePerBar=1;
    
    datetime Time0;int TradePerBar=0;int BarCount=-1;
    Then just after, add this :

    Code:
    int init(){Time0=Time[0];return(0);}
    int deinit(){return(0);}
    Add in-line, following each condition (buy and sell) :

    Code:
    &&(TradePerBar<=MaxTradePerBar)
    Just after the conditions :

    Code:
    if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;}
    Before each OrderSend function :

    Code:
    if(Time0!=Time[0]){
    After each OrderSend function :

    Code:
    Time0=Time[0];if(ticket>0)TradePerBar++;
    Don't forget the } at the end.
    Hi funyoo,

    i wanted the code to use to max 3 orders per bar to open.
    EA opens but only one order.
    Should we use the program change?

    Thanks and Regards
    derumuro

    Sorry for my bad english !

Similar Threads

  1. Trade What You See, Not What You Think
    By forexmetal2015 in forum Trading discussion
    Replies: 0
    Last Post: 10-01-2012, 13:01
  2. Replies: 0
    Last Post: 10-02-2010, 10:10
  3. Replies: 0
    Last Post: 09-21-2010, 00:37
  4. 1 trade a day
    By thesecret25 in forum Ideas for expert advisors
    Replies: 15
    Last Post: 05-12-2009, 18:27

Tags for this Thread

add, change, expert, genius, indicator, magic, magic number, sells, signal, thank you, 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
  •