PINE LIBRARY
Updated position_tool

Library "position_tool"
Trying to turn TradingView's position tool into a library from which you can draw position tools for your strategies on the chart. Not sure if this is going to work
calcBaseUnit()
Calculates the chart symbol's base unit of change in asset prices.
Returns: (float) A ticks or pips value of base units of change.
calcOrderPipsOrTicks(orderSize, unit)
Converts the `orderSize` to ticks.
Parameters:
orderSize (float): (series float) The order size to convert to ticks.
unit (simple float): (simple float) The basic units of change in asset prices.
Returns: (int) A tick value based on a given order size.
calcProfitLossSize(price, entryPrice, isLongPosition)
Calculates a difference between a `price` and the `entryPrice` in absolute terms.
Parameters:
price (float): (series float) The price to calculate the difference from.
entryPrice (float): (series float) The price of entry for the position.
isLongPosition (bool)
Returns: (float) The absolute price displacement of a price from an entry price.
calcRiskRewardRatio(profitSize, lossSize)
Calculates a risk to reward ratio given the size of profit and loss.
Parameters:
profitSize (float): (series float) The size of the profit in absolute terms.
lossSize (float): (series float) The size of the loss in absolute terms.
Returns: (float) The ratio between the `profitSize` to the `lossSize`
createPosition(entryPrice, entryTime, tpPrice, slPrice, entryColor, tpColor, slColor, textColor, showExtendRight)
Main function to create a position visualization with entry, TP, and SL
Parameters:
entryPrice (float): (float) The entry price of the position
entryTime (int): (int) The entry time of the position in bar_time format
tpPrice (float): (float) The take profit price
slPrice (float): (float) The stop loss price
entryColor (color): (color) Color for entry line
tpColor (color): (color) Color for take profit zone
slColor (color): (color) Color for stop loss zone
textColor (color): (color) Color for text labels
showExtendRight (bool): (bool) Whether to extend lines to the right
Returns: (bool) Returns true when position is closed
Trying to turn TradingView's position tool into a library from which you can draw position tools for your strategies on the chart. Not sure if this is going to work
calcBaseUnit()
Calculates the chart symbol's base unit of change in asset prices.
Returns: (float) A ticks or pips value of base units of change.
calcOrderPipsOrTicks(orderSize, unit)
Converts the `orderSize` to ticks.
Parameters:
orderSize (float): (series float) The order size to convert to ticks.
unit (simple float): (simple float) The basic units of change in asset prices.
Returns: (int) A tick value based on a given order size.
calcProfitLossSize(price, entryPrice, isLongPosition)
Calculates a difference between a `price` and the `entryPrice` in absolute terms.
Parameters:
price (float): (series float) The price to calculate the difference from.
entryPrice (float): (series float) The price of entry for the position.
isLongPosition (bool)
Returns: (float) The absolute price displacement of a price from an entry price.
calcRiskRewardRatio(profitSize, lossSize)
Calculates a risk to reward ratio given the size of profit and loss.
Parameters:
profitSize (float): (series float) The size of the profit in absolute terms.
lossSize (float): (series float) The size of the loss in absolute terms.
Returns: (float) The ratio between the `profitSize` to the `lossSize`
createPosition(entryPrice, entryTime, tpPrice, slPrice, entryColor, tpColor, slColor, textColor, showExtendRight)
Main function to create a position visualization with entry, TP, and SL
Parameters:
entryPrice (float): (float) The entry price of the position
entryTime (int): (int) The entry time of the position in bar_time format
tpPrice (float): (float) The take profit price
slPrice (float): (float) The stop loss price
entryColor (color): (color) Color for entry line
tpColor (color): (color) Color for take profit zone
slColor (color): (color) Color for stop loss zone
textColor (color): (color) Color for text labels
showExtendRight (bool): (bool) Whether to extend lines to the right
Returns: (bool) Returns true when position is closed
Release Notes
v2Added:
position_data
stores position data for the entry
Fields:
entry_x (series int): stores entry time
entry_x2 (series int): stores real entry price (when you get filled)
entry_y (series float): stores entry price
exit_x (series int): stores time of exit
exit_y (series float): stores price of exit
sl (series float): stores stop loss price
tp (series float): stores tp price
posclosed (series bool): for checking if the position is closed, do not change
posentered (series bool): for checking if the position is entered, do not change
poserror (series bool): for checking if sl and tp are on opposite sides of each other, do not change
direction (series int): for storing direction of position, calculated automatically, either 1 or -1
win (series bool): determine if the position is a win
sl_css (series color): color of stop loss zone
tp_css (series color): color of take profit zone
Removed:
calcBaseUnit()
Calculates the chart symbol's base unit of change in asset prices.
calcOrderPipsOrTicks(orderSize, unit)
Converts the `orderSize` to ticks.
calcProfitLossSize(price, entryPrice, isLongPosition)
Calculates a difference between a `price` and the `entryPrice` in absolute terms.
calcRiskRewardRatio(profitSize, lossSize)
Calculates a risk to reward ratio given the size of profit and loss.
createPosition(entryPrice, entryTime, tpPrice, slPrice, entryColor, tpColor, slColor, textColor, showExtendRight)
Main function to create a position visualization with entry, TP, and SL
Release Notes
v3Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.