Working with Python in MT5 and plotting directly to charts

 
Hello,
I am brand new to MT5, and the Python intergration is what really appeals to me. 
I went to File--> New and selected Python Script. 
then went to Matplotlib. and wrote a basic script 
import MetaTrader5 as mt5
import matplotlib.pyplot as plt
from datetime import datetime

# Initialize connection to MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed")
    mt5.shutdown()
    quit()

# Fetch daily bar data for the EURUSD symbol
symbol = "EURUSD"
today = datetime.now()
rates = mt5.copy_rates_from(symbol, mt5.TIMEFRAME_D1, today, 1)

# Shutdown connection to MT5
mt5.shutdown()

# If data was received, plot it
if rates is not None and len(rates) > 0:
    # Prepare the data for plotting
    high_price = rates[0][2]  # High price
    low_price = rates[0][3]   # Low price
    mid_price = (high_price + low_price) / 2  # Mid price
    
    # Plot the high, low, and mid prices
    plt.figure(figsize=(10, 5))
    plt.axhline(y=high_price, color='g', linestyle='-', label='High of Day')
    plt.axhline(y=low_price, color='r', linestyle='-', label='Low of Day')
    plt.axhline(y=mid_price, color='b', linestyle='-', label='Mid of Day')

    plt.title(f'{symbol} Daily High, Low, and Mid Prices')
    plt.xlabel('Time')
    plt.ylabel('Price')
    plt.legend()
    plt.show() 
Improperly formatted code edited by moderator.
The plot shows up in a pop up window that is Matplotlib. My question is how do I plot from python to the actual MetaQuotes Chart? 
Any guidance or documentation links would be appreciated
Documentation on MQL5: Python Integration / copy_rates_from
Documentation on MQL5: Python Integration / copy_rates_from
  • www.mql5.com
copy_rates_from - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Joshua Dawson: The plot shows up in a pop up window that is Matplotlib. My question is how do I plot from python to the actual MetaQuotes Chart? 

You can't! At least, not directly. That is reserved for the MQL5 language.

The Python API is for running Python scripts externally and using MetaTrader 5 as a service to supply the data and to relay trading instructions.

The API does not expose any other functionality and you cannot interact with its user interface in any direct way.

For more direct interaction, you should use MQL5 which offers more functionality. It is a compiled language, similar in syntax, logic and speed as C/C++.

 

Please do not think I am arguing, I am not, i sincerely appreciate your time, I am just trying to understand. So even if we select Python Script from the MQL Wizard File, MetaTrader 5 is just giving us another option for an IDE? And then I create a MQL5 file that pulls the data from the VPS/Local machine for the LTSM models? And by doing it this way, I can have my models plot the projections? Am I correct in my thinking or way off base here?

 
Joshua Dawson #Please do not think I am arguing, I am not, i sincerely appreciate your time, I am just trying to understand. 

I was not arguing either! There was no emotion in my post. It was just a detailed reply to your question.

Joshua Dawson #: So even if we select Python Script from the MQL Wizard File, MetaTrader 5 is just giving us another option for an IDE?

Yes! It is somewhat misleading in my opinion because it leads novices to believe that Python somehow interacts with MetaTrader directly.

Joshua Dawson #: And then I create a MQL5 file that pulls the data from the VPS/Local machine for the LTSM models? And by doing it this way, I can have my models plot the projections? Am I correct in my thinking or way off base here? 

Sorry, but I am unable to offer an adequate answer, because I have no ideia about your specific project requirements.

 
Fernando Carreiro #:

I was not arguing either! There was no emotion in my post. It was just a detailed reply to your question.

Yes! It is somewhat misleading in my opinion because it leads novices to believe that Python somehow interacts with MetaTrader directly.

Sorry, but I am unable to offer an adequate answer, because I have no ideia about your specific project requirements.

Fernando, 
My apologies, I wasn't suggesting you were being argumentative, I was making sure that my reply didn't sound like being argumentative to your advice.
LOL It is very misleading, I was like wow I can plot directly from Python this is a game changer!!!!! 

I am going to do more research on your guidance, so I know how to implement my strategies correctly. 

I wanted to thank you for all your help today, quick responses, and professionalism. 

I look forward to many more conversations my friend, take care.