Download MetaTrader 5
To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
manuel
21
manuel 2015.10.12 16:03 
Hello :)

I made an EA which opens a trade and set the SL and TP automatically without any problem on eur/usd and Gbp/usd, but for some reason it won`t work on the usd/jpy. can anyone help me ?

 

Thanks

Manuel 

peter.MT4Web
158
peter.MT4Web 2015.10.12 16:52  

Check the Error-Code and your Entry / SL / TP.

UsdJpy has only 3 Digits.

whroeder1
13610
whroeder1 2015.10.12 18:35  
You likely have hard coded constants.
DeanDeV
330
DeanDeV 2015.10.12 19:29  
bantoine2:
Hello :)

I made an EA which opens a trade and set the SL and TP automatically without any problem on eur/usd and Gbp/usd, but for some reason it won`t work on the usd/jpy. can anyone help me ?

 

Thanks

Manuel 

Remember point size.
manuel
21
manuel 2015.10.13 14:59  

OK i have another problem now, before I solve the one with JPY.

 

 

First of, english is not my mother tongue so please don`t describe it to complicated for me.

My problem is that my EA which runs on an offline chart opens

-  trades out of the time I told him to take trades

- trades sometimes and sometimes not within the timeframe

I am testing my EA on 2 brokers and on the one broker it takes trade at 10 am and on the other broker it doesn`t.  But like I said it is not with all of the trades, it is just with some.

The whole code is standing in the onTick() method (i saw on other webpages, that this method might be a problem on an offline chart, but I wouldn´t agree with that, because if this would be true, the EA wouldn´t open any positions, right?) if this method and we have a 5-digit-broker which uses a different time zone as we are living in, but we considered the time zone in our variables.

Can you help me please?


The code:

if(((starttimeVM()<=TimeCurrent())&&(TimeCurrent()<endtimeVM())) || ((starttimeNM()<=TimeCurrent())&&(TimeCurrent()<endtimeNM())))
   {
      //No Position when trend already exists!
      if(FirstTickInTime==true)
      {
         if((ValueOfLastMACD>0) && (ValueOfLastMACD>ValueOfLastSignal))
         {
            TradePossible = false;
         }
         
         if((ValueOfLastMACD<0) && (ValueOfLastMACD<ValueOfLastSignal))
         {
            TradePossible = false;
         }
         
         FirstTickInTime = false;
      }
      
      
      //Position possible once the macd crosses again!
      if(TradePossible == false)
      {
         if((ValueOfLastMACD>0) && (ValueOfLastMACD<ValueOfLastSignal))
         {
            TradePossible = true;
         }
         
         if((ValueOfLastMACD<0) && (ValueOfLastMACD>ValueOfLastSignal))
         {
            TradePossible = true;
         }
      }
      
      
      //conditions for Long Trade open!
      if((ValueOfLastMACD>0) && (ValueOfLastMACD>ValueOfLastSignal) && (MarketInfo(NULL, MODE_ASK)>=ValueOfLastUpperBB) && (LongTradeAllowed==true) && (LongTradeAllowedInThisSection==true) && (TradePossible == true))
      {
         LongTradeStarted = Ask;
         LongLotSize = LotSize;
         LongOrderTicketNumber = OrderSend(NULL, OP_BUY, LongLotSize, LongTradeStarted, 3, (LongTradeStarted - StopLoss*Point), 
                                                                 (LongTradeStarted + TakeProfit*Point), NULL, 1234, 0, clrGreen);
         LongTradeAllowed = false;
         LongTradeAllowedInThisSection = false;
         LongStopShifted = false;
      }
      
      
      //conditions for Short Trade open!
      if((ValueOfLastMACD<0) && (ValueOfLastMACD<ValueOfLastSignal) && (MarketInfo(NULL, MODE_BID)<=ValueOfLastLowerBB) && (ShortTradeAllowed==true) && (ShortTradeAllowedInThisSection==true) && (TradePossible == true))
      {
         ShortTradeStarted = Bid;
         ShortLotSize = LotSize;
         ShortOrderTicketNumber = OrderSend(NULL, OP_SELL, ShortLotSize, ShortTradeStarted, 3, (ShortTradeStarted + StopLoss*Point), 
                                                                     (ShortTradeStarted - TakeProfit*Point), NULL, 1234, 0, clrRed);
         ShortTradeAllowed = false;
         ShortTradeAllowedInThisSection = false;
         ShortStopShifted = false;
      }
   }
peter.MT4Web
158
peter.MT4Web 2015.10.13 15:34  

Check the OrderSend for Errors.

Check the MT4 Log.

Insert some Print statements.

manuel
21
manuel 2015.10.13 16:05  
eddie:

Check the OrderSend for Errors.

Check the MT4 Log.

Insert some Print statements.


 

- I modified the mql4 file as shown. have I done it in the right way?

- can you give me a solution why trades are opened out of the time frame ?

 

Open Problem --> 

//Conditions for long trade open!
      if((ValueOfLastMACD>0) && (ValueOfLastMACD>ValueOfLastSignal) && (MarketInfo(NULL, MODE_ASK)>=ValueOfLastUpperBB) && (LongTradeAllowed==true) && (LongTradeAllowedInThisSection==true) && (TradePossible == true))
      {
         LongTradeStarted = Ask;
         LongLotSize = LotSize;
         LongOrderTicketNumber = OrderSend(NULL, OP_BUY, LongLotSize, LongTradeStarted, 3, (LongTradeStarted - StopLoss*Point), 
                                                                 (LongTradeStarted + TakeProfit*Point), NULL, 1234, 0, clrGreen);
         if(LongOrderTicketNumber<1)
         {
            error=GetLastError();
            Print("Error = ",ErrorDescription(error));
         }
         else
         {
         OrderSelect(LongOrderTicketNumber,SELECT_BY_TICKET);
         OrderModify(LongOrderTicketNumber,OrderOpenPrice(),(LongTradeStarted - StopLoss*Point), (LongTradeStarted + TakeProfit*Point),0,clrGreen);
         OrderPrint();
         }
         LongTradeAllowed = false;
         LongTradeAllowedInThisSection = false;
         LongStopShifted = false;
      }
      
      
      //conditions for Short Trade open!
      if((ValueOfLastMACD<0) && (ValueOfLastMACD<ValueOfLastSignal) && (MarketInfo(NULL, MODE_BID)<=ValueOfLastLowerBB) && (ShortTradeAllowed==true) && (ShortTradeAllowedInThisSection==true) && (TradePossible == true))
      {
         ShortTradeStarted = Bid;
         ShortLotSize = LotSize;
         ShortOrderTicketNumber = OrderSend(NULL, OP_SELL, ShortLotSize, ShortTradeStarted, 3, (ShortTradeStarted + StopLoss*Point), 
                                                                     (ShortTradeStarted - TakeProfit*Point), NULL, 1234, 0, clrRed);
         if(ShortOrderTicketNumber<1)
         {
            error=GetLastError();
            Print("Error = ",ErrorDescription(error));
         }
         else
         {
         OrderSelect(ShortOrderTicketNumber,SELECT_BY_TICKET);
         OrderModify(ShortOrderTicketNumber,OrderOpenPrice(),(ShortTradeStarted - StopLoss*Point), (ShortTradeStarted + TakeProfit*Point),0,clrRed);
         OrderPrint();
         }
         ShortTradeAllowed = false;
         ShortTradeAllowedInThisSection = false;
         ShortStopShifted = false;
      }

 

 

Time Problem --> 

extern string StartVM = "06:58:00";
extern string EndeVM = "09:25:00";
extern string LetzterTradeSchliessenVM = "09:30:00";
extern string StartNM = "13:28:00";
extern string EndeNM = "14:55:00";
extern string LetzterTradeSchliessenNM = "15:05:00";

datetime starttimeVM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + StartVM;
  return StringToTime(datetimenow);
}

datetime starttimeNM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + StartNM;
  return StringToTime(datetimenow);
}

datetime endtimeVM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + EndeVM;
  return StringToTime(datetimenow);
}

datetime endtimeNM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + EndeNM;
  return StringToTime(datetimenow);
}

datetime LSVM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + LetzterTradeSchliessenVM;
  return StringToTime(datetimenow);
}

datetime LSNM()
{ string currentdatestr=TimeToString(TimeCurrent(),TIME_DATE);
  string datetimenow=currentdatestr+" " + LetzterTradeSchliessenNM;
  return StringToTime(datetimenow);
}

/
To add comments, please log in or register