Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 2

 

thank you for the article.

 
Great article for a beginner! i'm very excited. Thank you very much.
 

very nice article, thanks for it, helped me a lot, are you in the ATC 2011???

cheers 

 
olowsam:

Yes, it's true that the article does not dicsuss how to close positions in details, however, if you open a Sell position, once you open a Buy, the sell position is automatically closed.

Therefore, to close a Buy position, open a Sell; and to close a Sell position, open a Buy.

Thank you. 

hi olowsam, 

 could you please show me, where the code that make it like that ? "..., if you open a Sell position, once you open a Buy, the sell position is automatically closed."

'coz in your example, you only put single order(sorry, i'm a total beginner)  ;

//--- Putting all together


         //--- send order

         OrderSend(mrequest,mresult);


because i'm currently trying to make my EA like that, and i use PSAR as my indicator. i want my EA to buy and sell following the trend all along the time.

just can't figure the coding, how to make it auto close sell and then Open Buy(and also auto Close Buy and then Open Sell),  each time PSAR draws the opposite dot.

I need help actually.

Currently i can manage the EA to open position when PSAR draw Opposite using 

trade.PositionOpen(_Symbol,                                          // symbol

                               ORDER_TYPE_BUY,                                   // buy order

                               Money_M(),                                        // lots to trade

                               Ask,                                              // last ask price

                               0,//Ask - StopLoss,                                   // Stop Loss

                               buystop,//Ask + TakeProfit,                                 // Take Profit 

                               " "); 

the Problem is when i want to close my position only when the PSAR has Draw the opposite Dot.   

thanks 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
mora:

very nice article, thanks for it, helped me a lot, are you in the ATC 2011???

cheers 

Yes, he participates - https://championship.mql5.com/2011/en/users/olowsam
 

Hi everyone,

I downloaded "my_first_ea.mq5" and tried to test it.

It coudn't place any trades.

Here are the type of errors: 

 2011.11.13 23:39:58 2011.11.01 14:20:00   Alert: The Sell order request could not be completed -error:4756
 2011.11.13 23:39:58 2011.11.01 14:20:00   failed instant sell 1.00 EURUSD at 1.36833 sl: 1.37133 tp: 1.35833 [Invalid request]
 

same with buy orders

2011.11.13 23:39:56 2011.11.01 13:25:00   Alert: The Buy order request could not be completed -error:4756
2011.11.13 23:39:56 2011.11.01 13:25:00   failed instant buy 1.00 EURUSD at 1.37186 sl: 1.36886 tp: 1.38186 [Invalid request]
   

Any ideas about why is that?

You help appreciated, Thanks... 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM - Documentation on MQL5
 
thanks ur artical.
 

Hi,

code looks great but when i try it I get this error

 2011.11.13 23:39:58 2011.11.01 14:20:00   Alert: The Sell order request could not be completed -error:4756
 2011.11.13 23:39:58 2011.11.01 14:20:00   failed instant sell 1.00 EURUSD at 1.36833 sl: 1.37133 tp: 1.35833 [Invalid request]

 

No trades are executed.

Could someone help fixing?

Thanks

 

 
Financialabs:

Hi,

code looks great but when i try it I get this error

 2011.11.13 23:39:58 2011.11.01 14:20:00   Alert: The Sell order request could not be completed -error:4756
 2011.11.13 23:39:58 2011.11.01 14:20:00   failed instant sell 1.00 EURUSD at 1.36833 sl: 1.37133 tp: 1.35833 [Invalid request]

 

No trades are executed.

Could someone help fixing?

Thanks

 

I asked the same question and no one replied.

I have found it.

It is a bug. You have to add a line of code 

ZeroMemory(mrequest); 

that line should be before the mrequest.action=...  mrequest.price=... etc. lines.

 
senerzen:

I asked the same question and no one replied.

I have found it.

It is a bug. You have to add a line of code 

ZeroMemory(mrequest); 

that line should be before the mrequest.action=...  mrequest.price=... etc. lines.

Thank you, the bug is fixed.
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.