PINE LIBRARY
已更新 strategy

Library "strategy"
Library containing few key calculations for strategy involving leveraged limit and stop orders
getQty(entry, stop, riskPercentage)
calculate qty and leverage based on entry and stop price for given risk percentage.
Parameters:
entry: Entry Price
stop: Stop Price
riskPercentage: risk percentage per trade
Returns: [quantity, leverage] - Quantity based on the risk and calculated leverage on position including existing positions
bracketOrder(entry, stop, target, maxLeverage, isLimitOrder, riskPercentage)
Calculates position size based on risk and creates bracket orders for given entry/stop/target
Parameters:
entry: Entry Price
stop: Stop Price
target: Target Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskPercentage: risk percentage per trade
Returns: orderPlaced - true if orders successfully placed, false otherwise.
order(entry, stop, maxLeverage, isLimitOrder, riskPercentage)
Calculates position size based on risk and creates order for given entry/stop
Parameters:
entry: Entry Price
stop: Stop Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskPercentage: risk percentage per trade
Returns: orderPlaced - true if orders successfully placed, false otherwise.
Library containing few key calculations for strategy involving leveraged limit and stop orders
getQty(entry, stop, riskPercentage)
calculate qty and leverage based on entry and stop price for given risk percentage.
Parameters:
entry: Entry Price
stop: Stop Price
riskPercentage: risk percentage per trade
Returns: [quantity, leverage] - Quantity based on the risk and calculated leverage on position including existing positions
bracketOrder(entry, stop, target, maxLeverage, isLimitOrder, riskPercentage)
Calculates position size based on risk and creates bracket orders for given entry/stop/target
Parameters:
entry: Entry Price
stop: Stop Price
target: Target Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskPercentage: risk percentage per trade
Returns: orderPlaced - true if orders successfully placed, false otherwise.
order(entry, stop, maxLeverage, isLimitOrder, riskPercentage)
Calculates position size based on risk and creates order for given entry/stop
Parameters:
entry: Entry Price
stop: Stop Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskPercentage: risk percentage per trade
Returns: orderPlaced - true if orders successfully placed, false otherwise.
發行說明
v2Added:
bracketOrderWithoutLeverage(id, entry, stop, target, isLimitOrder)
Creates bracket orders for given entry/stop/target without leverage and qty calculation. (Uses the values from strategy definition)
Parameters:
id
entry: Entry Price
stop: Stop Price
target: Target Price
isLimitOrder: if true, places limit order for entry, else places stop order.
Returns: orderPlaced - true if orders successfully placed, false otherwise.
發行說明
v3發行說明
v4Updated:
getQty(entry, stop, riskAmount, riskType)
calculate qty and leverage based on entry and stop price for given risk percentage.
Parameters:
entry: Entry Price
stop: Stop Price
riskAmount: risk percentage per trade or risk cash per trade
riskType: Can be either trategy.percent_of_equity or strategy.cash
Returns: [quantity, leverage] - Quantity based on the risk and calculated leverage on position including existing positions
bracketOrder(id, entry, stop, target, maxLeverage, isLimitOrder, riskAmount, riskType)
Calculates position size based on risk and creates bracket orders for given entry/stop/target
Parameters:
id
entry: Entry Price
stop: Stop Price
target: Target Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskAmount: risk percentage per trade or risk cash per trade
riskType: Can be either trategy.percent_of_equity or strategy.cash
Returns: orderPlaced - true if orders successfully placed, false otherwise.
order(id, entry, stop, maxLeverage, isLimitOrder, riskAmount, riskType)
Calculates position size based on risk and creates order for given entry/stop
Parameters:
id
entry: Entry Price
stop: Stop Price
maxLeverage: Maximum leverage allowed
isLimitOrder: if true, places limit order for entry, else places stop order.
riskAmount: risk percentage per trade or risk cash per trade
riskType: Can be either trategy.percent_of_equity or strategy.cash
Returns: orderPlaced - true if orders successfully placed, false otherwise.
發行說明
v5Corrected calculation logic for newPosition in getQty function. Thanks to serkany88 for highlighting
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
Trial - trendoscope.io/trial
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
Subscribe - trendoscope.io/pricing
Blog - docs.trendoscope.io
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。