OrderSend Problem in demo

 

Hi friends,

I am doing an EA for my personal use and I don't know why when I put an order instantly this order is quit....

I am using a demo account.

Code:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get minimum stop level
   double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
   Print("Minimum Stop Level=",minstoplevel," points");
   double price=Ask;
//--- calculated SL and TP prices must be normalized
   double stoploss=NormalizeDouble(Bid-minstoplevel*Point,Digits);
   double takeprofit=NormalizeDouble(Bid+minstoplevel*Point,Digits);
//--- place market order to buy 1 lot
   int ticket=OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
   if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
      Print("OrderSend placed successfully");
//---
  }

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Some brokers don't have a stop level.

    MODE_STOPLEVEL

    14

    Stop level in points

    A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL is actually "floating" here.


  3. Linash: I don't know why when I put an order instantly this order is quit....
    Use the debugger or print out your variables, including _LastError and find out why.
 
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it.

  2. Some brokers don't have a stop level.

    MODE_STOPLEVEL

    14

    Stop level in points

    A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL is actually "floating" here.


  3. Use the debugger or print out your variables, including _LastError and find out why.

Thanks, the problem was that i put wrong parameters on SL and TP