• Evaluating indicators on important metrics without the need to write a strategy script for backtesting.
• Using indicators with built-in risk management.
A Trade-Grp makes up one or more trade positions from the first position entering to the last position exiting. Using Trade-Grp’s instead of positions should help you better assess if the metric results fit your trading style.
Below are two (2) examples of a Trade-Grp with three (3) positions.
A table of metrics is available if the “Show Metrics Table” checkbox is enabled on the Inputs tab, but metrics always show in the Data Window.
Examples of the Metrics Table are shown below.
• ROI (Return on Investment) and CAGR (Compound Annual Growth Rate) are based on the Avg Invest/Trade-Grp and are adjusted for dividends if the “Include Dividends in Profit” checkbox is enabled.
• Profit/Risked is based on Trade-Grp’s. Also known as reward/risk, as well as expectancy per amount risked. It determines the effectiveness of your strategy and provides a measure of comparison between your strategies. This is adjusted for dividends if the “Include Dividends in Profit” checkbox is enabled. In the Data Window the color is green when above the breakeven point of making a profit and red when below the breakeven point. In the Table the color is red if below the breakeven point, otherwise it is the default color. For example, using the 3 metrics tables above:For every USD risked the profit is 1.709 USD.
For every BTC risked the profit is 0.832 BTC.
For every JPY risked the profit is 0.261 JPY.
• Winning % is based on Trade-Grp’s. In the Data Window the color is green when above the breakeven point of making a profit and red when below the breakeven point. In the Table the color is red if below the breakeven point, otherwise it is the default color.The breakeven point is a relationship between the Profit/Risked and Winning % to indicate system profitability potential. Another way to assess trading system performance. For example, for a low Winning % a high Profit/Risked is needed for the system to be potentially profitable.
• Profit Factor (PF) is based on Trade-Grp’s. The dividend payment, if any, is not considered in the calculation of a win or loss. The “Include Dividends in Profit Factor” checkbox allows you the option to either include or not include dividends in the calculation of Profit Factor. The default is enabled.Must enable the “Include Dividends in Profit” checkbox to include dividends in PF.Including dividends in PF evaluates the trading strategy with a more overall profitability performance view.Enable/Disable “Include Dividends in Profit Factor” checkbox also affects the Avg Trade-Grp Loss, and thus Equity Loss from ECL and % Equity Loss from ECL.
• Max Consecutive Losses are based on Trade-Grp’s.
• Nbr of Trade-Grp’s and Nbr of Positions.These help you to determine if enough trades have occurred to validate your strategy. The Nbr of Positions is the count of positions on the chart. The TV list of trades in the Strategy Tester may indicate more than what is actually shown on the chart. The Data Window includes 'Nbr Strat Tester Trades', which equals the TV listing trades, to help you locate specific trades on the chart.
• Time in Market (%) is based on Trade-Grp’s and date range selected.
• Avg Invest/Trade-Grp will indicate the average amount of money invested in a Trade-Grp. This is adjusted for dividends if the “Include Dividends in Profit” checkbox is enabled.
• Equivalent Consecutive Losses, labeled as Equiv. Cons. Losses (ECL).This value is determined by the Winning % and Nbr of Trade-Grp’s. This simulates the more likely case of a series of losses, then a small win, then another series of losses to form an equivalent consecutive losing streak. To lower the value, increase the Winning %.
• Equity Loss from ECL is the equity loss from the equivalent consecutive losses.
• % Equity Loss from ECL is the percent of equity loss from the equivalent consecutive losses.
• Pyramid rules enforce and maintain position sizing designated by you on the Inputs tab (% Equity to Risk, Up/Dwn Gap) & Properties tab (number of pyramids, slippage, and commission).A pyramid position will not occur unless both its stop covers the last entry price with gap/slippage and commission cost of previous trade is covered. If take profit is enabled, a pyramid position will not occur unless commission cost of the trade is covered when take profit target is reached.
• Position sizing, stop-loss (SL), trailing stop-loss (TSL), and take profit (TP) are used.
• Wash sale prevention for applicable assets is enforced. Wash sale assets include stock and fund (e.g. ETF’s).
• No more than one entry position per candle is enforced .
• Losing Trade-Grp’s indicated at the exit with label text in the color blue. Used to easily find consecutive losses affecting your strategy’s performance. The dividend payment, if any, is not considered in the calculation of a win or loss.
• Position values can be displayed on the chart. The number format is based on the min tick value, but is limited to 8 decimal places only for display purposes.
• Dividends per share and the amount can be displayed on the chart.
• Hold Days . This is the number of days to hold before allowing the next Trade-Grp. Can be a decimal number. This feature may help those trading on a cash account to avoid any settlement violations when trading the same asset.
• Date Filter. Partition the time when trading is allowed to see if the strategy works well across the date range selected. The metrics should be acceptable across all four (4) time ranges: entire range, 1st half, IQR (inter-quartile range), and 2nd half.
• Price gap amount identification. Used in determining if a pyramid entry may be profitable, and may be used in determining slippage amount to use.
• When TP is enabled, the PSE will only allow a pyramid position if the potential is profitable based on commission and price gap selected.
• Trade-Grp’s shown in background color: green for long positions and red for short positions.
• The PSE will alert you to update your stop-loss as the market changes if your exchange/broker does not allow for trailing stop-loss orders. Enable this option on the Inputs tab with Alert Chg TSL.
• The PSE will alert you if your drawdown exceeds Max % Equity Drawdown set on the Inputs tab.
• The PSE will send an alert to warn you of an expiring GTC order.Some brokers will indicate the order is GTC, Good 'Till Cancelled, but there really is a time limit on the order and is typically 60-120 days. Therefore, the PSE will alert you if you've been in position for close to 60 days so you can refresh your order. The alert is typically a few days before the 60-day time period.
• For order fill alerts just use a {{placeholder}} in the Message of the alert. Details on how to enter placeholders is explained below.
• Identify same bar enter/exit for first entries and pyramids. This is shown in the Data Window as well. This can help you determine what stop-loss % works best for your trading style.
• Leverage trading information is displayed in the Data Window and applies to Trade-Grps.Failed PosSize or Margin (%): Shows a zero if the failed-to-trade position size was less than 1 or shows the margin % which failed to meet the margin requirement set in the Properties tab. A flag will show on the bar where a failed-to-trade occurred. This is only applicable to the first position of a Trade-Grp. Position the cursor over the flag for the value to show in the Data Window.
Notional Value: total Trade-Grp position size x latest entry price x point value. The equity must be > notional value x margin requirement for a trade to occur.Current Margin (%): must be greater than margin requirement set on the Properties tab in order for a trade to occur.Margin Call Price: when enabled on the Style tab is displayed on both the chart and the Data Window as shown below.
• Pyramiding requires the Stop Method to be set to either TSL or Both (meaning SL & TSL).
• The maximum number of pyramids is determined by the value entered in the Properties tab.
• Pyramid orders require the enter price to be higher than the previous close for Longs and lower than the previous close for Shorts.
• Pyramids also require the stop with gap/slippage to be higher than the last entry price for Longs, and lower than the last entry price for Shorts. This covers all previous positions and maintains position sizing.
• When take profit, TP, is enabled, the pyramids also require that they will be profitable when opening a position assuming they will reach TP. This is automatically adjusted by you with the Dwn Gap/Up Gap, Slippage, and Commission settings.
Enable to change background color where in a trade. Green for long positions and red for short positions.
Enable to show if losing Trade-Grp and is indicated by text in blue color. The last position may be at a loss, but if there was profit for the Trade-Grp, then it will not be shown as a loss .
Enable to show the currency value of each position in gold color.
This feature is only applicable if the asset pays dividends and the time frame period of the chart is 1D or less, otherwise ignored. The PSE assumes dividends are taken as cash and not reinvested.
Enable to adjust ROI, CAGR, Profit/Risked, Avg Invest/Trade-Grp, and Equity to include dividend payments. This feature considers if you were in position at least one day prior to the ex-dividend date and had not exited until after the ex-dividend date.
When Show Dividends is enabled it will display the payout in currency/share, as well as the total amount based on the number of shares the position(s) of the Trade-Grp are currently holding.
This checkbox allows you the option to either include or not include dividends in the calculation of Profit Factor. Must enable the “Include Dividends in Profit” checkbox to include dividends in PF. The dividend payment, if any, is not considered in the calculation of a win or loss.
Options are font size and table location.
Enable for the strategy to alert you when a trade did not happen due to low equity or low order size. Applicable only for the first position of a Trade-Grp.
Options are 'Longs Only', 'Both', 'Shorts Only'.
This is the number of days to hold before allowing the next Trade-Grp. Applies only to the first trade position of a Trade-Grp. Where a Trade-Grp consists of the first position plus any pyramid positions.
The value entered will be overwritten to >= 31 to prevent wash sale for applicable assets in the event the last Trade-Grp was a loss. Wash sale assets include stock and fund (i.e. ETF’s).
The minimum value is the equivalent of 1 candle and is automatically assigned by the PSE if the entered value is equivalent to less than one candle. To calculate Hold Days in # of candles on the Hour chart divide the chart period by 24 x #candles. On the Minute chart divide the chart period by 60 then by 24 x #candles.
Shows a vertical dotted line at the From Date and To Date for visual inspection of the setting.
When enabled, trades are allowed between the From Date and To Date, i.e., the date range.
When disabled, trades are allowed for all candles.
Partition the time when trading is allowed to see if your indicator settings work well across the date range. Click 1st Half, IQR (inter-quartile range), or 2nd Half buttons to trade a portion of the date range.
Select only one at-a-time to partition the time when trading is allowed.When 1st Half is enabled only trades for the 1st half of the date range are allowed.When IQR is enabled only trades for the inter-quartile date range are allowed.When 2nd Half is enabled only trades for the 2nd half of the date range are allowed.
The % of Equity to Risk has been separated into two (2) areas: for initial trades and for pyramid trades. This allows for greater ability to maximize profits within your acceptable drawdown. A variation of the Anti-Martingale method from the initial trade if you choose to use it in that manner.% Equity to Risk for Initial Trades: enter the percent of equity you want to risk per position for the initial trades of each Trade-Grp. For example, for 1% enter 1.% Equity to Risk for Pyramid Trades: enter the percent of equity you want to risk per position for the pyramid trades of each Trade-Grp. For example, for 2% enter 2.% Equity for Max Position Size: the position size will not exceed this amount. For example, for 25% enter 25.Max % Equity Drawdown Warning: an alert will be triggered if the maximum drawdown exceeds this v alue. For example, for 10% enter 10.
NOTE: The Stop Method must be either Both or TSL in order for the pyramids to work. This feature enforces position sizing.
Stop-loss, SL, and trailing stop-loss, TSL, are other features that enforce risk management.
The trailing stop-loss, TSL, is activated immediately if Stop Method = TSL. If Stop Method = Both, then the TSL is activated when its value is above stop-loss, SL, for Longs and below the SL for Shorts.
The calculated TSL value (shown on the chart by + symbol) of the previous bar is used for the current bar and the plot value is off by default, but you can it turn on via the Style tab. This is available so you can better understand how the TSL value used was calculated from. It is beneficial to show when monitoring the real-time candle.
When enabled, this feature will alert you to update your stop price if it moves greater than the change amount in %. The amount is the absolute % so will work for both Longs and Shorts. For example, for 1% enter 1 . This is provided since some exchanges/brokers do not offer TSL orders and you must manually adjust as price action plays out.
The alert will also suggest a stop limit price based on the gap selected and explained below.
The alert will occur at the close of the candle at the calculated TSL value of the candle just prior to the real-time candle.
A price gap is the difference between the closing price of the previous candle and the opening price of the current candle. Dwn Gap and Up Gap are illustrated here.
The values of the Dwn Gap and Up Gap can be seen in the Data Window and are based on the settings of the Date Filter.
The options are “zero gap”, "median gap", "avg gap", "80 pct gap", "90 pct gap". The X pct gap stands for X percentile rank. For example, "80 pct gap" means that 80% of the gaps are less than or equal to the value shown in the Data Window. Select “zero gap” to disable this feature.
If Show Stop Limit is enabled, it will show a dotted-line below or above the current stop price where a stop-limit order should be taken. It is shown based on the gap option selected. Again, the PSE trades market, limit, and stop orders, but a stop-limit may be shown if you wanted to see where one would be set using the Up/Dwn Gap.Dwn Gap: Affects Short Take Profit, Long Pyramid Entries, and to show the Long Stop Limit.Up Gap : Affects Long Take Profit, Short Pyramid Entries, and to show the Short Stop Limit.
When take profit (TP) is enabled, the PSE will determine if opening a pyramid position will be in profit assuming the TP will be hit while considering commission costs (on Properties tab).The larger of Up Gap or Slippage value is used with Long positions regarding TP.The larger of Dwn Gap or Slippage value is used with Short positions regarding TP.
Adjust Slippage on the Properties tab to account for a realistic bid-ask spread. You can use one of Dwn/Up Gap values or other guidelines. Again, the Dwn/Up Gap values are based on the Date Filter input settings.
Heed warnings from the TradingView Pine Script™ manual about values entered into the Slippage field.
The Slippage (ticks) have a noticeable influence on entry price and exit price especially at the beginning when the date range includes prices from $0.01 to $100,000.00 like that for BTC-USD INDEX. When this is the case, it is best to use different slippage values when partitioning time with the Date Filter.
To minimize the effects of slippage, yet account for it select ‘median gap’ on the Input Tab and use that value for slippage on the Properties tab.
The slippage value is included in the placeholder {{strategy.order.price}}.
The PSE is designed to be used both without leverage (the default) and with leverage.
These two settings apply to Trade-Grps. For example, for 5x leverage enter 20 (1/5x100=20).Margin for Long Positions: Set as desired. The default is 100%.
Margin for Short Positions: Set as desired. The default is 100%.
This setting on the Inputs tab applies to each trade position within a Trade-Grp.Max % Equity per Position: Set as desired. The default is 20% and intended for non-leverage trading. For leverage trading set as desired. For example, for 3x leverage enter 300 (3x100=300).
The PSE uses the strategy parameter calc_on_order_fills=true to allow for enter/exit on the same bar and generate alerts immediately after an order is filled. This parameter is on the Properties tab and is named ‘Recalculate After order is filled’ and is enabled by default.
Disabling this feature will cause the PSE to not work as intended.
You will see the following Caution! on the TV Strategy Tester
This occurs because the PSE has the strategy parameter calc_on_order_fills = true.
Again, the PSE will only work as intended if this parameter is enabled and set to true.
Therefore, you can close the caution sign and be confident of receiving realistic results.
• Using bar magnifier: Set as desired.
• On Bar Close: Disable. The PSE will not work as intended if this is enabled.
• Using Standard OHLC: Set as desired.
Set alerts to gain access to all the alerts from PSE. This allows for both order filled alerts, as well as the alert function calls related to refresh GTC orders, drawdown exceeded, update stop-loss order, and Failed to Trade.
Example Message for Manual Trading Alerts
(This is just an example. Consult TV manual for possible placeholders to use.){
Alert for {{plot("position_for_alert")}} position. (long = 1; short = -1)
{{exchange}}:{{ticker}} on TF of {{interval}} at Broker Name
{{strategy.order.action}} Equity x Equity_Multiplier USD in shares at price = {{strategy.order.price}},
where Equity_Multiplier = {{strategy.order.contracts}} x {{strategy.order.price}} / {{plot("Equity")}}
or {{strategy.order.action}} {{strategy.order.contracts}} shares at price = {{strategy.order.price}}.
}
Note: Use the Equity x Equity_Multiplier method if you have several accounts with different initial capital.
Example Message for Bot Trading Alerts
(You must consult your specific bot for configuring the alert message. This is just an example.){
"action": "{{strategy.order.action}}",
“price”: {{strategy.order.price}}
"amount": {{strategy.order.contracts}},
"botId": "1234"
}
The diagram below illustrates how to connect indicators to the PSE.
The Aroon and MACD indicators are only used here as an example. Substitute your own indicators and add as many as you like.
A video of how to connect your indicator(s) to the PSE is below.
https://www.tradingview.com/chart/QQQ/sTKK4nBK-HOW-TO-Connect-Indicators-to-the-PSE-Practical-Strategy-Engine/
The Connection Indicator for the PSE, also called here the connection-indicator.
Below is a description of how to connect your chosen indicators to the connection-indicator. Two (2) indicators were chosen for the example, but you may have one (1) or many indicators.
If you have source code access to your indicators you can paste the code directly into the connection-indicator to eliminate the need to have those indicators on the chart and the additional connection of them to the connection-indicator. Below will assume source code to the indicators are not available.
The MACD and Aroon Oscillator are from TV built standard indicators and are shown here just as an example for inputs (i.e. source) to the connection-indicator. They were configured as follows:
The source code for the connection-indicator is shown below. Substitute your own chosen indicators and add as many as you like to create your connection-indicator that feeds into the PSE. The MACD and Aroon Oscillator were simply chosen as an example. Configure your connection-indicator in the manner shown below.
The input box for the connection-indicator is shown below. The default for input source is “close”. For Input_Ind_1 click the dropdown and select the MACD Histogram. For Input_Ind_2 click the dropdown and select Aroon Up and Aroon Down as shown.
Below is a description of how to connect your chosen indicators to the PSE from the connection-indicator.
At the PSE Input tab, the Signal Connection Section is where you select the source of the Entry and Exit Signal to the PSE. These are the outputs from connection-indicator.
The default source is “close”. Click the dropdown and select the entry and exit signal to establish a connection as shown below.
הגישה לסקריפט זה מוגבלת למשתמשים שהוסמכו על ידי הכותב ובדרך כלל דורשת תשלום. אתה יכול להוסיף אותו למועדפים שלך, אך תוכל להשתמש בו רק לאחר שתבקש אישור ותקבל אותו מהמחבר שלו. למידע נוסף, צור קשר עם CoinOperator, או עקוב אחר הוראות המחבר למטה.
TradingView לא מציעה לשלם עבור סקריפט ולהשתמש בו אלא אם כן אתה סומך ב-100% על המחבר שלו ומבין כיצד הסקריפט עובד. במקרים רבים, אתה יכול למצוא אלטרנטיבה טובה לקוד פתוח בחינם בבסקריפטים הקהילתיים שלנו.