Help! I keep getting Error 130 when my stoploss and takeprofit are definitely valid. What should I do?

 

Hi all, I have tried to troubleshoot myself but I couldn't find what is wrong with my code? I tried to send buystop order using an EA, but it kept returning Error 130. I have verified that my stoploss price and takeprofit price exceed the minimum stoplevel required by the server/broker. I even manually widen the stop loss and takeprofit price so that I'm far exceeding the requirement.

For instance, the following are extracted from strategy tester journal. This setup has a valid stop loss, entry price and take profit price:

2024.08.12 02:21:53.350 2023.04.04 12:55:00  StopOrder GBPNZD,M15: Alert: BUY STOP order rejected with Error: 130

2024.08.12 02:21:53.350 2023.04.04 12:55:00  StopOrder GBPNZD,M15: OrderSend error 130

2024.08.12 02:21:53.350 2023.04.04 12:55:00  StopOrder GBPNZD,M15: Alert: Sending BUYSTOP order with EntryPrice: 1.98566; StopLossPrice: 1.97807; TakeProfitPrice: 2.00084; Lot_Size: 0.1

2024.08.12 02:21:53.350 2023.04.04 12:55:00  StopOrder GBPNZD,M15: Alert: StopLevel: 120

2024.08.12 02:21:53.350 2023.04.04 12:55:00  StopOrder GBPNZD,M15: Alert: _1RInPoint: 758.9999999999985 (My stoploss distance in point is way more than the stoplevel)


The following is my code:

   double ATR = iATR(Symbol(),NULL,14,0);
   Alert("ATR: " + ATR);
   double EntryPrice = NormalizeDouble(Ask,Digits);
   double StopLossPrice = NormalizeDouble(EntryPrice - (3 * ATR),Digits);
   double _1R = EntryPrice- StopLossPrice;
   double TakeProfitPrice = NormalizeDouble(EntryPrice + (2 * _1R),Digits);
   double Lot_Size = 0.1;
   double _1RInPoint = _1R * MathPow(10,Digits);
   int StopLevel = MarketInfo(NULL,MODE_STOPLEVEL);
   Alert("_1RInPoint: " + _1RInPoint);
   Alert("StopLevel: " + StopLevel);
   Alert("Sending BUYSTOP order with EntryPrice: " + EntryPrice + "; StopLossPrice: " + StopLossPrice + "; TakeProfitPrice: " + TakeProfitPrice + "; Lot_Size: " + Lot_Size);
   if(IsTradingAllowed() && !AlreadyOpened(9999))
              {
               int OrderID = OrderSend(NULL,OP_BUYSTOP,Lot_Size,EntryPrice,3,StopLossPrice,TakeProfitPrice,NULL,9999);
               if(OrderID < 1)
                 {
                  Alert("BUY STOP order rejected with Error: " + GetLastError());
                 }
               else
                 {
                  Alert("BUY STOP Order ID: " + OrderID + " placed successfully");
                 }
              }
 
Are you trying to send OP_BUYSTOP at the ASK price? Enter OP_BUY or "EntryPrice = Ask + (3*ATR)" for example...
 

There is no need to create pending orders in code.

  1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

    Don't worry about it unless you're scalping M1 or trading news.

  2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

 
William Roeder #:
ans can't watch the screen 24/7, so they use pending orders; EAs can, so no
Thanks! I have decided to set up "pseudo pending order" by sending market order when the price is right. Thanks for the tip!