Last active
September 16, 2025 14:39
-
-
Save st1vms/411e41625d68b740f404a7f4bebcad85 to your computer and use it in GitHub Desktop.
OCO Sell Order Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="it"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>OCO Sell Order Calculator</title> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| margin: 40px; | |
| max-width: 500px; | |
| } | |
| label { | |
| display: block; | |
| margin-top: 15px; | |
| } | |
| input[type="number"] { | |
| width: 100%; | |
| padding: 8px; | |
| margin-top: 5px; | |
| } | |
| button { | |
| margin-top: 20px; | |
| padding: 10px; | |
| width: 100%; | |
| background-color: #4CAF50; | |
| color: white; | |
| border: none; | |
| cursor: pointer; | |
| } | |
| button:hover { | |
| background-color: #45a049; | |
| } | |
| .result { | |
| margin-top: 20px; | |
| padding: 10px; | |
| border: 1px solid #ddd; | |
| background-color: #f9f9f9; | |
| word-wrap: break-word; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>OCO Sell Order Calculator</h1> | |
| <label for="entryPrice">Entry price:</label> | |
| <input type="number" id="entryPrice" step="0.00000001"> | |
| <label for="maxLossPercent">Max Accepted Loss (%):</label> | |
| <input type="number" id="maxLossPercent" step="0.01" placeholder="5"> | |
| <label for="ratio">Profit/Loss Ratio (default 2):</label> | |
| <input type="number" id="ratio" step="0.01" placeholder="2"> | |
| <button onclick="calculateOCO()">Calculate</button> | |
| <div class="result" id="result"></div> | |
| <script> | |
| function calculateOCO() { | |
| const entryPrice = parseFloat(document.getElementById('entryPrice').value); | |
| let maxLossPercent = parseFloat(document.getElementById('maxLossPercent').value) / 100; // da % a decimale | |
| let ratio = parseFloat(document.getElementById('ratio').value); | |
| if (isNaN(ratio) || ratio <= 0) { | |
| ratio = 2; // default | |
| } | |
| if (isNaN(maxLossPercent) || maxLossPercent <= 0) { | |
| maxLossPercent = 0.05; // default | |
| } | |
| if (isNaN(entryPrice) || entryPrice <= 0) { | |
| document.getElementById('result').innerHTML = "Insert positive valid values..."; | |
| return; | |
| } | |
| // Stop Limit | |
| const stopLimit = entryPrice * (1 - maxLossPercent); | |
| // Take Profit | |
| const takeProfit = entryPrice * (1 + maxLossPercent * ratio); | |
| // Stop Target (a metà della distanza tra entry e stop limit) | |
| const stopLossOrder = entryPrice - (entryPrice * maxLossPercent / 2); | |
| function formatNumber(num) { | |
| let str; | |
| if (num < 0.01) str = num.toFixed(8); | |
| else if (num < 10) str = num.toFixed(3); | |
| else if (num < 1000) str = num.toFixed(2); | |
| else str = num.toFixed(2); | |
| return str.replace(/\./g, ","); | |
| } | |
| document.getElementById('result').innerHTML = ` | |
| <p><strong>Take Profit:</strong> ${formatNumber(takeProfit)}</p> | |
| <p><strong>Stop Target:</strong> ${formatNumber(stopLossOrder)}</p> | |
| <p><strong>Stop Limit:</strong> ${formatNumber(stopLimit)}</p> | |
| `; | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment