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

 
 guguqiaqia:

step 1: download your this sample code.

step 2: compile it in mql5 .

step 3:in mt5,open chart eurusd 1m, then ,click "auto trading"

step 4:set break symbol in code line 223,224 etc...

step 5:click start debugging button in mt5, then,show this error.

Hello,

Thanks for sharing your steps. If I can take you back to the code,

if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
{
   Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
}
else
{
   Alert("The Buy order request could not be completed -error:",GetLastError());    // line 223
   ResetLastError();                                                                // line 224
   return;

As far as I know, the code did what its supposed to do. You got the error because the order you tried to place was NOT SUCCESSFUL and that is what the line 223 was supposed to do. Please read this  - https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes -  to know what the error means.  (Actually, 10030 means  Invalid order filling type ).

To understand what the order filling type -ORDER_FILLING_FOK  -

mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type  ( line 213 )

  means, please read https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling 

Hope this answered your question. 

 

Hi Samuel,

I downloaded the code, installed it and ran it and I realized it's opening buy and sell orders mostly at every candle that meet the criteria (I'm using H1 as timeframe).

I did not debugging and realized some part of the codes are not triggered. Are you guys able to run the EA properly with the code available for download? 

Files:
screen.jpg  417 kb
 

Hello Mr Olowoyo

 

 

 Thanks you very much for your extremelly interesting article about the way to build and EA.

It is simples for beginners and really helpful 

I am really new in the coding of EA but I realize it is extremelly necessary to test different strategies.

I have downloaded  you EA and try to compile it but I get immediately 50 errors ...

In the previous comments I did not see such problems reported by the users ...

Please find enclosed a extract of the error table.

I will appreciate very to receive some help 

 

Jean Philippe 

Files:
 

Hi Samuel.

your guide was awesome and really cleared the air.

but I have some problems in calling other indicators in my EA.

can you tell me how add MACD and VIDyA signals in my EA? I need to calculate the Signal and Main amount of MACD for example but don't know how to call them in my EA. That would be a great help if you tell me how to do that :)

 you are awesome 

 

I am trying to compile the code provided in this tutorial but getting the error

iADX: wrong parameter count

at the following line

adxHandle=iADX(NULL,0,ADX_Period);

The code seems fine to me. How do I fix the error?

Could anyone help?

 
Dear Samuel
your article was magnificent.
i'm not sure if anyone could have wrote a better beginner guideline.
looking forward to your new articles.

Best Regards

 

Hi,


I have a custom indicator, how to I create an EA, like in your example?

 

Guys,

This is a simple quick modified code if you have an error with multiple orders opening at the same time.

Replace this code :  from line 167 -177

   if(PositionSelect(_Symbol)==true) // we have an opened position
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         Buy_opened=true;  //It is a Buy
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
         Sell_opened=true; // It is a Sell
        }
     }

with this:

   int total= PositionsTotal();
   for(int i=0;i<total;i++)
     {
      if(PositionGetSymbol(i)==_Symbol);
        {
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
           {
            Buy_opened=true;  //It is a Buy
           }
         else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
           {
            Sell_opened=true; // It is a Sell
           }
        }
      }

Thanks  @Samuel Olowoyo

 

Hi, I'm new, great guide, thank you!


I have a problem though. I compiled the provided example, ran through the debugger, the break points worked, resumed the debugging and I get 4756 errors on both buy and sell orders, like this:


The Buy order request could not be completed -error:4756
The Sell order request could not be completed -error:4756
...


What may be happening and what should I look into to correct this behaviour?


V.

 
vmajor:

Hi, I'm new, great guide, thank you!


I have a problem though. I compiled the provided example, ran through the debugger, the break points worked, resumed the debugging and I get 4756 errors on both buy and sell orders, like this:



What may be happening and what should I look into to correct this behaviour?


V.


It's a bug in the EA. Take a look at page 2 where the solution is.

Better approach: use https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade class.

Documentation on MQL5: Standard Library / Trade Classes / CTrade
Documentation on MQL5: Standard Library / Trade Classes / CTrade
  • www.mql5.com
Standard Library / Trade Classes / CTrade - Reference on algorithmic/automated trading language for MetaTrader 5