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

 
surfdoode2:


I also still have this error having made both suggested corrections:

ZeroMemory(mrequest);

and also

if(Buy_opened || Sell_opened)

Please can someone help with the error 4756? It just seems unable to place a Buy Order.

Check if you used the SymbolInfoTick function and wrote this part of the code:

//--- Get the last price quote using the MQL5 MqlTick Structure
   if(!SymbolInfoTick(_Symbol,latest_price))
     {
      Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
      return;
     }
Documentation on MQL5: Market Info / SymbolInfoTick
Documentation on MQL5: Market Info / SymbolInfoTick
  • www.mql5.com
SymbolInfoTick - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
surfdoode2:


I also still have this error having made both suggested corrections:

ZeroMemory(mrequest);

and also

if(Buy_opened || Sell_opened)

Please can someone help with the error 4756? It just seems unable to place a Buy Order.


Maybe the Filling Type of your Broker  is ORDER_FILLING_IOC , you can try to edit the code from:

mrequest.type_filling = ORDER_FILLING_FOK;

To:

mrequest.type_filling = ORDER_FILLING_IOC;

I had the same problem and now I solved it successfully

 
Excellent work my guy ... I learnt something today
 

please what should i tick on those checkbox in the dialog box

Files:
 

Hi everybody begginings:

All I have needed to do to fix error 4756 (for both buy and sell codes change the next 3 lines):

// any opened Sell position?

         if(Sell_opened || Buy_opened) // Include both orders in this conditional with an OR operator
           {
            Alert("We already have a Sell position!!!");
            return;    // Don't open a new Sell Position
           }
         ZeroMemory(mrequest);                                                 // Include this line in this position
         mrequest.action=TRADE_ACTION_DEAL;                                // immediate order execution
         mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // latest Bid price
         mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                          // currency pair
         mrequest.volume = Lot;                                              // number of lots to trade
         mrequest.magic = EA_Magic;                                          // Order Magic Number
         mrequest.type= ORDER_TYPE_SELL;                                     // Sell Order
         mrequest.type_filling = ORDER_FILLING_IOC;      // Change the "FOK" by "IOC"
         mrequest.deviation=100;                                             // Deviation from current price

 
Nice article, save my days, thanks bro..
 
louisd #:

Hi All,

Brand new to MQL5 (and FOREX for that matter) but, long time programmer. I opened the My_First_EA.mq5 file and compiled but, I'm not getting the Debug functions. If I open any of the example script files I do get the Debug option. Also received a warning return value of 'OrderSend' should be checked. What do I have to do to get Debug functionality?

Louis

It seems the file with the code (*.mq5) should be placed somewhere in MQL5 installation directory (for example, in the `Shared Projects`)
 
surfdoode2 #:


I also still have this error having made both suggested corrections:

ZeroMemory(mrequest);

and also

if(Buy_opened || Sell_opened)

Please can someone help with the error 4756? It just seems unable to place a Buy Order.

Make sure you have allowed Algo Trading.
 
Does anybody know why did he check for the number of bars (<60) the second time in the article? His explanation of this action is not an explanation at all.
 
Samuel Olowoyo #:

Hello,

First from your explanation, when you removed those lines of code, you get an error and when you did not multiply the stoploss/takeprofit values by 10, you get an error? This I believe has explained that those lines of code are very important.

Back to the article, it explained those lines of code are necessary if you are using a chart with 5 decimal digits (0.XXXXX) or 3 decimal digits (0.XXX) currency pairs.

See examples below: 

 

 5 - Decimal Digits price

 

3 - Decimal Digits price 

I hope this has answered your question.

Hmm.. no it doesn't at all.
Samuel Olowoyo #:

Hello,

First from your explanation, when you removed those lines of code, you get an error and when you did not multiply the stoploss/takeprofit values by 10, you get an error? This I believe has explained that those lines of code are very important.

Back to the article, it explained those lines of code are necessary if you are using a chart with 5 decimal digits (0.XXXXX) or 3 decimal digits (0.XXX) currency pairs.

See examples below: 

 

 5 - Decimal Digits price

 

3 - Decimal Digits price 

I hope this has answered your question.

No it doesn't at all. You just repeat what you said in the article.
Reason: