Coder Social home page Coder Social logo

Comments (6)

kieran-mackle avatar kieran-mackle commented on May 17, 2024

Hey Lewis, the KeyError above is popping up because you haven't specified the indicator type as STOCHASTIC (the key you have named 'STOCHASTIC' is just the string used to label the indicator on the chart), but you have made me realise that I have actually deprecated the stochastic key, so apologies for the stale docs/code.

The preferred way to plot this would be using type: multi, as per the example below.

self.indicators = {"RSI": {"type": "RSI", "data": self.stoch_rsi},
                   "STOCHASTIC": {"type": "multi",
                                  "K": {"data": self.stoch_rsi_k, "color": "blue"},
                                  "D": {"data": self.stoch_rsi_d, "color": "red"},
                                  },
                   }

I think I decided to remove the STOCHASTIC type as the multi type is much more general and customisable, though I probably should have made the change clearer...

As per your other questions:

  • Yes, you can do this using the get_trades method, with the argument trade_status = 'closed'. This will return all closed trades taken for the instrument/s specified, ordered by time closed (it is basically indexing broker.trades. Some notes: this functionality (specific retrieving closed trades) is currently only supported in the virtual broker, ie. in backtesting. To call this method from your strategy, you will need to include INCLUDE_BROKER: True in your strategy configuration - see the docs here for an example.
  • I have a feeling this is due to a margin call occurring, a feature implemented in v0.6.1. To check if it is, try increasing the broker_verbosity to 1 via the configure method - this will print when a margin call occurs. This should only happen if you are trading on margin (ie. leverage is set greater than 1), and if your margin fraction (available margin/NAV) drops below the margin_call_fraction. However, I am assuming you will not have changed the margin_call_fraction from the default of 0, so the only way for this to occur is if your margin available or NAV goes negative. So another check would be to print the NAV each update. If these suggestions don't help, or don't seem relevant, let me know and we can figure out what's going on.

from autotrader.

lleewwiiss avatar lleewwiiss commented on May 17, 2024

When using 1 leverage I get Insufficient margin to fill order. printed for every trade, I am testing it on ETH-USD is this because for a 10,000 account it cannot trade partial amounts with a 1% risk e.g. 1ETH is more than 1%*10000 and with 1 leverage it can't make the trade, therefore, it cancels it

from autotrader.

kieran-mackle avatar kieran-mackle commented on May 17, 2024

I can't seem to replicate the issue (tried the macd demo strategy active in the demo runfile), and partial trades are allowed by default.

Looking into the code a bit deeper, I think this is coming from the get_size method of the broker utilites, and likely the get_pip_ratio method. The latter method is currently focused towards forex pairs, so might produce unexpected results for non FX instruments. I will need to fix this up to make it more general.

Basically what it looks like is happening, is that your stop losses are too tight (whether true, or not true due to an incorrect pip_value) forcing the trade size required to risk 1% up too high. This size then gets cancelled when the order reaches the broker, because although the trade would only lose 1% if the stop was hit, the margin required to open such a large trade is greater than the account margin available.

Sorry about the bug, but I can suggest a work around in the meantime: copy the get_size method into your strategy module, and provide the correct pip_value (line 82). Then just call this method to calculate the size and provide it when creating your orders.

from autotrader.

lleewwiiss avatar lleewwiiss commented on May 17, 2024

Thanks, I will give it a try. I can give you the exact data/strategy if you would like to use it for debugging, its only a simple one

from autotrader.

kieran-mackle avatar kieran-mackle commented on May 17, 2024

No problem, let me know how you go. And sure, feel free to email it to me: [email protected]

from autotrader.

lleewwiiss avatar lleewwiiss commented on May 17, 2024

It seems to be a problem with RISK_PC using the macd strategy from the demo (latest version) with leverage set to 1 and RISK_PC set to 3 it gets all cancelled trades on EURAUD and mostly cancelled on ETH-USD. Might help with debugging.

from autotrader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.