Building your own trading bot using MetaTrader 4 and MQL4

Brian shows you how to program your own basic trading bot using MetaTrader 4 and MQL4.


  1. Does anyone know how to change this code to only trade Tuesday – Thursday, and only trade from 9am – 2 pm server time?
    I am new to codes and I don't want to mess anything up on the current EA I am using.

    datetime LastOpenTradeTime()


    datetime result = 0;

    for(int i = OrdersTotal()-1; i >= 0; i–)


    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

    if(OrderType() > 1) continue;

    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)


    result = OrderOpenTime();






    bool SelectLastHistoryTrade()


    int lastOrder = -1;

    int total = OrdersHistoryTotal();

    for(int i = total-1; i >= 0; i–)


    if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;

    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)


    lastOrder = i;




    return(lastOrder >= 0);


    datetime LastOpenTime()


    datetime opentime1 = 0, opentime2 = 0;


    opentime1 = OrderOpenTime();

    opentime2 = LastOpenTradeTime();

    if (opentime1 > opentime2)

    return opentime1;


    return opentime2;


  2. Thank you for this video! Would you be able to write something that would buy when price crosses over and 5 m candle closes above the Lead 2 line in the Ichimoku and vice versa? How much would you charge for that, if you were to consider doing it?

  3. Why the software doesn't recognize the functions "OP_SELL" or "OP_BUY"? For you in the video it is recognized and show you the functions, for me it's just a text. I did exactly as you did. I use MetaTrader 4 and followed step by step without any mistakes.
    Please help. I also would like to get some guides how to program everything that I wish for, as for now I do now know what to type in the code to make it happen. I learned how to code (Computer Science degree) but I have no idea how this software works or what functions are in there and what they do.
    Please I would like to get any kind of helpful information.

    Best Regards

  4. hello there if you still there I would like to request from you to make a bot like this.
    I made a buy with 1lot and 60pips take profit and 80pips stop loss but with an sell order of 2lots below the buy order of pips with take profits of 60pips and 80stop loss this process will continue until the take profit and stop loss didn't hit. please if you know how to make this pls answer. I'll wait for your reply thank you….

  5. Finally I have multiple streams of income which I earn weekly from my
    invstmnt. Thanks to Harry_fxvalue on instegrm. He’s trading platform
    generates about € 6000 of profit which In accessible to. It’s a blast I
    time you…

    Follow Trade Technology Ltd, focuses on developing systems that assist financial institutions in collecting, analyzing and applying transaction data, including the construction of a docking internet tracking transaction system.

    – Member of the *HKSTP Startup Alumni Association (SAA)

    – Graduated in Incubation program provide by HKSTP


    – Top10 Investment Value Award

    – China & Hong Kong Resources Integration Award 2017

    – Dsiruptive Innovation Award 2017

    held by Angel Investment Foundation


    HKSTP: Hong Kong Science and Technology Parks Corporation which is a public corporation set up by the Hong Kong Government in 2001 to foster the development of innovation and technology in Hong Kong.

    HKSTP Startups Alumni Association is a vibrant community established to enhance the bonding between HKSTP and graduates from our incubation and acceleration programmes.

    It is a platform for the graduates to enjoy reunions and the extended value services from HKSTP, and to contribute to the ecosystem in return.

  7. If I want to test a strategy using a custom indicator that I download would I have to code the function for that indicator as well or would there be a function when downloading the indicator?

  8. I have traded with a lot of individuals but I have never come across anyone as good as Metro__Kelvinfx on IG, just by applying his strategies, I now trade independently. he is the best I'd advise any novice in investing to trade with him. .

  9. Every trader can earn decent payouts at times, however, those aiming to have a regular income from trading might need a consistent profit trading strategy. Opting for the services of Roger Wallace has been the best shift of my life, his strategies remains the best.

  10. The secret of successful trading is good risk management, discipline, and the ability to control your emotions. Anyone can guess right and win every once in a while, but without risk management it is virtually impossible to remain profitable over time.

  11. Hi, you should check this bot called Bit Robot who provides a daily passive income, so no hassle. Depending of the contract you buy, you basically have between 17 and 21% monthly return in USDT or in the cryptocurrency of your choice. It’s a Belgium company who develops the bot, the team looks legit, they are on Youtube, Instagram and Facebook so you can check by yourself and they got an interesting referral program . So feel free to check their site and if you have questions don’t hesitate, I’m happy to help you. Here is my link if you want to be in my team in order to build your own team after : cheers

Leave a Reply

Your email address will not be published.