MQL4 OrderSend Error 2 ...but everything on my code is fine

 

hellow folks ...!!

my EA is working super fine on two brokers that i do normally use for testing my systems...last week i decided to download another brokers platform because my those two brokers minimum trading volume is big and i wanted to try something different(i wanted to testing under low capital conditions)...the while testing my EA on new broker it starts well it opens two trades correctly as my condition..Then after those two trades it bombards me with OrderSend error 2.... I have tried Printing Conditions,inspecting the code if i can see any mistake but i haven't seen i have also tried searching on the forum but i found nothing much helpful...will you please help me to figure out what might be wrong because i'm struggling with this problem for more than 3 days

This is the simple code for opening a buy position only

//---
double buy(double lot,int MagicNumber,double stoploss,double takeprofit){
 double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
 double buyPos=OrderSend(Symbol(),OP_BUY,lot,ask,slippage,ask-stoploss*_Point,ask+takeprofit*_Point,"TheGrid",MagicNumber,0,clrNONE);
   return buyPos;
} 
//i have checked all the conditions they all right and this is how open a buy position
if (ExistBuyStop(magic)==false && ExistPos(MagicNumber)==false && rsi()<low && macd()>0 )
  {
  RefreshRates();
   buy(adaptiveLot(),MagicNumber,atr(),atr()); 
  }
// these double functions===adativelot() and atr() rsi() and macd are all ok and they print correct values as i want them

 
 double buyPos=OrderSend(Symbol(),OP_BUY,lot,ask,slippage,ask-stoploss*_Point,ask+takeprofit*_Point,

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

Reason: