riskRewardPositionTool

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<positionDrawObject>): 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<positionDrawObject>): 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.
- Ability to set partial take profits
- Information label (shows how many points you're up and the risk/reward)
- Ability to customize position color (yes it was possible and im stupid)
- Many other things.
If you were using this library prior to v4 and wish to upgrade, please make sure you modify your script accordingly. Some function names and arguments were updated which will break your script if not correctly implemented.
Updated:
drawNewPosition(pos, posCSS)
Used to draw a new position on the chart. Do not use directly. Instead, use enterOrder().
Parameters:
pos (positionData)
posCSS (positionCSS)
Returns: The positionDrawObject instance containing the position's data and drawing objects.
method getExitParams(pos, posCSS)
Used to update exit parameters.
Namespace types: positionData
Parameters:
pos (positionData)
posCSS (positionCSS)
Returns: Exit price/color.
enterOrder(pos, posDrawArr, posCSS)
Used to enter an order.
Parameters:
pos (positionData): positionData object containing position data.
posDrawArr (array<positionDrawObject>): An array of positionDrawObject instances to which the new position's drawing objects will be added.
posCSS (positionCSS): positionCSS object containing styling data for the position's drawing objects.
positionData
positionData Stores relevant data for a position.
Fields:
entry (chart.point)
entryActual (chart.point)
partial_1 (chart.point)
partial_2 (chart.point)
exit (chart.point)
slPrice (series float)
partial1Price (series float)
partial2Price (series float)
tpPrice (series float)
positionClosed (series bool)
positionEntered (series bool)
positionError (series bool)
dir (series int)
winLoss (series int)
pnlDrawnForFirstTime (series bool)
positionDrawObject
positionDrawObject Stores relevant data for a position's drawing objects. You should not modify any of these directly. Instead, use enterOrder()
Fields:
data (positionData): The positionData instance containing the position's data.
tpBox (series box): The box object representing the take profit area on the chart.
slBox (series box): The box object representing the stop loss area on the chart.
pnlBox (series box): The box object representing the profit and loss area on the chart. This box updates based on the current price action if the position is open, or is overlayed on the TP or SL box with its color if the position is closed.
entryLine (series line): The line object representing the entry price level on the chart.
partialLine_1 (series line): The line object representing the first partial take profit level on the chart (if applicable).
partialLine_2 (series line): The line object representing the second partial take profit level on the chart (if applicable).
positionInfoLbl (series label): The label object displaying information about the position, like Pnl in points and RR.
entryDot (series label): The label object representing the entry point on the chart.
partial1Dot (series label): The label object representing the first partial take profit point on the chart (if applicable).
partial2Dot (series label): The label object representing the second partial take profit point on the chart (if applicable).
exitDot (series label): The label object representing the exit point on the chart.
check (series bool)
Removed:
logPositionState(eventName, pos)
Used to log the position state.
Added:
createBreakevenLine(pos, posCSS, x2Time)
Helper function used to draw the optional breakeven stop line.
Parameters:
pos (positionData): The position data for which to draw the breakeven line.
posCSS (positionCSS): The style settings for the position drawing objects.
x2Time (int): The time coordinate for the line's right-side endpoint.
Returns: The breakeven stop line object, or na if breakeven stop is disabled.
Updated:
method getExitParams(pos, posCSS)
Used to update exit parameters.
Namespace types: positionData
Parameters:
pos (positionData): positionData object containing position data.
posCSS (positionCSS): positionCSS object containing styling data for the position's drawing objects.
Returns: Exit price/color.
positionData
positionData Stores relevant data for a position.
Fields:
entry (chart.point)
entryActual (chart.point)
partial_1 (chart.point)
partial_2 (chart.point)
exit (chart.point)
slPrice (series float)
useBreakevenStop (series bool)
breakevenTriggerRR (series float)
breakevenPrice (series float)
breakevenArmed (series bool)
partial1Price (series float)
partial2Price (series float)
tpPrice (series float)
positionClosed (series bool)
positionEntered (series bool)
positionError (series bool)
dir (series int)
winLoss (series int)
pnlDrawnForFirstTime (series bool)
positionDrawObject
positionDrawObject Stores relevant data for a position's drawing objects. You should not modify any of these directly. Instead, use enterOrder()
Fields:
data (positionData): The positionData instance containing the position's data.
tpBox (series box): The box object representing the take profit area on the chart.
slBox (series box): The box object representing the stop loss area on the chart.
pnlBox (series box): The box object representing the profit and loss area on the chart. This box updates based on the current price action if the position is open, or is overlayed on the TP or SL box with its color if the position is closed.
entryLine (series line): The line object representing the entry price level on the chart.
breakevenLine (series line): The optional line object representing the breakeven stop level on the chart (if enabled).
partialLine_1 (series line): The line object representing the first partial take profit level on the chart (if applicable).
partialLine_2 (series line): The line object representing the second partial take profit level on the chart (if applicable).
positionInfoLbl (series label): The label object displaying information about the position, like Pnl in points and RR.
entryDot (series label): The label object representing the entry point on the chart.
partial1Dot (series label): The label object representing the first partial take profit point on the chart (if applicable).
partial2Dot (series label): The label object representing the second partial take profit point on the chart (if applicable).
exitDot (series label): The label object representing the exit point on the chart.
check (series bool)
Pine Bibliothek
Ganz im Sinne von TradingView hat dieser Autor seinen/ihren Pine Code als Open-Source-Bibliothek veröffentlicht. Auf diese Weise können nun auch andere Pine-Programmierer aus unserer Community den Code verwenden. Vielen Dank an den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Veröffentlichungen verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert.
Haftungsausschluss
Pine Bibliothek
Ganz im Sinne von TradingView hat dieser Autor seinen/ihren Pine Code als Open-Source-Bibliothek veröffentlicht. Auf diese Weise können nun auch andere Pine-Programmierer aus unserer Community den Code verwenden. Vielen Dank an den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Veröffentlichungen verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert.