Hi there. 130 error issue.

 
            double iHighPrice = iHigh(NULL, 0, 1);
            double stopLossOnce = getLowestPriceThree();

            // Ensure the stop-loss level respects the minimum stop level
            double minStopLevel = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) * Point;
            double normalizedStopLossOnce = NormalizeDouble(stopLossOnce, Digits);
            double stopLoss = (normalizedStopLossOnce < Ask - minStopLevel) ? normalizedStopLossOnce : Ask - minStopLevel;

            // Ensure entry price is above the current Ask price
            double entryPrice = NormalizeDouble(iHighPrice, Digits);
            if (entryPrice <= Ask)
            {
                entryPrice = Ask + minStopLevel; // Set entry price to be beyond current Ask price
            }

            // Debugging prints
         /*
            Print("StopLossOnce: ", stopLossOnce);
            Print("NormalizedStopLossOnce: ", normalizedStopLossOnce);
            Print("StopLoss: ", stopLoss);
            Print("Ask: ", Ask);
            Print("EntryPrice: ", entryPrice);
            Print("iHighPrice: ", iHighPrice);
         */

            // Ensure conditions to place the order are met
            if (entryPrice > Ask && iHighPrice > Ask && currentLow > currentEma)
            {
                double lots = calculateLotSize(iHighPrice, stopLossOnce) / contractSize;
                lots = NormalizeDouble(lots, 1);
                longOpenedAt = TimeCurrent();

                int orderType = OP_BUYSTOP;
                openedOrder = OrderSend(
                    Symbol(),
                    orderType,
                    lots,
                    entryPrice,
                    slippage,
                    NormalizeDouble(stopLoss, Digits),
                    0,  // Take Profit
                    DoubleToString(priceProgress),
                    MAGICMA,
                    TimeCurrent() + order_expiration_time_long,
                    clrBlueViolet
                );

...

Was trying to handle that for almost 2 days, cannot find the solution. Understanding that it is cause the invalid stops didn't really help

 
Аркаша:
getLowestPriceThree
You have posted part of the code, which is incomplete. To increase the chances of getting help you should post your full source code
 
Rajesh Kumar Nait #:
You have posted part of the code, which is incomplete. To increase the chances of getting help you should post your full source code

after that nothing that can be useful for the case. There is all the things that i trying to handle to avoid the error 

nothing useful for the case

 

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 #:

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.

Right, thank you a lot! Appriciate that
 
Аркаша #:
Right, thank you a lot! Appriciate that

Okay, still need the solution. I need to use pending orders, is there any solution for this?

 

Especially, it happens for long, for short it happens a way less. But still huge amount of trades. Short function provided

           double iLowPrice = iLow(NULL, 0, 0) * 0.9998;
            double stopLossOnce = getHighestPriceThree();

            // Ensure the stop-loss level respects the minimum stop level
            double minStopLevel = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) * Point;
            double normalizedStopLossOnce = NormalizeDouble(stopLossOnce, Digits);
            double stopLoss = (normalizedStopLossOnce > Bid + minStopLevel) ? normalizedStopLossOnce : Bid + minStopLevel;

            // Ensure entry price is below the current Bid price
            double entryPrice = NormalizeDouble(iLowPrice, Digits);
            if(entryPrice >= Bid)
              {
               entryPrice = Bid - minStopLevel; // Set entry price to be beyond current Bid price
              }


            if(iLowPrice < Ask)
              {
               shortOpenedAt = TimeCurrent();

               double lots = calculateLotSize(iLowPrice, stopLossOnce) / contractSize;
               lots = NormalizeDouble(lots, 1);

               openedOrder = OrderSend(
                                Symbol(),
                                OP_SELLSTOP,
                                lots,
                                entryPrice,
                                slippage,
                                stopLoss,
                                0,
                                DoubleToString(priceProgress),
                                MAGICMA,
                                TimeCurrent() + order_expiration_time_short,
                                clrRed
                             );

               if(openedOrder < 0)
                 {
                  Print("OrderSend failed with error short#", GetLastError());
                 }
               else
                 {
                  Print("OrderSend successfully: Ticket #", openedOrder);
                 }
              }
           }
        }
     }
  }