Download MetaTrader 5

Open a position error?

To add comments, please log in or register
Have you installed MetaTrader 5? Find out more about it!
cpr
26
cpr 2016.11.21 02:42 

Hi all,

I'm writing a simple code to open a position BUY and SELL...just to learn, but it doesn't work. Anyone can tell me why? I have declared all variables (SL, TP and lots) and the code has been compiled succesfully...but it doesn't open positions...

Thanks in advance

int OnInit()
  {
//---
   OrderSend(Symbol(),OP_BUY, lots, MarketInfo(Symbol(),MODE_ASK), 3, MarketInfo(Symbol(),MODE_ASK)-(SL*Point), MarketInfo(Symbol(),MODE_ASK)+(TP*Point), "Buy Trade", magic, 0, Blue);
   OrderSend(Symbol(),OP_SELL, lots, MarketInfo(Symbol(),MODE_BID), 3, MarketInfo(Symbol(),MODE_BID)+(SL*Point), MarketInfo(Symbol(),MODE_BID)-(TP*Point), "Sell Trade", magic, 0, Red);
//---
   return(INIT_SUCCEEDED);
  }
whroeder1
14470
whroeder1 2016.11.21 14:38  
  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. What is STOP_LIMIT, Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  3. You are not adjusting SL, TP, and slippage for 4/5 digit brokers.
    double   pip        = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      slippage   = 3 * int(pip / _Point);
  4. Did you normalize lots properly?
    Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
cpr
26
cpr 2016.11.21 20:55  
whroeder1:
  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. What is STOP_LIMIT, Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  3. You are not adjusting SL, TP, and slippage for 4/5 digit brokers.
    double   pip        = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      slippage   = 3 * int(pip / _Point);
  4. Did you normalize lots properly?

Many thanks for your answer, just some questions:

1. How can I check retur codes?

2. Can I use this cose to normalize SL and TP?

NormalizeDouble(Ask+SL*Point,Digits)

Thanks in advance

whroeder1
14470
whroeder1 2016.11.21 21:06  
cpr:
1. How can I check retur codes?
2. Can I use this cose to normalize SL and TP?
  1. What part of these were unclear? 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. What part of these were unclear? SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum)
To add comments, please log in or register