TradingView
trialanderror
23 de Dez de 2020 12:25

Position Size Calculator w/ profit targets 

Arcimoto, Inc.NASDAQ

Descrição

This script helps the user visualize profit targets and calculates position size based on the input risk amount.

Input variables:
- Risk amount
- Entry price
- Stop loss amount
- Profit target amount

Calculated variables:
- Profit loss ratio
- Position size
- Postion cost

Plotted variables:
- shaded: entry price --> price target (green filled)
- shaded: entry price --> stop loss target (red filled)
- 1:1 p/l ratio --> yellow line
- 2:1, 3:1, 4:1 p/l ratios --> green lines

Overlay text can be toggled on/off in parameter input section

Comentários
cloudbursts
Took me hours of testing position management indicators in order to find this exact indicator design. Incredibly rare. Thank you for your creative work here and the thoughtfulness you put into it!

Some questions:

1. How can I toggle the price labels on for each of the levels (entry, stop, target, 1R, 2R, 3R, 4R)?

2. How can I move the position sizing text to the right of the candles? Currently it overlaps the candles, obscuring both the text and the candles.
daveslow84
I edited my comment and the edit disapeared... damn! :D
I saw your comment in the code about not knowing how to change that yourself after I posted, sorry :)
I was reading in the pine doc and under "Text and Shapes" and in the section "Tables" I found some stuff that might help. Bear with me though, I've only started learning pine yesterday night :D

I think the problem lies with xloc.bar_time and yloc.price. I would guess that tells pine where on the X and Y axis the label should be printed, at the current bar on the x axis and at the hight of the last closing price on the y axis! If you check in the documentation under Tables there's info on how to place a label for example in the top right corner of the chart. Alternatively I think you could just add a number modifier to xloc and/or yloc to have the label fixed on the chart for example to the right or above the last candle.

This is copied from the documentation about positioning labels with x/yloc:
//
X
Is either a bar index or a time value. When a bar index is used, the value can be offset in the past or in the future (maximum of 500 bars in the future). Past or future offsets can also be calculated when using time values. The x value of an existing label can be modified using label.set_x() or label.set_xy().
XLOC
Is either xloc.bar_index (the default) or xloc.bar_time. It determines which type of argument must be used with x. With xloc.bar_index, x must be an absolute bar index. With xloc.bar_time, x must be a UNIX time in milliseconds corresponding to the time value of a bar’s open. The xloc value of an existing label can be modified using label.set_xloc().
Y
Is the price level where the label is positioned. It is only taken into account with the default yloc value of yloc.price. If yloc is yloc.abovebar or yloc.belowbar then the y argument is ignored. The y value of an existing label can be modified using label.set_y() or label.set_xy().
YLOC
Can be yloc.price (the default), yloc.abovebar or yloc.belowbar. The argument used for y is only taken into account with yloc.price. The yloc value of an existing label can be modified using label.set_yloc().
//
So basically try adding label.set_yloc(insert value offset from last price) which would raise the label for example?

Hope this wasn't complete garbage but complete noob here :D
All the best and thanks for the indicator!
daveslow84
Really nice but... the text overlay needs to be placed differently so as not to obscure the candles!
I have no idea how to do that unfortunately as I've only just started dabbling with pine :D (complete noob even)
apart from that I absolutely like it!
Mais