Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

bots - TradingView Pine script: How to refer to individual trades?

I'm kind of a noob in coding, but recently I've been working on a strategy for a trading bot for bitcoin that i am developing. The concept is the following. When certain conditions are met (ema1 crossover ema2), the bot will buy a x amount of shares, and when and specific "exit long" conditions happen it will close the existing long. The problem with this is that the conditions for "close long" are different from the "close short" conditions. If it weren′t for this, i would use strategy_close_all but i don′t want to close the long when the "close short" condition occurs.

I thought about some solutions, but i don′t know how to implement them or even if they can be made:

  1. A "close long" and "close short" command that i am missing. or a close a designated position
  2. I tried using an if OpenLong and CloseLong = strategy_close_all. And the same for shorts but it doesn′t work because the OpenLong condition may stop existing after a few candles, provoking that the conditions never happen leaving the position open.

Is there a way to refer to the current trading position (long or short) even when the buy or sell conditions are not met anymore?

Thank you in advance.

question from:https://stackoverflow.com/questions/66054837/tradingview-pine-script-how-to-refer-to-individual-trades

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...