0
votes

I am getting Error:

EURUSD,H4: OrderSend failed with error #130

Experts Please guide where I am making mistake?

void OnTick()
  {
   
   H1EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
   H4EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H4,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
   StopLossBuy = High[2] + (30 * Point);
   StopLossSell = Low[2] - (30 * Point);

   if(
      Close[1]>H4EMAprev && 
      Close[1]>H1EMAprev
      )
     { 
      Price = NormalizeDouble(High[1] + (30 * Point), 5);
      TpOrderOne = NormalizeDouble(Price + (100 * Point), 5);

      //Pending order BUY
      Ticket1 = OrderSend(Symbol(),OP_BUYSTOP,1,Price,3,StopLossBuy,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
      
      if(Ticket1<0)
       {
        Print("OrderSend failed with error #",GetLastError());
       }
      else
       {
        Print("OrderSend placed successfully");
       }
     }

   if(
      Close[1]<H4EMAprev && 
      Close[1]<H1EMAprev
      )
     {
      
      Price = NormalizeDouble(Low[1] - (30 * Point), 5);
      TpOrderOne = NormalizeDouble(Price - (100 * Point),5 );
      
      //Pending order BUY
      Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,Price,3,StopLossSell,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
      
      if(Ticket1<0)
       {
        Print("OrderSend failed with error #",GetLastError());
       }
      else
       {
        Print("OrderSend placed successfully");
     }

  }

Experts Please guide where I am making mistake?

I want my EA to work like this:
Trade Open Criteria:

  1. Buy Trade will be open immediately on start of current candle IF last candle's closing price was above EMA(EXPONENTIAL MOVING AVERAGE) (i.e: Close[1] > EMA).
  2. Sell Trade will be open immediately on start of current candle IF last candle's closing price was below EMA(EXPONENTIAL MOVING AVERAGE) (i.e: Close[1] < EMA).

Open Trade Price:

  1. Pending Buy Trade price will be 3 pips above of last candle's High (i.e: TradePriceOpen = High[1] + 3 pips).

  2. Pending Sell Trade price will be 3 pips below of last candle's Low (i.e: TradePriceOpen = Low[1] - 3 pips).

Stop Loss:

  1. SL will be 3 pips below of 2nd last candle's Low in Sell Stop Pending Order (i.e: SL = Low[2] - 3 pips).
  2. SL will be 3 pips above of 2nd last candle's High in Buy Stop Pending Order (i.e: SL = High[2] + 3 pips).

Take Profit:

  1. TP will be 10 pips below of the price where trade was opened in Sell Stop Pending Order (i.e: TP = TradePriceOpen - 10 pips).
  2. TP will be 10 pips above of the price where trade was opened in Buy Stop Pending Order (i.e: TP = TradePriceOpen + 10 pips).
1
this wont compile because you have 'TpFirstOrder' as take profit but you never declared it. Please correct the code to go furtherDaniel Kniaz

1 Answers

0
votes

Your stoploss logic is reversed. You cannot place a stop loss higher than the order entry price on a buy order and visa-versa.