I can Sell , but cant Buy with same settings

 

Hello,

I have downloaded the following EA and modified it as i intend to trade, but there is a problem ...

extern bool    OpenBuy     = true;
extern bool    OpenSell    = false;

With this settings, it doesnt open a Buy position, But if i change to false and Sell to true, it does work... with the same time and date ... ( with the Strategy Testing )

Here is my Code:

//+------------------------------------------------------------------+
//|                                                  TimeBasedEA.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//changed by:       "forex4capital@yahoo.ca"
//change again by: madmax3

// Time frame: M5 and higher

extern int     MagicNumber = 20080122;
extern double DistancefromAsk;
extern double DistancefromBid;
extern double  TakeProfit  = 500;
extern double  StopLoss    = 250;
extern double  Lots        = 1;
extern double  StartDay    = 13;
extern double  StartHour   = 09;
extern double  StartMinute = 00;
extern double  StartSeconds= 00;
extern bool    OpenBuy     = false;
extern bool    OpenSell    = true;
extern int     NumBuys     = 1;
extern int     NumSells    = 1;
extern int     Slippage    = 2;

//+-----------------------------------------------------------------+
//|                        S T A R T                                 |
//+------------------------------------------------------------------+
int start()
  {
   int cnt, ticket, total;
  
//-------------------------------------+
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
//-------------------------------------+
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
//-------------------------------------+
  
   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(StartDay==Day() && StartHour==Hour() && StartMinute==Minute() && StartSeconds<=Seconds() && Close[1]>Open[1] && OpenBuy)
      //if(ct == StartHour && High[1]<Open[0] && OpenBuy)
        {
         for ( cnt = 0; cnt < NumBuys; cnt++)
         {
           ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask+(DistancefromAsk*Point),Slippage,0,0,"",MagicNumber,0,CLR_NONE);
         Sleep(10000);
           if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
            {
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderOpenPrice()+TakeProfit*Point, 0,Yellow);
           }
           }
            
          
         }
         return; 
        }
      // check for short position (SELL) possibility
      if(StartDay==Day() && StartHour==Hour() && StartMinute==Minute() && StartSeconds<=Seconds() && Close[1]<Open[1] && OpenSell)
      //if(ct == StartHour && Low[1]>Open[0] && OpenSell)
        {
         for ( cnt = 0; cnt < NumSells; cnt++)
         {
           ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"",MagicNumber,0,CLR_NONE);
           Sleep(10000);
           if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
            {
             OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point,OrderOpenPrice()-TakeProfit*Point, 0,Yellow);
             }
           }
           
         } 
         return; 
        }
     }
   return(0);
  }
// the end.

What could be the problem here ? i cant get it ... its so wierd ..

Thanks

EDIT: and one more thing, why in the script there is // Time frame: M5 and higher, what is the difference if i apply it to 1m chart and not 5m with Live account ?

 
Leopardos:

Hello,

I have downloaded the following EA and modified it as i intend to trade, but there is a problem ...

With this settings, it doesnt open a Buy position, But if i change to false and Sell to true, it does work... with the same time and date ... ( with the Strategy Testing )

Here is my Code:

What could be the problem here ? i cant get it ... its so wierd ..

Thanks

EDIT: and one more thing, why in the script there is // Time frame: M5 and higher, what is the difference if i apply it to 1m chart and not 5m with Live account ?


Why do you use seconds in strategietester ?

   total=OrdersTotal();
   if(total<1) 

Haven't you read other topics that this is a wrong method in live trading?

if(StartDay==Day() && StartHour==Hour() && StartMinute==Minute()/* && StartSeconds<=Seconds()*/ && Close[1]>Open[1] && OpenBuy)
 
deVries:


Why do you use seconds in strategietester ?

Haven't you read other topics that this is a wrong method in live trading?


I didnt to be honest, im still newbe ...
So, i will remove the seconds ...

But what is

total=OrdersTotal();
   if(total<1) 

what to do with this ?

Thanks again

 
  1. total=OrdersTotal();
    means the EA in incompatible with every other, including itself on other chart and manual trading.
    int total=0;
        for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
        &&  OrderMagicNumber()  == Magic.Number                 // my magic number
        &&  OrderSymbol()       == chart.symbol                 // and my pair.
        ){  total++; }
    if(total<1) ...
    

  2. Compare your two ordersends.
    ticket=OrderSend(Symbol(),OP_BUY, Lots,Ask+(DistancefromAsk*Point),Slippage,0,0,"",MagicNumber,0,CLR_NONE);
    ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,                        Slippage,0,0,"",MagicNumber,0,CLR_NONE);
    You can't open a buy EXCEPT at the Ask.

  3. Had you tested your return code you would have found out WHY. Adjust for 4/5 digit brokers, tp, sl AND SLIPPAGE.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){                                                     OptParameters();
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
           Alert("OrderModify failed: ", GetLastError());
         */
    
 
WHRoeder:
  1. means the EA in incompatible with every other, including itself on other chart and manual trading.
  2. Compare your two ordersends. You can't open a buy EXCEPT at the Ask.

  3. Had you tested your return code you would have found out WHY. Adjust for 4/5 digit brokers, tp, sl AND SLIPPAGE.


Thank you sir, Thanks alot, i fixed the EA ..

But one more thing, why there is "// Time frame: M5 and higher" included in the EA since i can choice the date and time ( which i have added to the EA ) ...

How this thing work about the Chart times with EAs ..

And about this ... im getting differend Buys when changing the Period,

with 1M period i get 9 trades only,

with 5M i get 6,

and 15M i get 12 orders

from 2010.03.1 to 2010.03.31 ... its a 23 Trading days and 8 weekends(Closed) ..

i want to be sure that all the trades im going to make, will function 100% .. i dont want to miss any of my future trades ..

Thanks again, this is the last thing i want to know and hopefully i will be ready to start my Trading ..

 

some 1 please?

 
Leopardos:

some 1 please?


You can use it on all the timeframes....

That's no problem when there is //..................

it is just a comment in the EA and not a working programline with an order

that you have different amount of trades testing in strategie the only thing i can think of is to look at the

history center and take a look at the different timeframes to the history

You can't place trades at seconds exactly with MT4 There is simply not every second new tick data

the best is to look for 30 seconds to open a new trade.....

The message of WHRoeder is very clear in what you have to do to make it possible trading at 5 digits brokers and 4 digit brokers in the right way

if you 're not sure freely testing on DEMO accounts ......

Reason: