orderSend runtime error

 

Hi,I have the following simple code to open an order

  ticket =OrderSend(_Symbol,0,1.0,Ask,5,0,0);

the problem is that in runtime Ordersend returns -1

GetLastEror then returns "Expression could not be evaluated"

I am going crazy because I ca't find where the problem is.the function parameters are simple, and debugging all of them have a value

Can any of you see what I am doing wrong?

thanks for your help

this is one of the main actions of an Expert advisor and I can't do it.do you know any other waay to create an order?

thanks for your help

 
karel2006:

Hi,I have the following simple code to open an order

the problem is that in runtime Ordersend returns -1

GetLastEror then returns "Expression could not be evaluated"

I am going crazy because I ca't find where the problem is.the function parameters are simple, and debugging all of them have a value

Can any of you see what I am doing wrong?

thanks for your help

this is one of the main actions of an Expert advisor and I can't do it.do you know any other waay to create an order?

thanks for your help

Take profit and stop loss is your input variables

extern int StopLoss   = 100;
extern int TakeProfit = 200;

//--

ticket =OrderSend(Symbol(),OP_SELL,1.0,Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",123456,0,Red);//Sell
//---
ticket =OrderSend(Symbol(),OP_BUY,1.0,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",123456,0,Green);//Buy
 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2.   ticket =OrderSend(_Symbol,0,1.0,Ask,5,0,0);
    Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total to the account.

    Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage. No SL means you have infinite risk.

    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
                Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

  3. "Expression could not be evaluated" sounds like a compile time error. Post the relevant code (including what's above) and indicate the relevant line number.
Reason: