PINE LIBRARY
已更新 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
版本注释
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
版本注释
v3Pine脚本库
本着真正的TradingView精神,作者将此Pine代码发布为开源库,以便我们社区的其他Pine程序员可以重复使用它。向作者致敬!您可以私密或在其他开源出版物中使用此库,但在出版物中重复使用此代码受网站规则约束。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
Pine脚本库
本着真正的TradingView精神,作者将此Pine代码发布为开源库,以便我们社区的其他Pine程序员可以重复使用它。向作者致敬!您可以私密或在其他开源出版物中使用此库,但在出版物中重复使用此代码受网站规则约束。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。