Expert Advisor won`t open a trade on jpy

Back to topics list To post a new topic, please log in or register
avatar
3
bantoine2 2015.10.12 18: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 

avatar
108
eddie 2015.10.12 18:52 #
 

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

UsdJpy has only 3 Digits.

avatar
13012
WHRoeder 2015.10.12 20:35 #
 
You likely have hard coded constants.
avatar
120
DeanDeV 2015.10.12 21: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.
avatar
3
bantoine2 2015.10.13 16: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;
      }
   }

 

avatar
108
eddie 2015.10.13 17:34 #
 

Check the OrderSend for Errors.

Check the MT4 Log.

Insert some Print statements.


avatar
3
bantoine2 2015.10.13 18: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);
}

Back to topics list  

To add comments, please log in or register