TN Alerts: A Smart Approach to Trade Entries and Exits

Category: Indicators By: Iván González Created: May 31, 2024, 3:32 PM
May 31, 2024, 3:32 PM
Indicators
4 Comments

Introduction

The indicator/system we will present is an alert system called TN alerts. This system is designed to identify entry and exit opportunities in the market using weighted moving averages and a trailing stop. The goal of this system is to provide clear signals for executing long and short trades while managing risk through the use of a dynamic trailing stop.

The TN alerts system stands out for its ability to adapt to different market conditions, offering a structured way to identify trends and manage trades efficiently. This system includes advanced features such as re-entries and signal visualization directly on the chart, facilitating decision-making for traders.

Indicator Parameters

The input parameters of the system are as follows:

  • TS (Trailing Stop): Percentage of trailing stop. This parameter defines the trailing stop adjustment percentage relative to the closing price.
  • TSswitch: Enable/disable the display of stop loss. When enabled, the stop loss is shown on the chart.
  • BGswitch: Enable/disable the background color on the chart. It allows clear visualization of long and short entry zones.
  • REswtich: Enable/disable the display of re-entries. Shows re-entry signals on the chart.
  • fastperiod: Fast period for calculating the moving average.
  • slowperiod: Slow period for calculating the moving average.
  • MAtype: Type of moving average to use (e.g., weighted).

These parameters allow high flexibility and customization of the system, adapting it to the trader’s specific needs and market behavior over different periods.

Moving Averages Calculation

Moving averages are a fundamental tool in technical analysis, and this system uses two:

  • wmaSlow: Slow moving average calculated over the period defined by slowperiod.
  • wmaFast: Fast moving average calculated over the period defined by fastperiod.

The moving averages are calculated as follows:

wmaSlow = average[slowperiod, MAtype](close)
wmaFast = average[fastperiod, MAtype](close)

The fast moving average (wmaFast) and the slow moving average (wmaSlow) help identify short-term and long-term trends, respectively. These moving averages are essential for determining the entry and exit conditions in the market.

Entry and Re-entry Conditions (Long and Short)

The conditions for long and short entries are defined as follows:

  • Long Entry: The slow moving average is greater than its previous value, and the current closing price is above the fast moving average, among other conditions.
  • Short Entry: The slow moving average is less than its previous value, and the current closing price is below the fast moving average, among other conditions.
enterlong = wmaSlow > wmaSlow[1] and close > wmaFast and close[1] > wmaFast[1] and close > close[1]
entershort = wmaSlow < wmaSlow[1] and close < wmaFast and close[1] < wmaFast[1] and close < close[1]

Re-entries

The system also considers re-entries in the same direction of the current trend, allowing to capitalize on extended market movements. This is visualized on the chart with specific colored arrows.

elsif REswtich and enterlong and inlong and inlong[1] then
    drawarrowup(barindex, low - 0.25 * tr) coloured("blue", 85)
elsif REswtich and entershort and inshort and inshort[1] then
    drawarrowdown(barindex, high + 0.25 * tr) coloured("gray", 85)

Re-entries are marked with blue arrows for long trades and gray arrows for short trades, indicating moments of reinforcement of the initial position.

Trailing Stop Calculation

The trailing stop is a crucial tool for risk management in trading. This system uses a dynamic trailing stop that adjusts based on the closing price. The trailing stop is calculated as follows:

tsPercent = TS / 100
once trailTop = close
if close > trailTop[1] or close < trailTop[1] * (1 - tsPercent) or entershort then
    trailTop = close
else
    trailTop = trailTop[1]
endif
once trailBot = close
if close < trailBot[1] or close > trailBot[1] * (1 + tsPercent) or enterlong then
    trailBot = close
else
    trailBot = trailBot[1]
endif

In this code, tsPercent defines the trailing stop percentage. trailTop and trailBot are used to store the trailing stop values for long and short positions, respectively. The trailing stop adjusts dynamically, allowing to lock in profits while minimizing losses.

Exit Conditions (Long and Short)

The system’s exit conditions are determined by the trailing stop. When the price reaches the trailing stop level, an exit signal is generated. The exit conditions are implemented as follows:

exitlong = trailTop < trailTop[1]
exitsh = trailBot > trailBot[1]
if enterlong then
    inlong = 1
elsif entershort or exitlong then
    inlong = 0
else
    inlong = inlong[1]
endif

if entershort then
    inshort = 1
elsif enterlong or exitsh then
    inshort = 0
else
    inshort = inshort
endif

Here, exitlong and exitsh determine if long or short positions should be closed based on the trailing stop. The variables inlong and inshort are used to track the current position status.

Visualization on the Chart

The system visualizes signals on the chart using arrows and background colors. This facilitates the interpretation of signals and decision-making in trading. The visualization is implemented as follows:

if inlong and Tsswitch then
    drawpoint(barindex, trailTop * (1 - tsPercent), 3) coloured("red")
elsif inshort and Tsswitch then
    drawpoint(barindex, trailBot * (1 + tsPercent), 3) coloured("green")
endif
if inlong and BGswitch then
    backgroundcolor("green", 15)
elsif inshort and BGswitch then
    backgroundcolor("red", 15)
endif
if enterlong and not inlong[1] then
    drawarrowup(barindex, low - 0.25 * tr) coloured("green")
elsif entershort and not inshort[1] then
    drawarrowdown(barindex, high + 0.25 * tr) coloured("red")
elsif REswtich and enterlong and inlong and inlong[1] then
    drawarrowup(barindex, low - 0.25 * tr) coloured("blue", 85)
elsif REswtich and entershort and inshort and inshort[1] then
    drawarrowdown(barindex, high + 0.25 * tr) coloured("gray", 85)
elsif exitlong and inlong[1] and not entershort then
    drawtext("▼", barindex, high + 0.25 * tr) coloured("black")
elsif exitsh and inshort[1] and not enterlong then
    drawtext("▲", barindex, low - 0.25 * tr) coloured("black")
endif

In this code, green and red arrows indicate long and short entries, respectively. Blue and gray arrows indicate re-entries, while black symbols indicate exits.

Complete Code of the Indicator/System

//--------------------------------------------------------------------------------//
//PRC_TN alerts
//version = 0
//11.03.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------------------------------//
//-----Inputs---------------------------------------------------------------------//
TS = 20 //% Trailing stop
TSswitch = 1 // Display Stoploss
BGswitch = 1 // Display BG color
REswtich = 1 // Display Re-entry
fastperiod=4
slowperiod=62
MAtype=2
//--------------------------------------------------------------------------------//
//-----Moving average calculation-------------------------------------------------//
wmaSlow = average[slowperiod,MAtype](close)
wmaFast = average[fastperiod,MAtype](close)
//--------------------------------------------------------------------------------//
//-----Setup Long&Short-----------------------------------------------------------//
enterlong = wmaSlow>wmaSlow[1] and close>wmaFast and close[1]>wmaFast[1] and close>close[1]
entershort = wmaSlow<wmaSlow[1] and close<wmaFast and close[1]<wmaFast[1] and close<close[1]
//--------------------------------------------------------------------------------//
//-----Trailing stop calculation--------------------------------------------------//
tsPercent = TS/100
once trailTop = close
if close>trailtop[1] or close<trailtop[1]*(1-tspercent) or entershort then
trailTop = close
else
trailTop = trailTop[1]
endif

once trailBot = close
if close<trailBot[1] or close>trailBot[1]*(1+tspercent) or enterlong then
trailBot = close
else
trailBot = trailBot[1]
endif
//--------------------------------------------------------------------------------//
//-----Exit Long&Short------------------------------------------------------------//
exitlong = trailTop < trailTop[1]
exitsh = trailBot > trailBot[1]

if enterlong then
inlong = 1
elsif entershort or exitlong then
inlong = 0
else
inlong = inlong[1]
endif

if entershort then
inshort = 1
elsif enterlong or exitsh then
inshort = 0
else
inshort = inshort
endif
//--------------------------------------------------------------------------------//
//-----Drawing trails-------------------------------------------------------------//
if inlong and Tsswitch then
drawpoint(barindex,TrailTop*(1-tspercent),3)coloured("red")
elsif inshort and Tsswitch then
drawpoint(barindex,TrailBot*(1+tspercent),3)coloured("green")
endif
//--------------------------------------------------------------------------------//
//-----Background colors----------------------------------------------------------//
if inlong and BGswitch then
backgroundcolor("green",15)
elsif inshort and BGswitch then
backgroundcolor("red",15)
endif
//--------------------------------------------------------------------------------//
//-----Plot signals---------------------------------------------------------------//
if enterlong and not inlong[1] then
drawarrowup(barindex,low-0.25*tr)coloured("green")
elsif entershort and not inshort[1] then
drawarrowdown(barindex,high+0.25*tr)coloured("red")
elsif REswtich and enterlong and inlong and inlong[1] then
drawarrowup(barindex,low-0.25*tr)coloured("blue",85)
elsif REswtich and entershort and inshort and inshort[1] then
drawarrowdown(barindex,high+0.25*tr)coloured("gray",85)
elsif exitlong and inlong[1] and not entershort then
drawtext("▼",barindex,high+0.25*tr)coloured("black")
elsif exitsh and inshort[1] and not enterlong then
drawtext("▲",barindex,low-0.25*tr)coloured("black")
endif
//--------------------------------------------------------------------------------//
return wmaFast as "WMA Fast"coloured("blue"), wmaSlow as "WMA Slow"coloured("purple")

Conclusion

This system provides a powerful tool for identifying entry and exit opportunities in the market using moving averages and trailing stops. The customization of parameters allows the system to adapt to different trading styles and markets. It is important to test and adjust the system in various market conditions to maximize its effectiveness.

The TN alerts is a versatile system that can be used by both novice and experienced traders. Its clear visualization and well-defined rules make it a valuable addition to any trading strategy.

Download
Filename: PRC_TN-alerts.itf
Downloads: 279
Iván González Master
Developer by day, aspiring writer by night. Still compiling my bio... Error 404: presentation not found.
Author’s Profile

Comments

Logo Logo
Loading...