PROTECTED SOURCE SCRIPT

MACD Strategy - Backtest [AlgoRider]

Updated
█ OVERVIEW

Hello dear Tradingviewers !

We are excited to share with you this new indicator which simulates a trading strategy based solely on the well-known technical indicator MACD . We designed it for the sole educational and analytical purposes of showing novice traders and new investors that basing a trading strategy only on one such technical indicator is not necessarily a good thing to do. We do not recommend to apply this strategy for real.

Thanks to this indicator redesigned in our own way by incorporating our simple and easy-to-use Backtest functionality, you will be able to see and report on the performance and results that such a strategy has produced in the past.

The configuration window has also been designed to be easily readable and simple to use. Our goal is to make parameter customization as easy as possible.


█ HOW THE STRATEGY WORKS

  •   The script will simply trigger Long entries when bullish MACD crossings appear (the Macd line crosses the Signal line upwards) and Short entries when bearish MACD crossings appear (the Macd line crosses below the signal line).

  •   A Short signal ends a Long trade, a Long signal ends a Short trade.

  •   The script also allows setting up custom TP and SL.

  •   An option allows you to trigger early crossings, which will influence entries and exits.

  •   There is no repaint, once an entry/exit symbol or drawing is displayed it doesn't change anymore. The Short and Long signals appear at the open of the candles, just after the signal was confirmed at the close of the previous candle. The custom TP and custom SL signals can appear when a candle is not yet finished, but once displayed they don't change.


█ HOW TO PROCEED

 1 —  Once the script is applied to your chart, it already works with its default settings. You can already see the performance of the strategy in the data table directly on the chart (in the top right corner by default).

 2 —  You can customize the strategy and influence the results/performance by modifying its parameters. 3 types of parameters are present and can be modified.

 3 —  You can use this indicator in all types of markets.

 4 —  You can apply the script in every timeframe.


█ PARAMETERS

• Settings For Backtesting


  - Strategy :   Choose from a drop-down list if the strategy should execute only Long trades or only Short trades or both. Default Both.

  - Invest.   :   Choose the amount you want to invest in the simulation. Default 10000.

 -  Position  :   Choose the amount of the position (Size order) that will be used during the simulation. This will be the $ amount staked/involved for each trade entry.
Ex: If you put 20000 in position and 10000 in Invest. We consider that you use at least a leverage x2. Default 10000.

  - Slipp. TP :   Choose the amount in percentage of average slippage for Take Profits. This parameter makes it possible to predict a potential gap between the theoretical exit price for each TP (On the graph) and the real exit price on an exchange when implementing the strategy for real (slippage may be due to a time lag of a few seconds from execution time of the order on the exchange and/or due to the execution of a market order).
Ex: If a TP exit order of a Long trade, with entry $19000 (on BTCUSDT ), is carried out in theory on the chart at $20000, in practice on the exchange the script have indeed sent an exit order at 20000 , but if the true exit price is 20050, the TP slippage is then +0.25%. Default 0.

  - Slipp. SL :   Choose the amount in percentage of average slippage for Stop Losses. This parameter makes it possible to predict a potential gap between the theoretical exit price for each SL (On the graph) and the real exit price on an exchange when implementing the strategy for real.
Ex: If an SL exit order of a Long trade, entry $19000 (on BTCUSDT ), is carried out in theory on the chart at $18000, in practice on the exchange the script have indeed sent an exit order at 18000 $, but if the true exit price is 17950, the slippage SL is then +0.278%. Default 0.

  - Fees %  :   Choose the percentage amount of fees applied to each trade to simulate the application of the strategy on the exchange of your choice. Applies to the entry and exit of each trade. Ex: For Binance Futures: 0.04; For Bybit futures: 0.06; For Ftx Futures: 0.075. Default 0.

  -  Cumulate Trades  :   If you check this, the Backtest will use 100% of the balance as Order Size (Position) for All or in the next X consecutive trades. Default not checked.
⚠️ Be Careful please, this option is available to show the full extent and possibilities of the algorithm when pushed to its limits thanks to the accumulation of profits (cumulative earnings ), but it is a strategy that involves great risk. If a bad trade suffers a -50% loss, 50% of the account balance is lost, if the position is liquidated, the entire account balance is lost.

  - All          :   If you check this All trades will be accumulated. Default not checked.

  - Consecutive Trades :   Choose the number of trades to accumulate. After X consecutive trades, the algorithm reassigns the initial order size to the current one and starts again for X consecutive trades. Minimum Value 2, Default 2.


• Settings To Optimize Performances and Risk Management


  - Fast_MA         :  Choose the length of the Fast Moving Average. Default 12.

  - Slow_MA        :  Choose the length of the Slow Moving Average. Default 26.

  - Enable Early Crossings  :  If you check this, when the algorithm will detect an early crossing wethere bullish or bearish , it will trigger the Long or Short entries. Default not checked.

  - Oscillator MA Type   :  Choose if the Macd line should be an Exponential Moving Average or a Simple Moving Average . Default Expo.

  - Signal Line MA Type    :  Choose if the Signal line should be an Exponential Moving Average or a Simple Moving Average . Default Expo.

  - Use TP / Use SL     :  If you check these, the algorithm will trigger personalized trade exit signals when the price evolution has reached the amounts indicated since the trade entry. Default not Checked.

 -  % TP - SL        :  Indicate here the personalized amount in percentage that you want for your Take Profit and Stop Loss of each trade. Default 15-5.


• Settings For Appearances


  - Small-size Data Table  : If you check this, the data table will become smaller to free up more space on the chart to make it visually more pleasing. Default not checked.

       Hide Table  /
  -   Hide Labels /     : You can check these to get a cleaner chart and focus only on what interests you in the indicator. Default not checked.
   Hide Risk-Reward Areas


█ LIMITATIONS

  •   ⚠️ We repeat it once again, this strategy is not intended to be reproduced in real conditions, we have designed it for educational and analytical purposes only.

  •   Even if you see good performances when you backtest the strategy, you must take into account that these results are performed in the past and that in no case does this guarantee that these same performances will be repeated again in the future.

  •   When you run for real a trading strategy you must be aware of the fact that you are solely responsible for the results that you will be able to obtain and you must be aware of the possibility at all times of partial or even total losses of your invested capital.

  •   Keep in mind that generating profits in trading is difficult. A strategy can perform very well at one time in the past during a period that is favorable to it, then from one day to the next it can give really bad results for several months or years.

  •   When backtesting a trading strategy, there are many factors to consider, not just trade entries to which you add a Take Profit and sometimes a Stop Loss. You must at least take into account the size of the position in relation to the capital you want to invest, the trading fees, the slippages (which can be really important depending on the exchange on which you are trading and depending on the asset you are trading), trading frequency, risk management, momentum, volumes and even more.




The information published here on TradingView is not prohibited, doesn't constitute investment advice, and isn't created solely for qualified investors.




═════════════════════════════════════════════════════════════════════════

Important to note : our indicators with the same backtesting system are published in separate publications, because putting them together in a single script would considerably slow down the execution of the script. In addition each indicator, even when it is based on a simple technical indicator, has several options, parameters and entry/exit conditions specific to the underlying technical indicator. Finally, we want to keep the simplicity of use, configuration and understanding of our indicator by not mixing strategies that have nothing to do with each other.
Release Notes
Bug fix when "Use TP" is checked
Release Notes
UPDATE:
• Data available for Entry Long / Entry Short / Exit Long / Exit Short / Bullish / Bearish
• Hedge Mode
Moving Average Convergence / Divergence (MACD)Portfolio managementstatistics

Protected script

This script is published closed-source and you may privately use it freely.

Want to use this script on a chart?


To know more about our indicators & strategies, please visit our website: algorider.io
Also on:

Disclaimer