This is not a indicator or strategy.

I thought of having a table showing running profit or loss on chart from a specific price.
I tried to put the same in code and ended up with this code.
This is a table showing the running profit or loss from a manually specified price and quantity.

when you add the code, This table asks us to input the entry price and quantity.
It will calculate the running profit or loss with respect to running price and puts that in the table.

We will have to input two things.

1.) entry price: the price at which a position(long/short) is taken.
2.) Quantity: A +value need to be entered for Long position and -value for short position.

code detects whether its a long position or short position based on the quantity info.

for example if a LONG position is taken at a price 60 of 100 quantity,
then in price we need to enter 60
and in quantity 100 (+ve value)

for SHORT position at a price of 60 of 100 quantity,
in price we need to enter 60
and in quantity -100 (-ve value)

once the table is added to the chart.
Just double click on the table, it will open the settings tab and we can provide new inputs price/quantity/position.
positioning of table is optional and all possible positioning options are provided.

Advise further improvements required if any in this code.

This piece of code can be used along with any indicator.
For which we may need to use valuewhen() additionally.
Try it yourself and ping me if required.

开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?