document.addEventListener( 'DOMContentLoaded', function() { // Prevent aggressive iframe caching in Firefox var statsIframe = document.getElementById( 'stats-iframe' ); if ( statsIframe ) { statsIframe.contentWindow.location.href = statsIframe.src; } } );var _litespeed_meta; var _litespeed_shell_interval = 3; // seconds var _litespeed_shell_interval_range = [3, 60]; var _litespeed_shell_handle; var _litespeed_shell_display_handle; var _litespeed_crawler_url; var _litespeed_dots; (function ($) { 'use strict'; /** * All of the code for your public-facing JavaScript source * should reside in this file. * * Note: It has been assumed you will write jQuery code here, so the * $ function reference has been prepared for usage within the scope * of this function. * * This enables you to define handlers, for when the DOM is ready: * * $(function() { * * }) ; * * When the window is loaded: * * $( window ).load(function() { * * }) ; * * ...and/or other possibilities. * * Ideally, it is not considered best practise to attach more than a * single DOM-ready or window-load handler for a particular page. * Although scripts in the WordPress core, Plugins and Themes may be * practising this, we should strive to set a better example in our own work. */ jQuery(document).ready(function () { /************** Common LiteSpeed JS **************/ // Link confirm $('[data-litespeed-cfm]').on('click', function (event) { if (confirm($.trim($(this).data('litespeed-cfm')).replace(/\\n/g, '\n'))) { return true; } event.preventDefault(); event.stopImmediatePropagation(); return false; }); /************** LSWCP JS ****************/ // page tab switch functionality (function () { var hash = window.location.hash.substr(1); var $tabs = $('[data-litespeed-tab]'); var $subtabs = $('[data-litespeed-subtab]'); // Handle tab and subtab events var tab_action = function ($elems, type) { type = litespeed_tab_type(type); var data = 'litespeed-' + type; $elems.on('click', function (_event) { litespeed_display_tab($(this).data(data), type); document.cookie = 'litespeed_' + type + '=' + $(this).data(data); $(this).blur(); }); }; tab_action($tabs); tab_action($subtabs, 'subtab'); if (!$tabs.length > 0) { // No tabs exist return; } // Find hash in tabs and subtabs var $hash_tab = $tabs.filter('[data-litespeed-tab="' + hash + '"]:first'); var $hash_subtab = $subtabs.filter('[data-litespeed-subtab="' + hash + '"]:first'); // Find tab name var $subtab; var $tab; var tab_name; if ($hash_subtab.length > 0) { // Hash is a subtab $tab = $hash_subtab.closest('[data-litespeed-layout]'); if ($tab.length > 0) { $subtab = $hash_subtab; tab_name = $tab.data('litespeed-layout'); } } if (typeof $tab === 'undefined' || $tab.length < 1) { // Maybe hash is a tab $tab = $hash_tab; if ($tab.length < 1) { // Maybe tab cookie exists $tab = litespeed_tab_cookie($tabs); if ($tab.length < 1) { // Use the first tab by default $tab = $tabs.first(); } } if (typeof tab_name === 'undefined') { tab_name = $tab.data('litespeed-tab'); } } // Always display a tab litespeed_display_tab(tab_name); // Find subtab name if (typeof $subtab === 'undefined' || $subtab.length < 1) { $subtab = litespeed_tab_cookie($subtabs, 'subtab'); } if ($subtab.length > 0) { var subtab_name = $subtab.data('litespeed-subtab'); // Display a subtab litespeed_display_tab(subtab_name, 'subtab'); } })(); // Manage page -> purge by $('[name=purgeby]').on('change', function (event) { $('[data-purgeby]').hide(); $('[data-purgeby=' + this.value + ']').show(); }); /*************** crawler ******************/ $('#litespeed-crawl-url-btn').on('click', function () { if (!$(this).data('url')) { return false; } $('.litespeed-shell').removeClass('litespeed-hide'); _litespeed_dots = window.setInterval(_litespeed_loading_dots, 300); _litespeed_crawler_url = $(this).data('url'); litespeed_fetch_meta(); $(this).hide(); }); $('#litespeed_manual_trigger').on('click', function (event) { $('#litespeed-loading-dot').before('

A trailing stop-loss is not a static limit-it follows price movement by a fixed distance (points or percentage). When price rises, the stop level moves up; when price falls, the stop remains locked. This locks profits while allowing room for growth. On an advanced trading platform, you configure the trail distance (e.g., 2% or 50 points). The key safety rule: never set a trail too tight-volatile assets trigger premature exits. Test with demo data first. Use a minimum trail of 1.5x the average true range (ATR) of the asset. For crypto or forex, adjust for session volatility.
Another safe practice: combine trailing stops with a hard stop limit. If the platform disconnects or the script fails, a hard stop at a wider level prevents catastrophic loss. Always set the trailing activation price above entry-this avoids immediate stop-hits from noise. Review your broker’s slippage policy; during fast markets, execution may deviate from the triggered level.
Choose between fixed-point and percentage trails. Fixed-point works for low-priced assets; percentage suits high-value instruments. For indices, 1-2% trail works; for volatile stocks, 3-5%. Backtest on historical data within the platform’s script environment-this reveals optimal values without risking capital.
Modern platforms offer scripting languages (e.g., Pine Script, EasyLanguage) to automate trailing stops. Write logic that recalculates the stop on each new bar. The script must check for connectivity-if data feed lags, the stop may not update. Include a timeout function: if no new tick within 5 seconds, freeze the stop at last known level. Also, limit order frequency: sending too many amend requests can trigger rate limits or account restrictions.
Risk management begins before deployment. Use paper trading for at least 100 simulated trades. Monitor for edge cases: gap openings, dividend adjustments, or market halts. The script should output a log file-review it weekly for anomalies. Never grant the script full account access; restrict it to a dedicated sub-account or limited capital.
Wrap your trailing stop logic in try-catch blocks. If the platform API returns an error (e.g., “order rejected”), the script should halt further trading and alert you via email or SMS. Avoid infinite loops-place a maximum iteration counter. For multi-asset scripts, use separate variables per symbol to avoid cross-contamination.
Combine trailing stops with algorithmic scripts to create a dynamic safety net. For example, a script monitors volatility (Bollinger Bands width) and adjusts the trail distance automatically: wider bands = wider trail. This prevents whipsaw losses during high volatility. Another pattern: use a trailing stop only after price exceeds a moving average-this filters false breakouts.
The advanced platform’s sandbox mode is critical. Run the combined logic for two weeks in a simulated environment. Compare results against a simple static stop-loss. If the trailing script underperforms, refine the parameters. Only then switch to live with minimal position size (0.1% of account). Gradually scale up as the script proves stable.
Use 1.5 to 2 times the average true range (ATR) of the asset over the last 14 periods. Test this in demo mode first.
No. Always set a daily kill switch-if no trade occurs for 4 hours, the script should auto-disable. Review logs each morning.
Use limit orders instead of market orders for the stop. Set a small offset (e.g., 0.5%) to allow partial fills. Accept that gaps may still occur.
Your broker’s server retains the last sent stop level. For critical positions, set a redundant hard stop at a wider level on the exchange side.
Percentage trails (1-3%) are better for crypto due to wide price ranges. Fixed-point works only for stablecoins or low-volatility pairs.
Mark T., day trader
I coded a trailing stop script on this platform. The sandbox mode saved me from a bad volatility filter. After two weeks of paper testing, I went live with 0.5% risk. Profits are steady now.
Linda K., swing trader
Used the platform’s built-in trailing stop with ATR multiplier. It caught a 12% move in Apple without getting stopped early. The key was setting the activation price 1% above entry.
Raj P., algorithmic developer
I integrated a volatility-adjusted trailing stop via Pine Script. The platform’s API error handling is robust-my script halts on any data gap. No losses from disconnects so far.
]]>