OPEN-SOURCE SCRIPT

Customizable Non-Repainting HTF MACD MFI Scalper Bot Strategy v2

Updated
Customizable Non-Repainting HTF MACD MFI Scalper Bot Strategy v2
This script was originally shared by Wunderbit as a free open source script for the community to work with. This is my second published iteration of this idea.

WHAT THIS SCRIPT DOES:
It is intended for use on an algorithmic bot trading platform but can be used for scalping and manual trading.
This strategy is based on the trend-following momentum indicator . It includes the Money Flow index as an additional point for entry.
This is a new and improved version geared for lower timeframes (15-5 minutes), but can be run on larger ones as well. I am testing it live as my high frequency trader.

HOW IT DOES IT:
It uses a combination of MACD and MFI indicators to create entry signals. Parameters for each indicator have been surfaced for user configurability.
Take profits are now trailing profits, and the stop loss is now fixed. Why? I found that the trailing stop loss with ATR in the previous version yields very good results for back tests but becomes very difficult to deploy live due to transaction fees. As you can see the average trade is a higher profit percentage than the previous version.

HOW IS MY VERSION ORIGINAL:
Now instead of using ATR stop loss, we have a fixed stop loss - counter intuitively to what some may believe this performs better in live trading scenarios since it gives the strategy room to move. I noticed that the ATR trailing stop was stopping out too fast and was eating away balance due to transaction fees.

The take profit on the other hand is now a trailing profit with a customizable deviation. This ensures that you can have a minimum profit you want to take in order to exit.

I have depracated the old ATR trailing stop as it became too confusing to have those as different options. I kept the old version for others that want to experiment with it. The source code still requires some cleanup, but its fully functional.

I added in a way to show RSI values and ATR values with a checkbox so that you can use the new an improved ATR Filter (and grab the right RSI values for the RSI filter). This will help to filter out times of very low volatility where we are unlikely to find a profitable trade. Use the "Show Data" checkbox to see what the values are on the indicator pane, then use those values to gauge what you want to filter out.

Both versions
Delayed Signals : The script has been refactored to use a time frame drop down. The higher time frame can be run on a faster chart (recommended on one minute chart for fastest signal confirmation and relay to algotrading platform.)

Repainting Issues : All indicators have been recoded to use the security function that checks to see if the current calculation is in realtime, if it is, then it uses the previous bar for calculation. If you are still experiencing repainting issues based on intended (or non intended use), please provide a report with screenshot and explanation so I can try to address.

Filtering : I have added to additional filters an ABOVE EMA Filter and a BELOW RSI Filter (both can be turned on and off)
Customizable Long and Close Messages : This allows someone to use the script for algorithmic trading without having to alter code. It also means you can use one indicator for all of your different alterts required for your bots.

HOW TO USE IT:
It is intended to be used in the 5-30 minute time frames, but you might be able to get a good configuration for higher time frames. I welcome feedback from other users on what they have found.

Find a pair with high volatility (exampleETH3LUSDT ) - I have found it works particularly well with 3L and 3S tokens for crypto. although it the limitation is that confrigurations I have found to work typically have low R/R ratio, but very high win rate and profit factor.

Ideally set one minute chart for bots, but you can use other charts for manual trading. The signal will be delayed by one bar but I have found configurations that still test well.
Select a time frame in configuration for your indicator calculations.

Select the strategy config for time frame (resolution). I like to use 5 and 15 minutes for scalping scenarios, but I am interested in hearing back from other community memebers.

Optimize your indicator without filters : customize your settings for MACD and MFI that are profitable with your chart and selected time frame calculation. Try different Take Profits (try about 2-5%) and stop loss (try about 5-8%). See if your back test is profitable and continue to optimize.

Use the Trend, RSI, ATR Filter to further refine your signals for entry. You will get less entries but you can increase your win ratio.

You can use the open and close messages for a platform integration, but I choose to set mine up on the destination platform and let the platform close it. With certain platforms you cannot be sure what your entry point actually was compared to Trading View due to slippage and timing, so I let the platform decide when it is actually profitable.

Limitations: this works rather well for short term, and does some good forward testing but back testing large data sets is a problem when switching from very small time frame to large time frame. For instance, finding a configuration that works on a one minute chart but then changing to a 1 hour chart means you lose some of your intra bar calclulations. There are some new features in pine script which might be able to address, this, but I have not had a chance to work on that issue.
Release Notes
Updating comments and chart
Release Notes
Revision 2.5
Updated to Pinescript 5
Much improved Variant/Moving Average filter I have been working on with a customizable timeframe. Set your moving average filter ot any timeframe any length and choose between SMA,EMA,DEMA,TEMA and a few more types.

Changed RSI filter to customizable time frame and length of RSI. If you use lower numbers for the filter (40->50) this can improve your win rate. Try using 5minute or 3minute settings for the RSI filter and tinker with the settings.

Use the show data feature to help you figure out which trades should be taken out and how to go about doing so.
Release Notes
Added a "Buy Above RSI" filter which allows you to have a minimum RSI for entries. This has proven to be very effective since you can filter out periods of low volatility or as market is in a definite downturn. For instance, you can try filtering out a 1 hour time frame, 30-40 periods and only put in entries between RSI => 40 to 70. This type of band is helpful to ensure that there is activity in the market. Alternately, you can set buys for longer range orders in lower time frames if you find the right settings and have a large enough stop loss. Hope that helps!
Release Notes
Updating chart - also be sure to note that the time frame in chart is for 1 minute and has about a weeks worth of data.
Release Notes
I fixed a bug when adding the indicator to your chart. Not sure what changed, but I just moved the logic outside of strategy.close function in order to run the function and this seemed to have fixed the problem. I think they are depracating the when= in strategy open and closes and that might be the culprit.
Average True Range (ATR)Money Flow Index (MFI)Relative Strength Index (RSI)wunderbitwunderbit_tradingwundertrading

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Also on:

Disclaimer