SymbolInfoTick().
Martin Bittencourt:
Hi!
Which is the fastest way of getting the current price?
Option 1:
Option 2:
Option 3:
Some other option 4
I would bet in Option 2, but I'm asking just to be sure. :)
priceCurrent() by CSymbolInfo class... no? Or, if you have a selected position position.PriceCurrent() (by CPositionInfo class).
I have a problem...how to close a trade at the opening price of the next red candle
def execute_sell_trade(df, symbol, lot_size=0.2): """ Executes the RSI sell trade based on the given strategy conditions. Parameters: df (pd.DataFrame): DataFrame containing historical data, including RSI values. symbol (str): The trading symbol to execute the sell trade. lot_size (float, optional): The lot size for the sell trade. Default is 0.2. Returns: None Explanation: The `execute_sell_trade` function implements the sell part of the RSI (Relative Strength Index) strategy based on specific conditions. The strategy aims to capture potential overbought market conditions using the RSI indicator. The sell trade is taken when the RSI value is above 70, and a particular candle pattern is observed. Sell Conditions: 1. RSI is above 70, indicating an overbought market. 2. The candle two periods ago (confirmation candle) is green (close > open). 3. The previous candle (immediate previous to the current candle) is red (close < open). 4. The current candle (most recent) is also red (close < open). Execution: Once all the sell conditions are met, a sell trade is executed at the current market price. The trade is taken on the next red candle after the green confirmation candle. This means that when all conditions are satisfied, the function opens a sell trade at the open price of the next red candle. Exit: The trade remains open until the close of the second red candle after the confirmation candle. The exit time and exit price are recorded based on the close price of the second red candle. Note: In a real trading scenario, additional risk management and stop-loss mechanisms should be implemented to mitigate potential losses. """ current_bar = df.iloc[-1] previous_bar = df.iloc[-2] confirmation_bar = df.iloc[-3] # Check for sell conditions if current_bar["rsi"] > 70 and confirmation_bar["close"] > confirmation_bar["open"] \ and previous_bar["close"] < previous_bar["open"] \ and current_bar["close"] < current_bar["open"]: if not mt5.initialize(): print("initialize() failed ☢️") mt5.shutdown() return # Execute the trade on the next red candle (Candle 3 in the description) request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot_size, "type": mt5.ORDER_TYPE_SELL, "price": mt5.symbol_info_tick(symbol).bid, "deviation": 10, "magic": 0, "comment": "RSI Sell Strategy", "type_filling": find_filling_mode(symbol), "type_time": mt5.ORDER_TIME_GTC } result = mt5.order_send(request) mt5.shutdown() if result.comment == "Accepted": print("Sell executed") # Wait for the trade to close (at the close of the second red candle) while True: new_bar = get_historical_data(symbol, mt5.TIMEFRAME_M1, 1) if new_bar is not None: if new_bar.iloc[0]["close"] < new_bar.iloc[0]["open"]: break time.sleep(1) print("Trade closed") else: print("Error executing the trade")
This is the part of the function responsible for closing the trade
if result.comment == "Accepted": print("Sell executed") # Wait for the trade to close (at the close of the second red candle) while True: new_bar = get_historical_data(symbol, mt5.TIMEFRAME_M1, 1) if new_bar is not None: if new_bar.iloc[0]["close"] < new_bar.iloc[0]["open"]: break time.sleep(1) print("Trade closed") else: print("Error executing the trade")
Thank you in advance for your help
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi!
Which is the fastest way of getting the current price?
Option 1:
Option 2:
Option 3:
if (SymbolInfoTick)
Some other option 4
I would bet in Option 2, but I'm asking just to be sure. :)