TradingView
Solutions1978
29 июня 2021 г., 02:55

Dynamic Price Swing 

Описание

Finally, a price channel oscillator that works.

I programmed three flavors into this.

The first flavor uses the Fast and Slow EMA to check for the trend to ensure you don't trade in the wrong direction simply because the price crosses the previous highest high or lowest low (based on lookback bars).

The second flavor uses a seven point average of the Fibonacci bands to create an upper and lower central channel for quick trades (like DOGE).

The third flavor uses the golden Fibonacci ratio of 1.618 and trades when the price moves above or below this band.

Информация о релизе

Couple of tweaks to make this a better script with some additional precautionary checks for the trade triggers.

Basically this script is dynamically updated so it does not require constant maintenance. The basic price channel (Default selection) just looks for ups and downs from an average of the highest highs and lowest lows to trade based on volatility. It works best on a 30 minute timeframe. It depends on the lookback period, RSI, and risk management functions.

The other options require an understanding of the moving average and Fibonacci retracement to use. The fib portion is much less complicated since I've added the sequence selections as drop down choices. It's better suited for crypto that has wild swings above and below the Fibonacci retracement levels (like BTC and ETH have been doing lately).

Информация о релизе

After working on this through another 300 revisions, I finally got it to be more realistic if using the mixed Long/Short strategy and by adding some linear regression logic to make the channel logic more aggressive.

All of the triggers use the Risk Management Inputs and Lookback Periods.

This script will aggressively scalp crypto using the Average Price Channel strategy. This strategy depends upon the RSI Length, EMA Fast & Slow Lengths. Since it is aggressive you can tweak it using the risk management inputs based on the amount of your capital you are willing to draw down.

The Moving Average is less aggressive and depends on the same parameters as the Price Channel, but only triggers when the price channel is crossed.

The Fibonacci Average has been tweaked considerably to be more reliable and to have additional retracement level options for the upper and middle bounds. This trigger uses the Fast & Slow EMA Lengths and does not use the RSI Length.

The Price dips and peaks is still being worked on, right now it does okay but I am looking at combining some additional trend indicators with it to make it more robust.


Информация о релизе

Finally perfected this script after adding another 200 lines of code.

This strategy uses a blend of static and user input values for the indicators. I went over months of trade data to identify patterns that occur across multiple crypto currencies and used those common crosses or whether values were higher or lower than another and these are included as the triggers for buying and selling.

Additionally, since I have been contacted by many of you that would like to be able to send alerts to 3Commas or other webhook based bots I added an area in the strategy input for you to paste in the webhook message.

Since longs and shorts have different patterns this script is not intended to be used for both long and short at the same time. You will need to tweak the settings individually for long or short and have a one strategy to one bot ratio. In other words, if you are doing a long and short strategy for AMP, then you will set up two different alerts. One that is based on the long only settings for your long bot and another that is based on your short only settings for the short bot.

This strategy operates the best at a 15 minute resolution, any lower or higher has different patterns and I did not have the time to program all of the variations. This is why I am publishing this script as open source so you can have at it if you wish.

Информация о релизе

I took @janor123 comments to heart and went back through the strategy and removed items which could lead to overfitting or complicated the script more than it should be.

Other changes: Instructions on how to use this script are included in the settings tab of the script.

Major change: First real walkthough of any of my scripts to explain precisely how to use it.

Using the Average Price Channel
Summary of Settings
Stop Loss = 7
Target Profit = 8.1
Stop Trading Days = 3
Maximum Equity Loss % = 10
EMA Fast = 20
EMA Slow = 8 (not a typo, read the logic below)
Avg # bars 12
Price Lookback = 7

Setting the EMA Crossover
1. Add EMA Crossing Indicator by traderscorner
2. Default settings – when the Fast EMA is above the Slow EMA it indicates an upward trend and vice versa. Lower numbers for both fast and slow indicate faster responses to price movements and more crosses while higher numbers have less crosses and can provide insight into resistance levels. There is a little known secret here, take a look at the arrow placement for default settings of 5 for fast and 9 for slow. As you can see by the red (sell) and green (buy) arrows the trigger happens too late and in the wrong places.



Have you ever tried switching the lengths? Well, if you break the rules to see what will happen you will see that the arrows actually do line up where you want them to and actually indicate the right zones for buying and selling. You do not have to follow this advice, it is a suggestion for innovative thinking as part of this walkthrough of how to use this script.



Knife Settings

Find the longest high wick and calculate the percentage difference between the high and the close (diff = (high-close)/close * 100%). Find more than one so you can take an average. For my settings, the average of the three I found was 3.2%.




Picking a Strategy Setting: Long or Short but not Long/Short

I look at the Performance Summary Tab with my default risk management settings and select the strategy with the highest gross profit. Now, due to the compounding nature of back testing when I change the strategy from Long/Short to Long Only the values in the Performance Summary tab will change to about 50% of what you see initially. Once I have selected a strategy, I go back and tweak the Average # of Bars and Price Lookback Period by +/- 3.

Risk Management Settings

The final setting to define are the risk management settings. What I do is take a look at the Drawdown and losing trade (negative profits) and add these two numbers up. I get the following values: 5.46, 6.71, 6.11, 8.63. I use these to test out a range of potential target profits that are realistic. I notice the highest profit at 8 and it went back down at 9. After a few more keystrokes of trial and error, I find that the sweet spot is 8.1%.

The stop loss is something you define based on comfort level. Setting it too low will skew the results and setting it too high will give you unrealistic expectations. For me, my comfort level is losing 7% on any trade.

Finally, if you leave this script on autopilot and want to make sure you don’t have it run awry then you would want to use the Stop Trading and Halt Trading settings. I set my losing days to 3 days in a row before the script halts and my maximum overall equity loss to 10%. This is based on personal preferences and does not have any logic or math behind it.


If you have any comments or questions, please feel free to reach out to me. As you can see by my update, I will listen to criticism and take a look at my scripts from your point of view to make it better for the TV community.

Информация о релизе

1. Had a typo in the Moving Average strategy, fixed it.
2. Added colors for using this as an indicator until I publish the study version.

Note: For Moving Average and Fibonacci strategy selections, DO NOT reverse the EMA lengths. That works when trying to do quick scalps as part of price channel movements based only on lows and highs. The MA and Fib strategies work best with the slow EMA length of between 20 and 50 with the fast EMA length of 10 to 20.

Информация о релизе

Another typo fixed on the coloring of the upper and lower price bands. It all works now, each strategy has been checked out as working and realistic.
Комментарии
Solutions1978
Forgot to mention:

To keep it a bit simpler I added inputs for all webhook messages to eliminate the need to recreate strategies as studies. For example, if you use 3Commas the messages look like this:

{
"message_type": "bot",
"bot_id": 1352051,
"email_token": "83da02b1-ac90-44c4-be6f-467cca698946",
"delay_seconds": 0
}

Copy the message and paste it in the right field, for example if you have a short bot set up on 3commas you will copy the trade start message from your bot and paste it into the Short Entry Message field in the strategy settings.

Then you would copy the 3commas message for closing the open deal into the Short Exit Message field.

Likewise, you would do the same for a long bot you created there.

Creating alerts after that it’s super simple. Create an alert from the strategy and set up it in a usual for the tool you’re using. All you need to do is create one single alert and replace the text in the alert with the following placeholder and you are good to go:

{{strategy.order.alert_message}}
innovationinvestmentpartners
thanks
definancingseason
This is pretty good thank you!
azubu23202869
Gradient Color Bars is not work
kazmirza8
how do you interpret this? your description sounds great, but the indicator looks so busy on screen that I don't know where to enter/where the exit.. please advise thank you
Solutions1978
@kazmirza8, this is designed as an automated strategy. I plan on converting it to a study with alerts this weekend.

In the meantime, you can use the message entries in the settings to create alerts. Instead of putting in the webhook messages you can do this:

Long Entry Message = Go Long
Long Exit Message = Close Long
Short Entry Message = Go Short
Short Exit Message = Close Short

Then create one alert that sends either an email or an SMS indicating the trigger for you to execute your trade manually. Change the body of the alert to {{strategy.order_alert_message}} and your alert will send you the right message based on the trigger condition.
Solutions1978
@kazmirza8,

I included some coding especially for you to make it easier to interpret this strategy visually instead of automated.

1. Turn on Use Gradient Color Bars and Colorize Bars
2. Pick the Purple -> Blue gradient
3. Look for these patterns

kazmirza8
@Solutions1978, WOW!!! Your thoroughness and willingness to listen to feedback means a lot!!! So much value delivered. I hope everyone reading this follows and approves of Solutions1978's work. This is amazing -- thank you :-)
I will have a couple of technical questions for you soon, Sir!

Thanks again!!!!
janor123
with so many variables/inputs, the predictive power is greatly diminished (i.e. backtest may look great, but odds are its overfitted). Especially given the relatively small sample size. As a general rule, you should have 20-25 trades *per input parameter*. This helps to mitigate the risk of overfitting. That means with a sample size of only 58 trades, you should have no more than 1 or 2 parameters, otherwise the strategy is almost certainly overfitted.
Solutions1978
@janor123,

I disagree that it is overfitted. These scripts I publish here represent a watered down version of the code I have running in AWS Neural Networks using AI and ML. Yes, there are quite a lot of variables; however, there are common patterns that are in every crypto. This script is tailored to the crypto trading realm, and my previous version had backtests that looked great but were resulting in more trades with losses. I went back to the drawing board and tried to create something that behaved the same way a person would sitting at the terminal and day trading. You look at an indicator, see there is a common price channel, set a sale at the top and hope the pattern repeats...and sometimes it works while other times you misread the indicators and a pump happened resulting in a loss for you.

I hated these pumps and looked for common things that occurred as a sign NOT to try a short scalp. That is in here as my vernacular indicator "Erection." Likewise there is a dump that happens, again there are crosses that happen across multiple variables that provide an 80% accuracy of the dump coming. This is in here as "flacid" or things of the like. I had my fun programming this and hope that it is looked at with a critical eye to see the value in it or provide comments on how to improve it.
Ещё