riskRewardPositionToolI tried making a tool like this a year ago and it didn't work as planned. I'm coming back after having practiced a little more. The script might still have some bugs, sorry about that. The position tool colors are hard-coded to my chart colors, I don't know how to make them changeable, sorry, but the script is open source, so feel free to copy it and change the colors to yours.
Library "riskRewardPositionTool"
drawNewPosition(position)
Used to draw a new position on the chart.
Parameters:
position (positionData) : The position data used to create the drawing objects for the position.
Returns: The positionDrawObject instance containing the drawing objects for the position.
getExitParams(pos)
Gets exit parameters for a position based on the current price action and the position's TP and SL levels.
Parameters:
pos (positionData) : The position data for which to calculate the exit parameters.
Returns: A tuple containing the exit price and the corresponding color for the exit area on the chart.
enterOrder(pos, posArray)
Used to enter a new position.
Parameters:
pos (positionData) : The position data for the new position being entered.
posArray (array) : The array storing all the positionDrawObject instances for the current chart. The
updOrders(posArray)
Used to update the drawing objects for an open position on each bar. Call once per bar.
Parameters:
posArray (array) : The array storing all the positionDrawObject instances for the current chart.
Returns: The modified array with updated positionDrawObject instances.
positionData
positionData Stores relevant data for a position.
Fields:
entry_x (series int) : X coordinate of the left side of the position tool (time).
entry_x2 (series int) : X coordinate of the right side of the position tool (time).
entry_y (series float) : price level of the entry.
exit_x (series int) : X coordinate of the exit (time).
exit_y (series float) : Price level of the exit.
sl (series float) : Price level of the stop loss.
tp (series float) : Price level of the take profit.
posclosed (series bool) : Indicates if the position is closed. Do not change directly.
posentered (series bool) : Indicates if the position is entered. Do not change directly.
poserror (series bool) : Indicates if there is an error with the position data. Do not change directly.
direction (series int) : Direction of the position. 1 for long, -1 for short. Do not change directly.
win (series bool) : Indicates if the position was a win. Do not change directly.
positionDrawObject
positionDrawObject Stores relevant data for a position's drawing objects.
Fields:
data (positionData) : The position data associated with the drawing objects.
tp_box (series box) : The box object representing the take profit area.
sl_box (series box) : The box object representing the stop loss area.
pnl_box (series box) : The box object overlaid on either the stop loss or take profit area representing open/closed PnL.
entry_line (series line) : The line object representing the entry price level.
pnl_line (series line) : The diagonal line going from the entry to the exit or current price level.
lbl (series label) : The label object showing the risk-to-reward ratio and PnL.
arw (series label) : The label object representing the arrow pointing to the entry price level.
arw_ext (series label) : The label object representing the extension of the arrow pointing to the entry
check (series bool) : A boolean used for internal checks when updating the drawing objects. Do not change directly.
Библиотека Pine Script®






















