Skip to content

unable to unset stop loss #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vism211 opened this issue Jan 6, 2025 · 5 comments
Open

unable to unset stop loss #64

vism211 opened this issue Jan 6, 2025 · 5 comments

Comments

@vism211
Copy link

vism211 commented Jan 6, 2025

I'm trying to implement a method to unset SL but i receive back order_error "1" / order_return_message "Error in modify").

This is what i'm doing: success = MT.Set_sl_and_tp_for_position( ticket = ticket ,stoploss = 0 ,takeprofit = position['take_profit'] ) where position['take_profit'] is the actual take profit already set on the position.

Testing with stoploss values grater than actual entry (position is a sell), succeeds

@Sedik7
Copy link

Sedik7 commented Apr 8, 2025

Dear Sir , hope this email found you well

I hope this email finds you well. I am writing to provide feedback and report several persistent issues encountered while implementing your PyTrader API for MT4/MT5 connectivity. We've been working on a Forex data collection system, and I wanted to share our findings to help improve the API.

Key Issues Encountered:

  1. Data Format Inconsistencies

    • The Get_last_x_bars_from_now() method sometimes returns string-formatted data instead of the expected list format
    • Inconsistent delimiter usage in string responses (using '$' separator)
    • No clear documentation on how to parse these different response formats
  2. Method Availability and Documentation

    • The Get_last_tick_info() method appears in documentation but doesn't exist in the API
    • Some methods like Symbol_select_tick() have unclear return value specifications
    • Missing documentation about error codes and their meanings
  3. Connection Management

    • Intermittent connection drops without clear error messages
    • Socket errors not providing sufficient detail for debugging
    • No automatic reconnection mechanism in case of connection loss
  4. Error Handling

    • The socket_error and command_return_error states sometimes remain set even after successful operations
    • Timeout values are not consistently respected
    • Error messages don't always correspond to the actual issue

Suggested Improvements:

  1. Data Handling

    • Standardize return formats across all methods
    • Provide clear documentation on data structure and parsing
    • Add helper methods for common data format conversions
  2. Documentation

    • Update method documentation to match actual implementation
    • Add comprehensive error code reference
    • Include more usage examples, especially for error handling
  3. Connection Management

    • Implement automatic reconnection mechanism
    • Add detailed connection state reporting
    • Provide connection health check method
  4. Error Handling

    • Reset error states after each operation
    • Implement more detailed error reporting
    • Add method-specific error codes

We have implemented various workarounds for these issues, but addressing them at the API level would greatly improve the user experience. I would be happy to provide more detailed information or test cases if needed.

Current Workarounds Implemented:

# Example of our current workaround for data format inconsistency
def parse_rates(raw_response):
    if isinstance(raw_response, str):
        # Handle string format with $ delimiter
        return [tuple(map(float, row.split('$'))) for row in raw_response.split(';')]
    return raw_response  # Assume list format

Would you be interested in our complete test suite that demonstrates these issues? We'd be happy to contribute to improving the API's reliability and usability.

Thank you for your time and consideration.

Best Regards
Sedik

@Branly76
Copy link
Collaborator

Branly76 commented Apr 8, 2025

First of all thank you for your comments. At the moment i'm working on an update of the Pytrader_API for several reasons. I have to say documentation is rather old and not all OK. Also on that i'm working. I did already a lot of refactoring the code.
Anyway i will check all your comments.
Just one question, which version are you using?

Best regards

@Branly76
Copy link
Collaborator

Hi Sedik,

Some answers on your remarks.

I assume you do not use the last version or not the same versions for EA and pytrader_api.
The Get_last_tick_info() is already a very long, long time in the pytrader_api.
The Symbol_select_tick() function is never coded, so can not be avaialable.

It is always pytrader_api asks and the EA gives an answer.
So automatic reconnecting would be an exception.
It then also ca happen because of automatic reconnection as user you would not notice that there is something not wel working.
pytrader_api has a Check_connection() function.
Reset of error states is now done
For the results of the different function we have:
. np.array
. dataframe
. dictionairy
This is a matter of taste, one likes more lists, on other dataframe, again another ....

Get_last_x_bars_from_now() gives always np.array as result.
It is strange to me that you see any ^,#,$ in the result of a function call.

But if you specific improvements we can always talk.

Version 4.01 will be posted very soon. Better documentation.

Best regards,
Branly

@Branly76
Copy link
Collaborator

All functions have this kind of documentation at hoovering:
"""
Retrieves instrument information.

    Args:
        instrument (str): instrument name

    Returns:
        dict: Dictionary with:
            instrument (str): instrument name
            digits (int): number of decimal places
            max_lotsize (float): maximum lot size
            min_lotsize (float): minimum lot size
            lot_step (float): step size for lot size
            point (float): point value
            tick_size (float): tick size
            tick_value (float): tick value
            swap_long (float): swap value for long positions
            swap_short (float): swap value for short positions
            stop_level (int): stop level for SL and TP distance
            contract_size (float): contract size
    """

@Sedik7
Copy link

Sedik7 commented Apr 11, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants