| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|
| | !pip install MetaTrader5 plotly pandas --quiet
|
| |
|
| |
|
| |
|
| |
|
| | import MetaTrader5 as mt
|
| | import pandas as pd
|
| | import plotly.graph_objects as go
|
| | from plotly.subplots import make_subplots
|
| |
|
| |
|
| |
|
| |
|
| | if not mt.initialize():
|
| | raise RuntimeError("MT5 initialization failed")
|
| | symbol = "XAUUSDm"
|
| | timeframe = mt.TIMEFRAME_M5
|
| | num_candles = 500
|
| |
|
| |
|
| |
|
| |
|
| | rates = mt.copy_rates_from_pos(symbol, timeframe, 0, num_candles)
|
| | df = pd.DataFrame(rates)
|
| | df['time'] = pd.to_datetime(df['time'], unit='s')
|
| | df.set_index('time', inplace=True)
|
| |
|
| |
|
| | df.rename(columns={
|
| | 'open': 'Open',
|
| | 'high': 'High',
|
| | 'low': 'Low',
|
| | 'close': 'Close',
|
| | 'tick_volume': 'Volume'
|
| | }, inplace=True)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | df['Delta'] = df.apply(
|
| | lambda row: row['Volume'] if row['Close'] > row['Open']
|
| | else (-row['Volume'] if row['Close'] < row['Open'] else 0),
|
| | axis=1
|
| | )
|
| |
|
| | print(df.head())
|
| |
|
| |
|
| |
|
| | fig = make_subplots(
|
| | rows=2, cols=1,
|
| | shared_xaxes=True,
|
| | vertical_spacing=0.03,
|
| | row_heights=[0.7, 0.3],
|
| | subplot_titles=(f'{symbol} Price', 'Volume (Delta Colored)')
|
| | )
|
| |
|
| |
|
| | fig.add_trace(go.Candlestick(
|
| | x=df.index,
|
| | open=df['Open'],
|
| | high=df['High'],
|
| | low=df['Low'],
|
| | close=df['Close'],
|
| | name='Price'
|
| | ), row=1, col=1)
|
| |
|
| |
|
| | colors = ['green' if d > 0 else ('red' if d < 0 else 'gray') for d in df['Delta']]
|
| | fig.add_trace(go.Bar(
|
| | x=df.index,
|
| | y=df['Volume'],
|
| | marker_color=colors,
|
| | name='Volume'
|
| | ), row=2, col=1)
|
| |
|
| |
|
| |
|
| |
|
| | fig.update_layout(
|
| | title=f'{symbol} Candlestick + Volume (Delta Colored)',
|
| | xaxis_rangeslider_visible=False,
|
| | template='plotly_dark',
|
| | height=700
|
| | )
|
| |
|
| |
|
| | fig.update_yaxes(title_text="Price", row=1, col=1)
|
| | fig.update_yaxes(title_text="Volume", row=2, col=1)
|
| |
|
| | fig.update_layout(
|
| | xaxis_rangeslider_visible=True
|
| | )
|
| |
|
| | fig.update_xaxes(
|
| | rangeslider_visible=True,
|
| | rangeslider_thickness=0.05
|
| | )
|
| |
|
| |
|
| | fig.show()
|
| |
|