Giter VIP home page Giter VIP logo

Comments (11)

JDJoe avatar JDJoe commented on May 22, 2024
  1. Margin trade (define margin level) with the order

in actions.py, you change the order line to:
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']), { 'leverage': data["leverage"] })

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024
  1. Stop loss order
    This works and also with margin.

This is how I used it in "Tradingview alert message:

{"type": "stop-loss", "side": "sell", "amount": "100", "symbol": "BCH/EUR", "price": "321", "leverage": "2", "key": "yourkeyhere"}

from tradingview-webhooks-bot.

LPX55 avatar LPX55 commented on May 22, 2024

@JDJoe https://github.com/Robswc/tradingview-webhooks-bot/tree/lda/webhook-bot

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024

Interesting. BTW, I can barely read code (I am not a programmer) but do I understand it correctly, you have moved the stop loss calculation to the bot side?

Not sure, if this is a good idea because this information should come from the strategy running on TradingView and it can be different for trading pairs. For example, I use volatility to calculate the possible SL and it's not a % percentage from last price.

I personally hope this bot remains as dumb as possible - only facilitate outside commands.

Maybe, in the future, it should be able to check did your limit order get filled and if not, do something about it.

from tradingview-webhooks-bot.

LPX55 avatar LPX55 commented on May 22, 2024

@JDJoe At the time I wrote it PineScript was still very limited in what info it can pass on (variables). If you look closely you'll see a file called talib.py which I never got around to. Had some personal issues to deal with the past 3 months. Ideally you'd want to calculate stop losses server-side, as even a few seconds can make a huge difference. The hard part is getting a constant stream of reliable data without any downtime, which TV is particularly good at. There's many ways to approach this I guess

from tradingview-webhooks-bot.

robswc avatar robswc commented on May 22, 2024

Most of the requests here can be done within the bot's "send order" action (as it was intended) BUT I am working on a branch that will allow for "blueprints" of sorts. It's been awhile since I worked with this bot, so I might get it wrong but for the following:

Stop Loss & Take Profit:

Should be possible by setting it to "StopLimit" or "StopMarket". Take profit can be done with a limit order, set to POST only, or "ParticipateDoNotInitiate" in the custom parameters. It should be possible, something like this:

order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']), params={'execInst': 'ParticipateDoNotInitiate'})

The bot is basically a ccxt trigger that runs when it gets a TV alert.

I could add the ability to cancel orders made by the bot, I would say this might not be totally efficient though, as it would have to grab the order ID from the exchange, then there would also have to be a way for the alert to know which order you're trying to cancel. It could be "last order" or "3rd from last" etc. Beyond that though would be a bit difficult.

You could do multiple orders even, if you want. Getting price:

exchange.fetch_ticker('XBTUSD')) for example. Then just run your stop/profit formula, and copy the "order = exchange..." to create 3 orders, essentially a bracket order.

Let me know how it works out!

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024
  1. Take profit

You can do this right now if you use limit order. This will give you a little kickback on fees too.
So, When going short, place limit buy order at what ever level below the current market and opposite for the long position - limit sell at something above the market.

To keep it simple:
When entering a new order:

  1. Cancel all open orders for the symbol XYZ (get rid of your previously placed SL, TP etc)
  2. Place your new order for symbol XYZ (market, limit, stop)
  3. Place new take profit ((stop) limit sell or buy) for XYZ at some price level.

What is really important is to execute all this in one single TradingView message so it can be processed in correct order.
Because the "key" is really long, TV wont be able to handle 3 x key + orders in one message.

from tradingview-webhooks-bot.

robswc avatar robswc commented on May 22, 2024

Ah, I see. I'm currently working on a new version that allows for placing a take profit and stop with one alert, it might only work with market orders to start though.

In the mean time, try seeing if this works:

    order1 = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price']))
    order2 = exchange.create_order(data['symbol'], 'stopLoss', ('sell' if data['side'] == 'buy' else 'buy'), data['amount'], data['takeProfitPrice']))
    order3 = exchange.create_order(data['symbol'], 'takeProfit', ('sell' if data['side'] == 'buy' else 'buy'), data['amount'], data['stopLossPrice']))

Off the top of my head, so it might not work.

Just add the "takeProfitPrice": "{{something}}"

In the tradingview alert to get that data to the bot.

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024

I'm currently working on a new version that allows for placing a take profit and stop with one alert

Sounds good. I'll be waiting. I'll be more than happy to help you test it.
Stop and take profit already works but there is no way to submit multiple orders at once.

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024

How's the new version looking? :)

from tradingview-webhooks-bot.

JDJoe avatar JDJoe commented on May 22, 2024

Any news about the new version?

from tradingview-webhooks-bot.

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.