Code a simple Trading Robot | Trading with Python

Поделиться
HTML-код
  • Опубликовано: 28 окт 2021
  • ATJ Traders is an Algorithmic Trading Firm based in Prague. We are seeking investors who want to invest in our trading algorithms. Our strategy backtests and trading results are publicly shared so you can invest with confidence. Visit www.atj-traders.com/
    In this video, we will show you:
    - How to code a simple trading robot
    - How to deploy the robot to trade through MetaTrader5
    Open a Trading Account with Vantage Markets (affiliate link):
    www.vantagemarkets.com/?affid...
    Join our Discord Community:
    / discord
    Risk Disclaimer:
    The content on this website does not serve as investment advice but serves for research purposes only. Your capital is at risk when trading in the financial markets. Past performance is not an indicator of future results. The use of ATJ Traders' content or 3rd party investment services is solely at your own discretion and responsibility.
    Affiliate Disclaimer:
    Links in the description contain affiliate links. ATJ Traders may receive rewards from clicks or purchases generated from those links.

Комментарии • 118

  • @sebavergarasassi6462
    @sebavergarasassi6462 Год назад +5

    Your example its amazing! Its better than the all mql5 documentation! I am very glad with you!

  • @ricardoalmeida6350
    @ricardoalmeida6350 Год назад +4

    Great video mate! Very nice starting point to develop a trading bot using python + MT5.

  • @NazimDulatov
    @NazimDulatov 2 месяца назад

    thank you very much for such an instructive and wonderful lesson, it's just super

  • @ATJTraders618
    @ATJTraders618  2 года назад +2

    What type of content do you want to see next? Do you want to see more code examples on different algo trading strategies? Do you want to see more backtests, strategy analysis or live trading? Or do you prefer to go more in-depth into the actual code? Please let me know and have a great day :).

    • @xiangli4314
      @xiangli4314 2 года назад +2

      Hi,thks for your video. It`s very very helpful for me ! I think this is a very good video serial for anyone who wants to learn trading by python.

    • @sammarieobrown6455
      @sammarieobrown6455 2 года назад

      @@xiangli4314 I so much agree!!

    • @sammarieobrown6455
      @sammarieobrown6455 2 года назад

      I see where you did a video on the long and short SMA cross over, could you do a short video on how to deploy it live? would love to see that

    • @FingerstyleLive
      @FingerstyleLive 2 года назад +1

      Can you show the example code of GRID trading with Martingale strategy?

    • @abdulmajeedtheone908
      @abdulmajeedtheone908 2 года назад

      how I can run my python code 24\7 in mt5 ?

  • @sangiansang
    @sangiansang 2 года назад

    Hey man, this is beautiful. Thanks.

  • @Dream_Boy_0
    @Dream_Boy_0 6 месяцев назад

    Thanks a lot bro.... Thank you so much for this wonderful video

  • @tigerthebrave2794
    @tigerthebrave2794 2 года назад

    Thank you and thank you again great content

  • @digitaldreamer495
    @digitaldreamer495 Год назад

    Excellent video, Thank's sir

  • @abdullahahmad9334
    @abdullahahmad9334 2 года назад

    you are good bro thank you again and again.

  • @FingerstyleLive
    @FingerstyleLive 2 года назад +1

    Thek you very much, I follow up on your content and it interested me. For the next content, can you show the example code of GRID trading with Martingale strategy?

  • @rajan6344
    @rajan6344 2 года назад +2

    Hi, it was a great presentation and good to see the nice code.
    Would you be able to share code or checked in some where please?

  • @limitedgain6433
    @limitedgain6433 2 года назад

    Thank you very much for sharing, But How can I stop the prompt to display any text, just run the algo without any output in the commandline?

  • @kampret06
    @kampret06 Год назад +2

    Hi there.. do you always run your code directly on demo account, or did you some backtesting before dropping the code on the account.?
    If you did backtesting it, how did you do it.?

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    I was knocked out by stop loss. But the indicator conditions were satisfied and the robot sent again the order. Again, the stop loss was knocked out so that it did not continue. You need to write a timeout for 1 hour in the code, for example. until the news spike passes

  • @Peter-kj1fm
    @Peter-kj1fm Год назад +1

    Salute Great content ..
    Am trading local Stokes and am trying to figure out if it is possible to create a price alert bot if non of the brokers in my area are featured on mt5.
    Thanks in advance

  • @harryowuor4851
    @harryowuor4851 Год назад +1

    great tutorial .though I encountered an error 'IndexError: single positional indexer is out of bounds' which occured between lines 93 and 121.I need your help debugging this please.

  • @fransjacowillemse6782
    @fransjacowillemse6782 Год назад +3

    Love your videos! to the point, have you ever done a bot that can choose a strategy based on a market condition, e.g. trending or ranging market then choose strat A or B or maybe adding some logic to determine the current market direction before executing the order, as some bots don't work well with certain market conditions, that way you can keep your bot running and it will only trade if the market is e.g. trending.

  • @jamesartemus8020
    @jamesartemus8020 Год назад +1

    how would you set the timeframe so that it runs through multiple time frames?

  • @anilvarma9893
    @anilvarma9893 Месяц назад

    Hi, is there any way to copy iCustom indicator or MQL Indicator buffer values into Python?

  • @Penta_Penguin_237
    @Penta_Penguin_237 2 года назад

    You are great Man! Just wanna say that. Thank you for all!

  • @gorgonzolasemfungo751
    @gorgonzolasemfungo751 8 месяцев назад

    TraderPy ---many thanks

  • @flubflub7896
    @flubflub7896 Год назад +1

    for me this doesnt work because you are setting the last close bar > sma to signal buy and vice versa. it doesnt mean buy when the price is above the moving average and sell when it is below the sma. when i run this code it sells when the last close bar of a timeframe specified if it is below the sma then sell and above then buy. when i look on your screen it seems your code runs differently for some reason.

  • @sayedmuzz5727
    @sayedmuzz5727 10 месяцев назад

    If I want to change my instrument what adjustment should I do?

  • @Suckaniggadickeveryday
    @Suckaniggadickeveryday Год назад

    hi i made this robot with some optimizations seperate robot for each pair but none of the orders are going through
    only the 1st one is plz help

  • @fbrand
    @fbrand 2 года назад +1

    Thank you again for laying our foundational understanding in these programs. What I wanted to know if you can also sometime show how to trade more than one currency pair and also what about trading the EU and EJ, then the decimals differ. Also as an add-on what is the best way to run these scripts, as I have previous tried and they run for a few hours, but then crash when just starting then straight from CMD. Cheers

    • @ATJTraders618
      @ATJTraders618  2 года назад +2

      Hey, regarding the decimals, you can adjust the point values based on the digit based on each symbol.
      Each symbol has its own decimal point value which you can get from symbol_info(). Therefore, the point value is easilly calculated using the following formula:
      point value = contract size / (10^digits)
      Regarding the script crash, there may be many causes. Do you have the error logged upon crash? If so, you can send me more details to tu@traderpy.com and I will happily have a further look.

  • @saltyxd55
    @saltyxd55 Год назад

    I love you man

  • @jayess2226
    @jayess2226 2 года назад +3

    I am new to Trading with Python but I wonder is there a more efficient way than to check for a signal with an infinite loop? Because therefore it requests the former close price many times per second but actually it would be enough to get the close price only when a bar is closed (so once a minute in your example).

    • @lovemaakhe
      @lovemaakhe 2 года назад +2

      you could use time.sleep(60) to pause the program between each loop iteration

  • @user-nn1hb1iu8i
    @user-nn1hb1iu8i Год назад

    It return me an error inside the function definition "signal()", it say to me "index out of bound", is it correct to change iloc[-1] with iloc[0] to target the first element?

  • @jorgeeliutharenasvalverde2363
    @jorgeeliutharenasvalverde2363 2 года назад +1

    Great content, would recomend you to add the overlap of a 10 and 15 EMAs as a signal in your enviroment.

    • @RobinArgumido
      @RobinArgumido 2 года назад

      Trading bots are mostly scams... but there are exceptions. You just need a lot a patience to backtest and run many bots, discard the ones that are scams and keep playing with the ones that are good. EDIT: since so many of you ask, yes I use Galileo FX..

    • @Sannsarca
      @Sannsarca Год назад

      @@RobinArgumido 😁

  • @mosaddiqbillah7124
    @mosaddiqbillah7124 Год назад

    I tried this code on JUPYTER NOTEBOOK and i was getting this error of "IndexError: single positional indexer is out-of-bounds" due to the "iloc" builtin function in the SIGNAL function definition whenever i run the code, if anyone can sort it out kindly. Thank you!

  • @merovechaureliand5974
    @merovechaureliand5974 10 месяцев назад

    Maybe I missed it, but where do you have a TP?

  • @sgaurav24
    @sgaurav24 10 месяцев назад

    Hi i have created sma cross over strategy on 5 min timeframe and i am getting tick by tick data but i need some help to updat code of one logic can ypu help me the same . I am happy to share the code

  • @aminmarogan2810
    @aminmarogan2810 Год назад

    Is it possible to get the stategy parameters from an INI file ?

  • @vikrant260
    @vikrant260 Год назад

    can you use this python script to backtest in MT5 terminal...If yes please make a video on that I couldn't find a single video on this topic.

  • @mrtumbi2974
    @mrtumbi2974 2 месяца назад

    Can I use it in Indian stock market

  • @keluargamabar
    @keluargamabar 11 месяцев назад

    how to applied this in nasdaq, bei, or stock market?

  • @socialanimalearth5718
    @socialanimalearth5718 Год назад

    did it try it with any exchanges in Cryptocurrency or you could try to optimize it with Binance exchange.

  • @bobmemer9062
    @bobmemer9062 Год назад

    how did you get the command prompt on mac?

  • @vanderberg8591
    @vanderberg8591 Год назад

    hi i coding that like but with supertrend . Can you share about like video? Thank you

  • @alpsgrin4501
    @alpsgrin4501 2 года назад

    please tell me what would you add in the code ??? to implement a stop sending an order ??? Or a slip function ??? if I added an indicator and the overbought or oversold zone did not come and do not want to enter a trade without confirmation of the second indicator

    • @ATJTraders618
      @ATJTraders618  2 года назад +1

      That is a good question. You can add an extra condition before you want to place on order.
      Let's say you have a crossover and you also want to check another condition, so the logic would look as follows:
      if bullish_crossover and rsi_oversold:
      Buy
      You can create a new indicator column and check other conditions as well which serve as filters for entries.

  • @sasupeter9102
    @sasupeter9102 Год назад

    IndexError: single positional indexer is out-of-bounds
    I gee this error when I try to run the code
    Please help

  • @ericyu9791
    @ericyu9791 2 года назад +1

    How to loop through all the symbols using this code ?😊

  • @gustavnilsson9589
    @gustavnilsson9589 9 месяцев назад

    Hey! This might be a dumb question, but how can it sell before it buys?

  • @cc-musics6382
    @cc-musics6382 2 года назад +1

    great but please teach us how to run our python but on a host or server because it just run on our computer because it need to run metatrader5.exe first in order to trade .thanks

  • @aspirantrade2697
    @aspirantrade2697 11 месяцев назад +1

    Hey. I recently discovered a lot of your videos on Python and trading because I am a student. I really enjoy it when a presentation goes into such detail and explains everything with codes. I also came across another such video by QuantInsti that talks about backtesting a trading strategy - "Full Algo Trading Course | Python Trading Bot | Python Quantitative Trading | 3/3".
    Quite curious to try both. Thank you!

  • @joaobuta3177
    @joaobuta3177 Год назад

    the source code link doesnt work , what can I do to open it on an IDE?

  • @TraderSam96
    @TraderSam96 10 месяцев назад

    Please help with how to set up the mql5 environment with python i keep getting this error
    "C:\Users\USER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\python.exe" -u "C:\Users\USER\AppData\Roaming\MetaQuotes\Terminal\A5862E2007921267C73493E43631301B\MQL5\Scripts\testing.py" unknown 1 failed
    in the mt5 journal and also
    'Python testing2': python process thread create error [The system cannot find the file specified. (2)]

  • @woltron4o
    @woltron4o 2 года назад

    Do you have any Github repos with this code?

  • @holaelectro3312
    @holaelectro3312 Год назад +1

    Can you elaborate a bit more on how order type is determined thru dictionary. The order type should written in full, for ex: mt5.ORDER_TYPE_BUY

  • @xiangli4314
    @xiangli4314 2 года назад +1

    Hi, I don't understand why u don't active this robot directly with ur code editor?(like: pycharm)

    • @ATJTraders618
      @ATJTraders618  2 года назад

      Hi Xiang Li, it is a habit of mine to run finished code in the command prompt. PyCharm is a heavy IDE and may take up alot of memory. When deploying robots on a VPS, you want to maximize resources.
      I do run my code in PyCharm for testing purposes but for this video, I decided to present it it cmd window.

  • @amosbiwott4084
    @amosbiwott4084 Год назад

    Can you please share on how to convert SMA to EMA.

  • @lukassimonik594
    @lukassimonik594 Год назад

    HI, where is set up the connection to the metatrader account? only if I run the python script in windows cmd, it will be worked? Thanks

    • @OswaldShoo
      @OswaldShoo 9 месяцев назад

      Did you find the answer yet i have the same question

  • @priyankachaudhary6816
    @priyankachaudhary6816 Год назад

    I have also built a trading bot...but I am having some issues...so i need your help.

  • @thanhtungnguyen5806
    @thanhtungnguyen5806 2 года назад

    I can't install MT5 lib on mac
    Could not find a version that satisfies the requirement MetaTrader5 (from versions: none)

  • @chagbertmoney
    @chagbertmoney 7 месяцев назад

    Great video! I have installed pandas & MT5 successfully, however I am getting errors in code (after MT5 is opened with focus on instrument e.g. EURUSD): 'DataFrame' object has no attribute 'close' and another one 'IndexError: single positional indexer is out-of-bounds' .. how can I resolve these.

    • @ATJTraders618
      @ATJTraders618  7 месяцев назад

      Hi, most likely, the DataFrame is empty. Please make sure that all symbols in the market watch are enabled.
      Also, try to enter a shorter time period in MT5. Sometimes, when the period is too long, it won't return any data.

  • @alexkhan7683
    @alexkhan7683 5 месяцев назад

    When I try to run the code like you in the command prompt, it does show that the code is analyzing the MT5 data. But no trades are opening on my MT5. What problem might I have? How can I fix it?

    • @ATJTraders618
      @ATJTraders618  5 месяцев назад

      Hi, do you receive any message back when you send an order? Please make sure that Auto Trading is enabled in the MetaTrader5 platform.

    • @alexkhan7683
      @alexkhan7683 5 месяцев назад +1

      Got it! Seemed to work now, what had happened was I needed to change the 'mt5.ORDER_FILLING_IOC' to 'mt5.ORDER_FILLING_FOK'. Would you know how I can write code to input stop loss and take profit for my risk management? Thanks for all the helpful videos

  • @samclaudemirlee9870
    @samclaudemirlee9870 Год назад

    What's your coding environment like? Can you deploy on linux?

    • @ATJTraders618
      @ATJTraders618  Год назад

      I use windows VPS where I deploy using Remote Desktop Connection.

  • @amosbiwott4084
    @amosbiwott4084 Год назад

    Hello Sir. its an amazing script. i would like to make it take profit once the trade runs in profit in seconds. how can i do that?

  • @LucasAlves-rw2ch
    @LucasAlves-rw2ch Год назад

    I really need your help in your code, it runs perfectly, the only parameter missing is stoploss and takeprofit
    I'm trying to put a stoploos of 20 points and a takeprofit and 1 point, but when I do that it doesn't send the orders to the market

    • @ATJTraders618
      @ATJTraders618  Год назад +1

      Hi, try to use floats instead of integers. Also sl and tp params are set as exact price levels.

    • @LucasAlves-rw2ch
      @LucasAlves-rw2ch Год назад

      @@ATJTraders618 Ok, I contacted your email explaining better, thanks for the help

  • @realchad9040
    @realchad9040 Год назад

    Hello. Can you create multihedge strategy with python?

    • @ATJTraders618
      @ATJTraders618  Год назад

      Hi, do you have any link where I can read more details about this strategy?

  • @linnomgroup
    @linnomgroup 6 месяцев назад

    Can i use this script for volitality index?

    • @ATJTraders618
      @ATJTraders618  6 месяцев назад

      Hi, yes of course. All you need to find a broker who offers trading the VIX. IC Markets, the broker I'm affiliated with, offers it. Check the description for more info. :)

  • @emmanuelajayi4059
    @emmanuelajayi4059 Год назад

    Hello, Nice Video
    Please i have a trading strategy that i want to turn into a trading bot

  • @Muhammadanaskhans
    @Muhammadanaskhans 10 месяцев назад

    hello sir i am new here i want your help sir please sir kindly write a code on crossing moving averages exponential method where two line cross over take buy or sell

  • @kannadastories652
    @kannadastories652 2 года назад +1

    Bro code price action strategy algo

  • @vandesar9114
    @vandesar9114 2 года назад

    Please create a video of trading robot using Machine Learning or Some Ai Tools inside the Python . Thanks

    • @ATJTraders618
      @ATJTraders618  2 года назад +4

      Hi Van De Sar, I am currently studying ML but as of this moment, I don't have enough practice to be confident in presenting this topic. Maybe sometime in the future.
      I do recommend Ernest Chan who is a great role model in developing ML models for trading: ruclips.net/video/BhaJVZNpL4M/видео.html

    • @vandesar9114
      @vandesar9114 2 года назад

      @@ATJTraders618 Don't worry, I just made a suggestion for your future plans. The videos you currently make are great.

  • @iceance5948
    @iceance5948 2 года назад

    Can I run it using VS CODE?

  • @elifkaragoz2606
    @elifkaragoz2606 2 года назад

    last_close = bars_df.iloc[-1].close
    it gives an "IndexError: single positional indexer is out-of-bounds" in the line above. What should i do? why we index it to [-1]?

  • @Day1kingfx
    @Day1kingfx Год назад

    Can you run the code on mt4?

  • @viettuannguyen1638
    @viettuannguyen1638 2 года назад

    could u share the code scripts as text so I can copy to run on my server?

  • @tommy2598
    @tommy2598 Год назад

    good day bro, if you can read my comment, I came across this tutorial and it is very useful but it seems it does not work anymore.

  • @itsely6608
    @itsely6608 11 дней назад

    Maybe it’s worth adding a command (Sleep) so that the broker doesn’t ban you for the number of requests to the exchange???

    • @ATJTraders618
      @ATJTraders618  10 дней назад

      From our experience, the requests do not interfere with the broker server and the it shouldn't cause a problem. A sleep function of 1 second is implemented in the code already.

  • @wongchenkeat1842
    @wongchenkeat1842 Месяц назад

    MetaTrader 5 library no longer working in python.

  • @Dream_Boy_0
    @Dream_Boy_0 6 месяцев назад

    Can anyone plz suggest me the documentation

    • @ATJTraders618
      @ATJTraders618  6 месяцев назад

      Hi, you can find the documentation for MT5 and the source code in the descriptions.

  • @Ichsanulkamil252
    @Ichsanulkamil252 Год назад

    i have error 'unsupported filling mode'

    • @ATJTraders618
      @ATJTraders618  Год назад

      Hi, it means that your broker only accepts certain order types.
      You can specify it filling type parameter and try different values like:
      FOK
      GTC
      IOC

  • @devngecu
    @devngecu 2 года назад

    Source code?

  • @nadeemrazani
    @nadeemrazani 2 года назад

    Statistical Arbitrage!!!👋👋👋👋👋

  • @Peter-kj1fm
    @Peter-kj1fm Год назад

    Hola

  • @aspirantrade2697
    @aspirantrade2697 11 месяцев назад

    Such a great video! It seriously helped me create my very own trading bot. If you're a beginner like me, this video is a must-watch.
    Also, check out "Algorithmic Trading Tutorial Python | Build Trading Algorithm from Scratch" by QuantInsti - another awesome video that helped me understand the fundamentals of algorithmic trading and build my own algorithm. Super helpful and definitely worth watching!
    Big thanks to both videos for giving me the knowledge and confidence to create my trading bot. Can't wait to see what it can do! 😄🚀