Why I can't send buy order?

 

So I followed this tutorial 

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners - MQL5 Articles


But I made things a little different and stupid just to test, but still, I can't send order, why? GetError function keeps returning error:4753 (position not found).


Eeverything seems to be ok with my code.

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
  • www.mql5.com
This article is aimed at beginners who wish to learn how to write simple Expert Advisors in the new MQL5 language. We will begin first by defining what we want our EA (Expert advisor) to do, and then move on to how we want the EA to do it. 1. Trading Strategy It will monitor a particular indicator, and when a certain condition is met (or...
Files:
 
  1.          mrequest.sl = latest_price.ask - 0.05;
             mrequest.tp = latest_price.ask + 0.10;
             mrequest.price = latest_price.ask;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  2.    if(!is_bought)
         {
          if(short_ma_value[0] > short_ma_value[1] > short_ma_value[2])
            {
             ⋮
             if(OrderSend(mrequest, mresult))
             ⋮
            }
         }
    
       if(mresult.retcode == 10009 || mresult.retcode == 10008) //Request is 
    Why are you looking at mresult if you haven't opened an order?
 

1-What do you mean by "bid/OrderClosePrice"? I'm not sure I understood it right. 

Does the " mrequest.tp" or " mrequest.sl", get triggered when the ask or bid price reaches it, or when the last deal price hit it

Honestly I'm trading shares, the broker's spread is very low, rarely more than 4 times the minimun currency unit, but knowledge is always power.

This code is mostly from the tutorial that I followed.


Does the code below sends an order?

if(OrderSend(mrequest, mresult)


In other words, do functions inside the if statement get "fully" called?


Why do you use double for maxSpread? Is a float not enough? Why?

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5