PINE LIBRARY
تم تحديثه

TradeManagement

371
TradeManagement is a Pine Script® library designed to simplify common trade-management and position-sizing calculations in TradingView strategies.

The library provides reusable functions for calculating:
Take-profit prices
Stop-loss prices
Risk/reward-based take-profit prices
Position size based on monetary risk
Position size based on risk per unit/contract
Current strategy entry price

Features
Pine Script®

Calculates a take-profit price using a percentage.
You can specify whether the trade is long or short.

Pine Script®

Calculates a stop-loss price using a percentage.
You can specify whether the trade is long or short.

Pine Script®

Calculates a take-profit price based on the distance between the entry price and stop-loss price, using a selected risk/reward multiplier.
For example, you can use a 2 multiplier for a 1:2 risk/reward target.

Pine Script®

Calculates the position quantity based on:
Entry price
Stop-loss price
Maximum monetary risk
The calculation uses TradingView's symbol-specific syminfo.pointvalue.

Pine Script®

Calculates the position quantity based on:
Entry price
Stop-loss price
Risk amount per unit/contract
Use this when you want to specify risk per contract (e.g., "Risk 0.01 per contract") rather than total monetary risk.

Pine Script®

Returns the current strategy's average entry price when a position is open.
This allows you to keep your strategy code clean while using the same trade-management functions across multiple strategies.

Important Note About Position Risk
The positionSize() function calculates the position quantity based on the specified monetary risk. However, the final risk may not always exactly match the risk amount entered.
This is because some markets or trading environments only allow specific quantity increments, such as whole-number quantities:
1, 2, 3, ...
For example, you may enter $5 as your maximum intended risk, but the calculated position size could result in an actual risk of $3.79.
This happens because the required position size might be something like 1.3, but the market or broker may only allow a quantity such as 1 or 2.
Therefore, the risk input should be considered the maximum intended risk, while the actual risk depends on the quantity precision or increment supported by the specific symbol and trading environment.

Strategy Compatibility
This library is intended primarily for use with TradingView strategies.
The position-sizing and entry-price functions rely on TradingView strategy information and symbol-specific properties.

Risk Disclaimer
This library provides calculation tools and does not guarantee a specific trading result or risk outcome.
Always verify the calculated position size, stop-loss distance, quantity rules, and actual monetary risk for the specific market, broker, or exchange before using the calculations in live trading.
ملاحظات الأخبار
v2

Removed:
positionSizeByRiskQuantity(entryPrice, slPrice, riskQuantity)
  Calculates position size based on risk per unit/contract.


Note : One Useless function removed

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.