Hello, I want to create a calculation to know at where I close stock trades, in order to improve my performance.

(apart from everything else) I measure ORDER::max_unrealized_gains and ORDER::max_unrealized_losses per share.

In this example

ORDER::max_unrealized_gains = $0,39

ORDER::max_unrealized_losses = -$0,15

Total range = $0,54

Closed trade for = $0,12

Percentage in the range = 50% (as 0,15 from negative side and 0,12 from positive make 0,27 and that is 1/2 from 0,54 range).

If I closed trade at $0,39, percentage in the range would be 100% (as it is at the very top of the range)

If I closed trade at -$0,15, percentage in the range would be 0% (as it at the very bottom)

If I closed trade at $0,255, percentage in the range would be 75% and so on. (as it is close to the top)

So how can I make this "percentage in range" calculation?

I am struggling to understand this. Which parts are the input to the calculation, and which are calculated? It would seem that max_unrealized_gains, max_unrealized_losses and Closed trade for are given, while Total range and Percentage in the range are calculated from the former three - is that correct?

If so, then you could calculate the percentage as =

( Closed trade for - max_unrealized_losses ) / Total range

or directly from the original input as =

Let ( [

range = max_unrealized_gains - max_unrealized_losses ;

posInRange = Closed trade for - max_unrealized_losses

] ;

posInRange / range

)