Cant send a buy order using Ordersend, Why does it not work?

 
#property version "1.00"
#property strict
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
extern int TakeProfit = 10;
extern int StopLoss = 10;

void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;

//here we are assuming that the TakeProfit and StopLoss are entered in Pips
TakeProfitLevel = Bid + TakeProfit*Point*10; //0.00001 * 10 = 0.0001
StopLossLevel = Bid - StopLoss*Point*10;

Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);

OrderSend(NULL, OP_BUY, 0.001, Ask, 10*10, StopLossLevel, TakeProfitLevel, "My 1st Order!"); //notice that slippage also has to be multiplied by 10

}
//+------------------------------------------------------------------+

Code Above:


I was trying to figure out why my script doesnt let me place a buy.

Things i have tried:

i have made sure my autotrading is on on mt4


other than that i dont know what else to do to try to resolve this problem.

 

1. Use ResetLastError before calling OrderSend and then GetLastError after calling OrderSend. Check what the error code is.

2. Double check your volume parameter to make sure it's >= minimum lot size, <= maximum lot size, and that it's a valid volume step.

OrderSend(NULL, OP_BUY, 0.001, Ask, 10*10, StopLossLevel, TakeProfitLevel, "My 1st Order!"); //notice that slippage also has to be multiplied by 10
You can grab those 3 pieces of information using either MarketInfo or SymbolInfoDouble. I'd go with SymbolInfoDouble to ensure compatibility with MQL5.
 

Be careful with NULL.

  1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
  2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
  3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
  4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
  5. Cloud Protector Bug? - MQL4 programming forum (2020.07.25)
Reason: