OrderSend

 

Hi,

I'm new to MQL4 and I'm using bellow code to send a test order to via demo account. But unfortunately order isn't getting executed to the market. Is anyone possible to assist me with this?

 

//input int      StopLoss=10;

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

extern int TakeProfit=10;

extern int StopLoss =10;


void OnStart()

  {

double TakeProfitLevel;

double StopLossLevel;


   TakeProfitLevel = Bid + TakeProfit*Point;

   StopLossLevel=Bid - StopLoss*Point;

   


   //Alert ("Take Profit Level = ", TakeProfitLevel);

   //Alert ("Stop Loss Level =", StopLossLevel);

   

   //int OrderSend (string "EURUSD", int OP_BUY, double 1.0, double Ask, int 10, double StopLossLevel,double TakeProfitLevel, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE);


//OrderSend("EURUSD",OP_BUY,1,Ask,3,StopLossLevel,TakeProfitLevel,"My order",16384,0,clrGreen);

    OrderSend("GBPUSD", OP_BUY, 1.0, Ask, 100, StopLossLevel, TakeProfitLevel,"My 1st Order!" );

   

  }

//+------------------------------------------------------------------+ 

 

Please post this code in SRC section. & remove the unnecessary codes which you marked with "//"

When you code make the program look clear, its good for your coding & others to understand.

Among your program following is the active ordersend line.

OrderSend("GBPUSD", OP_BUY, 1.0, Ask, 100, StopLossLevel, TakeProfitLevel,"My 1st Order!" );

 You said order is not sending in the market, What errors it shows? Probably slippage problem, trading condition not meet.

 

Hi to everybody, I'm also new in the coding language of MQL4. I'm going to benefit from this post to share my problem as it is similar to pankajalakal123.

When I backtest my program not a single order is placed. Although my program start (in the OnInit phase) with an instruction to buy long and short at ask price and bid price, then send another 4 orders to be executed if ask price moves from 10 PIP up or down.

 Could someone explain me where I'm wrong in the wrtiting of the code? 

 

Thanks a lot 

double aski;
double bidi;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   aski=Ask;
   bidi=Bid;
   OrderSend(Symbol(),OP_BUY,1,aski,2,aski-10*Point,aski+10*Point,"Ordre Achat",666,0,Green);
   OrderSend(Symbol(),OP_SELL,1,bidi,2,bidi+10*Point,bidi-10*Point,"Ordre Vente",666,0,Red);
   
   OrderSend(Symbol(),OP_BUYSTOP,1,aski+10*Point,2,aski,aski+20*Point,"Ordre Achat",666,0,Green);
   OrderSend(Symbol(),OP_SELLLIMIT,1,Bid+10*Point,2,Bid+20*Point,Bid,"Ordre Vente",666,0,Red);
   OrderSend(Symbol(),OP_BUYLIMIT,1,aski-10*Point,2,aski-20*Point,aski,"Ordre Achat",666,0,Green);
   OrderSend(Symbol(),OP_SELLSTOP,1,bidi-10*Point,2,bidi,bidi-20*Point,"Ordre Vente",666,0,Red);
       
      
//---
 
pipokito Could someone explain me where I'm wrong in the wrtiting of the code?
  1. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Your stops are 2 pips away from the open price. The must be at least MarketInfo(_Symbol, MODE_STOPLEVEL) * point away from the close price.
  3. Humans can't watch the screen 24/7 so they use pending orders; EA's can, so no need for pending orders, have it wait until the market reaches the trigger price and open an order.
Reason: