+ Reply to Thread
Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Error for the EA that trade in the same hours everyday

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

    Default Error for the EA that trade in the same hours everyday

    Hi all,

    Please help to check the below code, is there any error if I want to make this EA to put in a pending order at the same time everyday? I have tried to run the strategy tester, but end up it don't trade a single trade for 3 years period!!! I believe something wrong inside.

    Concept for this EA is:
    1. put the pending order for Buy stop and Sell stop at GMT5:59, anyone of them trigger, the other one will be deleted, and put down the expiration for them if they still haven't reach the SL or TP at GMT06:59.
    2. The Entry point for the Buy stop is the Highest close value between the current and previous bar, mean bar for GMT4 and GMT5, the Entry point for the Sell stop is the Lowest clost value between the current and the previous bar also.
    3. If the different for the Highest and the Lowest is more than 70 pips, then dun put the pending order.

    Please help to check any error or the improvement for the programming inside.
    *This program is actually modified from a program call 21hours, however it can't be work after i adjusted the entry point and time entry.

    Thanks.

    //------------------------------------------------------
    extern double Lots = 0.1;
    extern int ChasStartH = 05;
    extern int ChasStartM = 59;
    extern int ChasStopH = 06;
    extern int ChasStopM = 59;
    extern int SL = 40; //Stop Loss
    extern int TP = 100; //Take profit
    extern double BuyEP; //Entry point for Buy order
    extern double SellEP; //Entry point for Sell order

    int prevtime;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //----

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start()
    {
    //----





    int OrderCountOtl=0;
    int i=0;
    int total = OrdersTotal();
    for(i = 0; i <= total; i++)
    {

    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderMagicNumber() == 12321)
    {
    if (OrderType()>1) OrderCountOtl++;
    }

    }

    if (OrderCountOtl==1)
    {
    for(i = 0; i <= total; i++)
    {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderMagicNumber() == 12321)
    {
    if (OrderType()>1) OrderDelete(OrderTicket());
    }
    }
    }


    if(Time[0] == prevtime)
    return(0);
    prevtime = Time[0];
    if(!IsTradeAllowed())
    {
    prevtime = Time[1];
    return(0);
    }



    if (TimeHour(TimeCurrent())==ChasStartH && TimeMinute(TimeCurrent())==ChasStartM)
    {
    If (High[1]>High[0])
    {
    BuyEP = High[1];
    }
    If (High[1]<High[0])
    {
    BuyEP = High[0];
    }
    If (Low[1]<Low[0])
    {
    SellEP = Low[1];
    }
    If (Low[1]>Low[0])
    {
    SellEP = Low[0];
    }
    If (BuyEP-SellEP)>70*Point
    {
    return(0);
    }
    OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyEP,2,Ask-SL*Point,Ask+TP*Point,"",12321,0,Green);
    OrderSend(Symbol(),OP_SELLSTOP,Lots,SellEP,2,Bid+S L*Point,Bid- TP*Point,"",12321,0,Red);
    }

    if (TimeHour(TimeCurrent())==ChasStopH && TimeMinute(TimeCurrent())==ChasStopM)
    {
    i=0;
    total = OrdersTotal();
    for(i = 0; i <= total; i++)
    {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderMagicNumber() == 12321)
    {
    if (OrderType()==OP_BUY)OrderClose(OrderTicket(),Orde rLots(),Bid,2,Green);
    if (OrderType()==OP_SELL)OrderClose(OrderTicket(),Ord erLots(),Ask,2,Green);
    if (OrderType()>1)OrderDelete(OrderTicket());
    }
    }
    }

    //----
    return(0);
    }

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

    Default Some admentment do inside

    Have done some mistake inside, here is the updated changes for the ordersend.

    OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyEP+4*Point,3 ,BuyEP+(4-SL)*Point,BuyEP+(4+TP)*Point,"",12321,0,Green);
    OrderSend(Symbol(),OP_SELLSTOP,Lots,SellEP-4*Point,3,SellEP-(4-SL)*Point,SellEP-(4+TP)*Point,"",12321,0,Red)

    Anyone can help?

+ Reply to Thread

Similar Threads

  1. Getting Error ')' Parameter expected
    By anand1268 in forum MQL programming
    Replies: 4
    Last Post: 05-16-2009, 07:33
  2. 1 trade a day
    By thesecret25 in forum Ideas for expert advisors
    Replies: 15
    Last Post: 05-12-2009, 17:27
  3. Two Hours EA
    By funyoo in forum Expert advisors backtesting
    Replies: 0
    Last Post: 04-17-2009, 18:00
  4. Change lots/multiplier to lots=0.01 gives OrderSend error 130?
    By sleepypipsCDN in forum MQL programming
    Replies: 7
    Last Post: 04-12-2009, 08:17
  5. Trading to certain days and hours
    By HiwayNZ in forum MQL programming
    Replies: 1
    Last Post: 02-08-2009, 17:08

Posting Permissions

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