OPEN-SOURCE SCRIPT
Aggiornato

Precision Trade Zone By Kittisak

1 001
This indicator is designed for Money Management calculations, helping to facilitate risk management in trading, determining suitable leverage based on acceptable risk, and adjusting the Stop Loss level to align with the calculated leverage.

Abbreviation Descriptions
  • LR: Suitable Leverage.
  • EP: Entry Price.
  • BEP: Break-Even Point (a point where you can move your Stop Loss to prevent losses once the price reaches a certain level).
  • SL: Stop Loss (a recalculated Stop Loss level to match the leverage. You should use this as the Stop Loss price instead of the initial level you set).
  • TP: Take Profit (a point where you take profit based on the defined risk-reward ratio).


Note
When first activating the indicator, an error may occur, and no output will be displayed. This happens because you must first specify the Entry Price and Stop Loss in the indicator settings.

How Much Leverage Should You Use?
It may seem like a simple question but is difficult to answer.

Method for Calculating Suitable Leverage
Use the formula:

Pine Script®
Leverage = Acceptable Loss / (Distance between Entry Price and Stop Loss + (Buy Fee + Sell Fee))


Calculating the Correct Stop Loss Point
(Stop Loss levels will be slightly adjusted or extended)

For Long Positions:
Pine Script®
New Stop Loss = Entry Price * (1 - Acceptable Loss / (Calculated Leverage * 100))


For Short Positions:
Pine Script®
New Stop Loss = Entry Price * (1 + Acceptable Loss / (Calculated Leverage * 100))


Calculating the Correct Take Profit Point
(Take Profit levels will be slightly adjusted or extended)

For Long Positions:
Pine Script®
Take Profit = Entry Price * (1 + (Acceptable Loss / (Calculated Leverage * 100) * RR) + ((Buy Fee + Sell Fee) / 100))


For Short Positions:
Pine Script®
Take Profit = Entry Price * (1 - (Acceptable Loss / (Calculated Leverage * 100) * RR) + ((Buy Fee + Sell Fee) / 100))


Benefits of This Calculation

1. Accurate Risk Assessment
The calculated leverage accounts for trading fees. For example, if you aim for a 2% loss, this method ensures the actual loss is exactly 2%, not more (e.g., 2% plus fees).

2. Eliminates Guesswork
Randomly setting leverage can lead to risks because the Stop Loss level may not align with your position. This calculation ensures that the leverage aligns precisely with your desired Stop Loss level.

3. Realistic Profit Targets
For example, with a 2% acceptable loss and a 1:2 RR, you expect a 4% profit. However, without this calculation, fees may reduce your profit below 4%. This method includes fees, ensuring your profit matches the intended target.

Caution
This indicator does not account for slippage or requotes. Use it with caution and allow a buffer for slippage in your calculations.

Indicator นี้มีไว้สำหรับคำนวณ Money Management ซึ่งจะช่วยอำนวยความสะดวกในการจัดการความเสี่ยงในการเทรด การคำนวณ Leverage ที่เหมาะสมกับความเสี่ยงที่คุณยอมรับได้ และจัดการจุด Stop Loss ให้เหมาะสมกับ Leverage นั้น

คำอธิบายเกี่ยวกับคำย่อ

LR หมายถึง Leverage ที่เหมาะสม
EP หมายถึง Entry Price หรือราคาเข้าซื้อ
BEP หมายถึง Break-Even Point หรือจุดคุ้มทุน (คุณสามารถย้าย Stop Loss มาที่จุดนี้เมื่อราคาไปถึงจุดหนึ่งเพื่อป้องกันการขาดทุนได้)
SL หมายถึง Stop Loss (ซึ่งเป็น Stop Loss ที่คำนวณใหม่เพื่อให้ตำแหน่งเหมาะสมกับ Leverage ที่คำนวณได้ คุณควรใช้จุดนี้เพื่อเป็นราคา Stop Loss แทนจุด Stop Loss ที่คุณกำหนดไว้ในตอนแรก)
TP หมายถึง Take Profit (เป็นจุดที่คุณจะขายทำกำไรตาม RR ที่กำหนดไว้)

* หมายเหตุ เมื่อเริ่มเปิด Indicator จะเกิด Error ขึ้น และไม่มีผลลัพท์ใด ๆ แสดงให้เห็น นั่นเป็นเพราะคุณต้องเข้าไปกำหนด Entry Price และ Stop Loss ในการตั้งค่าของ Indicator เสียก่อน

ต้องใช้ Leverage เท่าไหร่? มันเป็นคำถามที่ดูเหมือนง่าย แต่ตอบยาก
วิธีคำนวณ Leverage ที่เหมาะสม ใช้สมการคือ

Pine Script®
Levarage = การขาดทุนที่ยอมรับได้ / (ระยะห่างระหว่าง Entry Price และ Stop Loss + (ค่าธรรมเนียมซื้อ + ค่าธรรมเนียมขาย))


นำผลลัพท์ Leverage ที่ได้มาคำนวณเพื่อหาจุด Stop Loss ที่ถูกต้อง (จุดของ Stop Loss จะมีการยืดขยายออกไปเล็กน้อย) โดยใช้สมการ

Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 - การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100)) // สำหรับ Long


Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 + การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100)) // สำหรับ Short


นำผลลัพท์ Leverage ที่ได้มาคำนวณเพื่อหาจุด Take Profit ที่ถูกต้อง (จุดของ Take Profit จะมีการยืดขยายออกไปเล็กน้อย) โดยใช้สมการ

Pine Script®
ตำแหน่ง Take Profit = Entry Price * (1 + (การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100) * RR) + ((ค่าธรรมเนียมซื้อ + ค่าธรรมเนียมขาย) / 100)) // สำหรับ Long


Pine Script®
ตำแหน่ง Take Profit = Entry Price * (1 - (การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100) * RR) + ((ค่าธรรมเนียมซื้อ + ค่าธรรมเนียมขาย) / 100)) // สำหรับ Short


ข้อดีของการคำนวณคือ
1. คุณจะได้ค่า Leverage ที่เหมาะสมกับความเสี่ยงที่คุณยอมรับได้โดยรวมค่าธรรมเนียมเข้าไปในนั้นแล้ว นั่นหมายความว่า ความสูญเสียจะเป็น 2% (ตามตัวอย่าง) จริง ๆ ไม่ใช่ 2% และถูกหักค่าธรรมเนียมเพิ่มอีก กลายเป็นสูญเสียมากกว่า 2%
2. การตั้ง Leverage มั่ว ๆ กลายเป็นความเสี่ยง นั่นเพราะตำแหน่งของ Stop Loss ไม่ได้อยู่ในจุดที่ควรจะเป็น การคำนวณนี้ช่วยให้คุณได้ Leverage ในตำแหน่ง Stop Loss ที่คุณต้องการโดยแท้จริง
3. ผลกำไรที่ได้รับตรงกับความต้องการจริง ๆ เช่น การขาดทุนที่ยอมรับได้ 2% และ RR 1:2 สิ่งที่คุณคิดคือกำไร 4% แต่จริง ๆ แล้วไม่ถึง 4% นั่นเพราะว่าโดนหักค่าธรรมเนียมไปส่วนหนึ่ง การคำนวณนี้ได้รวมค่าธรรมเนียมให้แล้ว คุณจึงได้กำไรที่ 4% อย่างถูกต้องตามต้องการ

ข้อควรระวัง
Indicator นี้ไม่ได้มีการควบคุมความเสี่ยงในเรื่องของ slippage หรือ requote โปรดใช้งานอย่างระมัดระวังและมีการเผื่อระยะสำหรับ slippage ด้วย
Note di rilascio
Remove the unused code.
ลบโค้ดส่วนที่ไม่ได้ใช้งานออก
Note di rilascio
Modify the function f_distance_percentage to calculate correctly.
Note di rilascio
The following improvements have been made to the code:

1. Leverage Calculation Enhancements

- Leverage is now calculated twice:
- The first calculation excludes fees to determine the Stop Loss position more accurately (the previous code included fees, which could result in incorrect Stop Loss placement).
- The second calculation includes fees to determine the appropriate leverage for trading.

2. Removed the Input Option for Rounding, Letting the System Determine It Automatically for Better Stop Loss Accuracy

- The best value is selected between rounding up and rounding down to ensure that:
- For Long positions, the new Stop Loss is not placed higher than the specified Stop Loss.
- For Short positions, the new Stop Loss is not placed lower than the specified Stop Loss.

3. Adjusted the Equation for Calculating the New Stop Loss Position

- For Long Positions:
- Changed from:
Pine Script®
New Stop Loss = Entry Price * (1 - Acceptable Loss / (Calculated Leverage * 100))

- To:
Pine Script®
New Stop Loss = Entry Price * (1 - Acceptable Loss / (Leverage Without Fees * 100))

- For Short Positions:
- Changed from:
Pine Script®
New Stop Loss = Entry Price * (1 + Acceptable Loss / (Calculated Leverage * 100))

- To:
Pine Script®
New Stop Loss = Entry Price * (1 + Acceptable Loss / (Leverage Without Fees * 100))


4. Code Readability and Efficiency Improvements

- Added explicit data types (`float` and `int`) to improve readability and reduce runtime errors.
- Refined the order of Stop Loss and Leverage calculations to enhance precision and stability.


มีการปรับปรุงโค้ดดังต่อไปนี้:

1. การปรับปรุงการคำนวณ Leverage

- มีการคำนวณ Leverage สองครั้ง:
- ครั้งแรก แบบไม่รวมค่าธรรมเนียม เพื่อใช้ในการคำนวณเพื่อกำหนดจุด Stop Loss ได้ถูกต้อง (โค้ดเดิมใช้แบบรวมค่าธรรมเนียมเป็นจุด Stop Loss อาจไม่ถูกต้องนัก)
- ครั้งที่สอง รวมค่าธรรมเนียม เพื่อนำไปใช้เป็น Leverage ที่เหมาะสม

2. ตัด Input ตัวเลือกการปัดเศษออกไป ให้ระบบเป็นผู้กำหนดเอง เพื่อให้การคำนวณ Stop Loss ที่แม่นยำและเหมาะสมมากขึ้น

- มีการเลือกค่าที่ดีที่สุดจากการปัดขึ้นและปัดลง เพื่อให้ Stop Loss ใหม่ ไม่อยู่ในตำแหน่งที่สูงกว่า Stop Loss ที่กำหนด (ในส่วนของ Long) และเพื่อให้ Stop Loss ใหม่ ไม่อยู่ในตำแหน่งที่ต่ำกว่า Stop Loss ที่กำหนด (ในส่วนของ Short)

3. แก้ไขสมการเพื่อหาค่า ตำแหน่ง Stop Loss ใหม่

- สำหรับ Long
จาก
Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 - การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100))

เป็น
Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 - การขาดทุนที่ยอมรับได้ / (Leverage ที่ไม่รวมค่าธรรมเนียม * 100))

- สำหรับ Short
จาก
Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 + การขาดทุนที่ยอมรับได้ / (Leverage ที่คำนวณได้ * 100))

เป็น
Pine Script®
ตำแหน่ง Stop Loss ใหม่ = Entry Price * (1 + การขาดทุนที่ยอมรับได้ / (Leverage ที่ไม่รวมค่าธรรมเนียม * 100))


4. การปรับปรุงโค้ดเพื่อความอ่านง่ายและประสิทธิภาพ

- เพิ่มประเภทข้อมูล (float และ int) เพื่อให้โค้ดอ่านง่ายขึ้นและลดข้อผิดพลาดขณะทำงาน
- ปรับปรุงลำดับการคำนวณ Stop Loss และ Leverage ให้มีความแม่นยำและเสถียรมากขึ้น
Note di rilascio
Long Position Fix

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.