@@ -224,18 +224,6 @@ def open_buy_position(self, comment: str = "") -> None:
224
224
Returns:
225
225
None
226
226
"""
227
- # Check trade mode to see if Buy operations are allowed
228
- symbol_info = Mt5 .symbol_info (self .symbol )
229
- if symbol_info .trade_mode == 0 :
230
- logger .warning (f"Cannot open Buy position for { self .symbol } - trading is disabled." )
231
- return
232
- if symbol_info .trade_mode == 2 : # Short only
233
- logger .warning (f"Cannot open Buy position for { self .symbol } - only Sell positions are allowed." )
234
- return
235
- if symbol_info .trade_mode == 4 and len (Mt5 .positions_get (symbol = self .symbol )) == 0 :
236
- logger .warning (f"Cannot open Buy position for { self .symbol } - symbol is in 'Close only' mode." )
237
- return
238
-
239
227
point = Mt5 .symbol_info (self .symbol ).point
240
228
price = Mt5 .symbol_info_tick (self .symbol ).ask
241
229
@@ -268,18 +256,6 @@ def open_sell_position(self, comment: str = "") -> None:
268
256
Returns:
269
257
None
270
258
"""
271
- # Check trade mode to see if Sell operations are allowed
272
- symbol_info = Mt5 .symbol_info (self .symbol )
273
- if symbol_info .trade_mode == 0 :
274
- logger .warning (f"Cannot open Sell position for { self .symbol } - trading is disabled." )
275
- return
276
- if symbol_info .trade_mode == 1 : # Long only
277
- logger .warning (f"Cannot open Sell position for { self .symbol } - only Buy positions are allowed." )
278
- return
279
- if symbol_info .trade_mode == 4 and len (Mt5 .positions_get (symbol = self .symbol )) == 0 :
280
- logger .warning (f"Cannot open Sell position for { self .symbol } - symbol is in 'Close only' mode." )
281
- return
282
-
283
259
point = Mt5 .symbol_info (self .symbol ).point
284
260
price = Mt5 .symbol_info_tick (self .symbol ).bid
285
261
@@ -383,27 +359,24 @@ def _handle_position_by_trade_mode(
383
359
self .total_deals += 1
384
360
385
361
def open_position (self , * , should_buy : bool , should_sell : bool , comment : str = "" ) -> None :
386
- """Open a position based on buy and sell conditions.
362
+ """Open a position based on the given conditions.
387
363
388
364
Args:
389
- should_buy (bool): True if a Buy position should be opened, False otherwise .
390
- should_sell (bool): True if a Sell position should be opened, False otherwise .
391
- comment (str): A comment for the trade .
365
+ should_buy: Whether to open a buy position.
366
+ should_sell: Whether to open a sell position.
367
+ comment: Optional comment for the position .
392
368
393
369
Returns:
394
370
None
395
371
"""
396
- symbol_info = Mt5 .symbol_info (self .symbol )
397
-
398
- # Check trade mode restrictions
399
- if self ._handle_trade_mode_restrictions (symbol_info ):
400
- return
401
-
402
372
# Open a position if no existing positions and within trading time
403
- if (len (Mt5 .positions_get (symbol = self .symbol )) == 0 ) and self .trading_time ():
404
- self ._handle_position_by_trade_mode (
405
- symbol_info , should_buy = should_buy , should_sell = should_sell , comment = comment
406
- )
373
+ if self .trading_time ():
374
+ if should_buy and not should_sell :
375
+ self .open_buy_position (comment )
376
+ self .total_deals += 1
377
+ if should_sell and not should_buy :
378
+ self .open_sell_position (comment )
379
+ self .total_deals += 1
407
380
408
381
# Check for stop loss and take profit conditions
409
382
self .stop_and_gain (comment )
0 commit comments