Skip to content
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

Exec Strategy create a lots order when trade=true #32

Open
1 of 4 tasks
duylddev opened this issue Mar 8, 2023 · 0 comments
Open
1 of 4 tasks

Exec Strategy create a lots order when trade=true #32

duylddev opened this issue Mar 8, 2023 · 0 comments

Comments

@duylddev
Copy link

duylddev commented Mar 8, 2023

Issue type

  • bug
  • missing functionality
  • performance
  • feature request

Brief description

When trade=true in strategyOptions, default MACD strategy creates a lot of order. It should create only 1 order
My assumption is bfx-strategy-exec create 1 order everytime receive trade event, but 1m timeframe, we'll receive a lot of trades that lead to create a lot of orders

Steps to reproduce

const strategyOptions = {
        symbol,
        timeframe,
        trades: false,
        candleSeed: candle_seed,
        capitalAllocation,
        maxDrawdownPerc,
        stopLossPerc,
      }

default MACD strategy

{
      onPriceUpdate: `\nconst whenLong = async (state = {}, update = {}) => {\n  const { price, mts } = update\n  const { macd } = HFS.indicatorValues(state)\n\n  if (macd.macd < macd.signal) {\n    return HFS.closePositionMarket(state, { price, mtsCreate: mts })\n  }\n\n  return state\n}\n\nconst lookForTrade = async (state = {}, update = {}) => {\n  const { price, mts } = update\n  const { macd } = HFS.indicators(state)\n  const current = macd.v()\n  const previous = macd.prev()\n\n  if (macd.l() < 2) {\n    return state // await sufficient data\n  }\n\n  const crossedOver = (\n    (current.macd >= current.signal) &&\n    (previous.macd <= previous.signal)\n  )\n\n  if (crossedOver) {\n    return HFS.openLongPositionMarket(state, {\n      mtsCreate: mts,\n      amount: 0.001,\n      price\n    })\n  }\n\n  return state\n}\n\n({ HFS, HFU }) => async (state = {}, update = {}) => {\n  const position = HFS.getPosition(state)\n\n  if (!position) {\n    return lookForTrade(state, update)\n  }\n\n  if (HFS.isLong(state)) {\n    return whenLong(state, update)\n  }\n\n  return state\n}`,
      defineIndicators:
        "(I) => {\n  const indicators = {\n    macd: new I.MACD([10, 26, 9])\n  }\n\n  indicators.macd.color = '#00ff00'\n\n  return indicators\n}",
    }
Additional Notes:
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

1 participant