Categories
Forex Daily Topic Forex System Design

Trading System design -Creating Your Strategy with Tradingview’s Pine Script – Part 2

In part 1 of this article series, we have created the Stochastic RSI indicator as part of our idea for a scalping strategy. Now that we have it functional, we will make the bull/bear phases and visually inspect whether it captures the turning market’s turning points.

Possible ways to create bull/bear slices

Our Stochastic RSI consists of two lines, k and d, and two trigger lines, ob and os. Therefore we can use multiple variants that may allow the creation of bull/bear price legs. Let’s consider the following 3

Variant 1 – The transition occurs at the SRSI entrance of the oversold or overbought regions.

Bull: The d-line crosses under the ob-line, which indicates it is into the overbought area
Bear: The d-line crosses over the os-line, indicating d‘s entry into the oversold area.

Code:
if crossunder (d, os)
    SRSI_Long := true
    SRSI_Short := false
else if crossover (d, ob)
    SRSI_Long := false
    SRSI_Short := true 
else
    SRSI_Long := SRSI_Long[1]
    SRSI_Short := SRSI_Short[1]

This code creates a condition SRSI_Long at the cross of d under os, which holds until d crosses over ob and reverses it, creating an SRSI_Short state. This condition is only modified by d crossing under os.
The else statement ensures the condition does not change from the previous bar.

Once we have defined the bull and bear segments, we can color-shade them to visualize them in the chart. To do it, we will use the bgcolor() function.

bgcolor(SRSI_Long ? color.green: na)
bgcolor(SRSI_Short ? color.red: na)

The first statement asks the condition of SRI-Long ( the ? sign). If true, the background color changes to green. Otherwise, no change (an). The second statement behaves similarly for SRSI_Short.

Let’s see how this piece of code behaves in the BTCUSD chart.

Variant 1 triggers the transitions too early. We see that on many occasions when the stochastic RSI enters the overbought or oversold region, it is more a signal of trend strength than a turning point.


Variant 2 – The transition occurs at D and K’s crossovers if in the overbought/oversold regions.

Bull: the k-line crosses over the d-line, if below os ( inside the oversold region. We ignore crosses in the mid-area)
Bear: the k-line crosses under the d-line, if above ob ( in the overbought area. We ignore crosses in the mid-area)

Code:

// creating the long and short conditions for case 2

if crossover(k,d) and d < os
     SRSI_Long := true
     SRSI_Short := false

else if crossunder(k,d) and d > ob
     SRSI_Long := false
     SRSI_Short := true
else
     SRSI_Long := SRSI_Long[1]
     SRSI_Short := SRSI_Short[1]
// bacground color change
bgcolor(SRSI_Long ? color.green: na) 
bgcolor(SRSI_Short ? color.red: na)

The last section for the background change is similar to Variant 1.

Let’s see how it behaves in the chart.

Variant 2 is an improvement. We see that the bull and bear phases match the actual movements of the market, although entries are still a bit early, and in some cases, it missed the right direction. It can be useful as a trigger signal, provided we can filter out the faulty signals.


Variant 3 – the transition occurs when d moved to the overbought or oversold region and, later, crosses to the mid-area.

Bull: the d-line crosses over the os-line
Bear: the d-line crosses under the ob-line.

if crossover (d, os)
    SRSI_Long := true
    SRSI_Short := false
else if crossunder (d, ob)
    SRSI_Long := false
    SRSI_Short := true 
else
    SRSI_Long := SRSI_Long[1]
    SRSI_Short := SRSI_Short[1]
// bacground color change
bgcolor(SRSI_Long ? color.green: na) 
bgcolor(SRSI_Short ? color.red: na)

 

And this is how it behaves in the chart.


Variant 3 lags the turning points slightly, but this quality makes it more robust, as, on most occasions, it’s right about the market direction. This signal, combined with the right take-profit, may create a high-probability trade strategy.

Let’s try this one. But this will be resolved in our next and last article of this series.

Stay tuned!

Categories
Forex Daily Topic Forex System Design

Trading System design -Creating Your Strategy with Tradingview’s Pine Script – Part 1

As promised, in this article, we will go through the steps to create a custom strategy, from the initial idea to the implementation of signals, stops, and targets.

The skeleton of a trading Strategy

To create a strategy programmatically is relatively simple. We need to define the Parameters and the trade rules first, followed by the position sizing algorithm, the entry commands, and the stop-loss and take-profit settings.

Visualizing the idea

Human beings are visual. We may think our trading idea is fantastic, but translating it into code may not be straightforward. It is much easier to detect the errors if we see our rules depicted on a chart.

With the parameter declarations and trade rules, we can create an indicator first, so we can see how it appears. After we are happy with the visual 

The idea

For our example, we will use a simple yet quite exciting indicator called Stochastic RSI, which applies the Stochastic study to the RSI values. This operation smoothes the RSI, and it reveals much better the turning points on mean-reverting markets, such as in Forex. Let’s see how it behaves as a naked strategy.

Diving into the process

First, you need to open an account with Tradingview. Once we are in, we create a new layout.

Then we open the Pine Editor.

It appears in the bottom left of your layout. Click on it… and it shows with a basic skeleton code.

The Stochastic RSI code.

As said, to create the Stochastic RSI indicator, we will make the RSI and then apply the stochastic algorithm to it.

1 study(title="Stochastic-RSI", format=format.price, overlay = false)

This first line declares the code to be a study, called Stochastic-RSI.  

format = format.price is used for selecting the formatting of output as prices in the study function.

Overlay = false means we desire the RSI lines to appear in a separate section. If it were a moving average to be plotted with the prices, overlay should be set to true.

RSIlength = input(14, "RSI-Length", minval=1)

We define the RSI length as an input parameter called RSI-Length.

src = input(close, title="RSI Source")

The variable src will collect the input values on every bar. The default is the bar close, but it may be modified by other values such as (o+c)/2.

myrsi = rsi(src, RSIlength)

This line creates the variable myrsi that stores the time series of the rsi.

This completes the calculation of the RSI. 

smooth_K = input(3, "K", minval=1)
smooth_D = input(3, "D", minval=1)

These two lines create the smoothing values of the stochastic %K and %D. Since it comes from input, they can be changed at will.

Stochlength = input(14, "Stochastic Length", minval=1)

This code defined the variable lengthStoch, computed from the input parameter.

k = sma(stoch(rsi1, rsi1, rsi1, Stochlength), smooth_K)
d = sma(k, smooth_D)

These two lines completes the calculation of the stochastic rsi.

plot(k, "K", color=color.white) - Plot a white k line 
plot(d, "D", color=color.red) - Plot a red d line.

To end this study, we will plot the overbought and oversold limits of 80 and 20, filling the mid-band with a distinctive color.

t0 = hline(80, "Upper Band", color=color.maroon)
t1 = hline(20, "Lower Band", color=color.maroon)
fill(t0, t1, color=color.purple, transp=80, title="Background")

The complete code ends as:

 

// This source code is subject to the terms of 
// the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © forex-academy
//@version=4
study(title="Stochastic-RSI", format=format.price, overlay = false)

RSIlength = input(14, "RSI-Length", minval=1)
src = input(close, title="RSI Source")
myrsi = rsi(src, RSIlength)

smooth_K = input(3, "K", minval=1)
smooth_D = input(3, "D", minval=1)
Stochlength = input(14, "Stochastic Length", minval=1)

k = sma(stoch(myrsi, myrsi, myrsi, Stochlength), smooth_K)
d = sma(k, smooth_D)

plot(k, "K", color=color.white)
plot(d, "D", color=color.red)

t0 = hline(80, "Upper Band", color=color.maroon)
t1 = hline(20, "Lower Band", color=color.maroon)
fill(t0, t1, color=color.teal, transp=80, title="Background")

This code is shown in our layout as

Stay tuned for the second part of this article, where we will evolve the Stochastic RSI into a viable strategy.

 

Categories
Forex Basics

TradingView Made Me A Better Trader (and It Can Do the Same for You)

TradingView is a technical analysis tool with a wide range of functions. It is basically a platform where you can perform analyses of different assets and markets in a simple, easy, and intuitive way. But it doesn’t stop there…

TradingView offers an online social network service for Traders. It is the most active social network for traders and investors, where you can talk to millions of traders around the world, and where users share their study of different assets and financial markets as well as being a place to discuss ideas for possible operations. In addition, we can operate directly from the platform if we connect a Broker to our Tradingview account.

What is TradingView?

It is a social trading platform, founded in 2011 and covering a major need for many traders. Since TradingView only acts as an analysis tool for upcoming trades and exchanges between investors and traders, we cannot classify it as a broker… In short, TradingView is a kind of social network for traders that in turn allows for analyses of different markets and financial instruments.

How much does Trading View cost? There are several possibilities as far as account type is concerned. We can get Tradingview for free, and we can opt for paid versions. As we write this article (during the final quarter of 2020), the available options are as follows:

You can create a free account, which provides basic services such as 1 chart per tab, 3 indicators per chart, and a saved chart layout, among other features. Access is limited to one device to the free account at a time.

Payment account options include Pro, Pro+, and Premium.

We have the TradingView Pro subscription: It is priced at $9.95 per month if billing is done every 2 years, $12.95 per month if invoiced every year, and $14.95 if invoiced every month.

Second TradingView Pro+ subscription: It is priced at $19.95 per month if billing is done every 2 years, $24.95 per month if invoiced every year, and $29.95 if invoiced every month.

And finally the TradingView Premium subscription: It has a price of 39.95 dollars per month if billing is done every 2 years, 49.95 dollars per month if invoiced every year, and 59.95 dollars if invoiced every month.

For more up-to-date information on prices and features, you can visit their website.

How to Use TradingView

How to set up Tradingview is one of the questions that every user asks the first time they use the platform. As we mentioned before, it has many tools, different types of graphics, and indicators of all kinds, designed in an easy and intuitive way for easy use and for all types of Traders, both beginners, and experts. Therefore the user will have at their disposal everything necessary to analyze, in a professional and simple way, the assets and/or markets that interest him.

How to operate Tradingview is simple thanks to its intuitive and user-friendly interface. Still, let’s give a brief overview of the entire platform. On the platform, in its most basic format; the one that comes by default before working and customize our space based on the functions of the package we have, we can see:

In the center, we find the price chart.

On the left side, we show the tools available for the analysis of the graph.

If we look at the top we will see a menu that allows us to change the asset, the temporality of the chart, the type of chart we want to have, indicators, or price alerts that we want to program.

At the top right, we can create and save profiles or graphics templates, or switch between those we already have saved. We can also from here modify the view size or some basic design options and properties of the chart as well as publish or share it with other users.

In the extreme right, we will see tools to create watch lists, the news calendar, our published operational ideas, or the option of “help” among other functions.

Finally, in the right area of the screen, we will see a table where we can follow the prices and news of the watch lists that we believe in the menu of zone 5.

As you can see, Tradingview offers endless features and features that will be useful for Traders who are starting their way in the financial markets as expert Traders or Professional Traders.

How to Trade With the TradingView Platform

Many traders ask themselves the following questions, usually before entering the mode of payment, in order to make the most of the platform:

  • Is Tradingview a Broker?
  • How to connect a broker to Tradingview?
  • Which brokers do you support?

All these questions have answers. Tradingview is not a broker, but if you have Brokers that can connect to the platform and so be able to trade with them through the platform and thus avoid having to change screens and simplify and streamline the operation.

Unfortunately, not all brokers can connect to Tradingview, and in addition, these, are changing over time. On their website, we can find the Affiliate Brokers, but we will see how to see it in the platform in a simple way and also know how to connect a Broker with TradingView.

Display the Tradingview Supported Brokers box. To see this, it is as simple as clicking on purchase or sale. We will automatically open at the bottom of our screen the Brokers available to trade with Tradingview, make sure you no longer have your Broker connected or you will be entering with a purchase or sale to the market.

In order to realize everything, we will have to be logged into our Tradingview account and have a Trading account in one of the accepted Brokers. Once we select the Broker we want to connect with, we will simply have to follow the simple steps and provide the information we are asked to provide. Once the broker is connected to the platform, being able to buy or sell will be just one click away.

What we would recommend is to do a bit of land survey and read reviews about Tradingview and its functionality with a connected Broker, as well as reviews from the Broker that we will use before launching into the water. This way we will not make false moves. And if our Broker is not one of the accepted ones, we can always take a look at alternatives to TradingView…

Is Trading View a broker? No, it is not. But as we mentioned, it has the option of being able to connect the broker’s “partners” and thus be able to operate from the same platform.

Alternatives to TradingView

Some examples of alternatives to TradingView may be:

  • MetaTrader
  • NinjaTrader
  • Protrader
  • Muunship
  • Trade Republic
  • Kattana

Tradingview is a platform of great utility for all Trader, be it Novice or expert, where to analyze different activities and financial markets. The reality is that it is a large social network with the aim of operators to exchange analyses, ideas, and opinions. And if we have our broker account connected, it will allow us to operate directly from the platform. It is therefore a platform with many functionalities and therefore one of the most used trading platforms.