diff --git a/202_macd_concept_Darshan_Edit.ipynb b/202_macd_concept_Darshan_Edit.ipynb new file mode 100644 index 0000000..7d3cbd2 --- /dev/null +++ b/202_macd_concept_Darshan_Edit.ipynb @@ -0,0 +1,167 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Moving Average Convergence/Divergence (MACD) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### MACD logic:\n", + "- Moving average convergence/divergence (MACD, or MAC-D) is a trend-following momentum indicator that shows the relationship - between two moving averages (simple or exponential) of a security’s price. The MACD line is calculated by subtracting the 'long period moving average' from 'short period moving average'\n", + "- Take for example below moving averages:\n", + "- short moving average (window = 12, fast moving)\n", + "- long moving average (window = 26, slow moving) \n", + "- macd = short ma - long ma\n", + "- signal line = ma of macd (window = 9)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Key Takeaway:\n", + "- MACD is best used with daily periods, where the traditional settings of 26/12/9 days is the norm.\n", + "- MACD triggers technical signals when the MACD line crosses above the signal line (to buy) or falls below it (to sell).\n", + "- MACD can help gauge whether a security is overbought or oversold, alerting traders to the strength of a directional move, and warning of a potential price reversal.\n", + "- MACD can also alert investors to bullish/bearish divergences (e.g., when a new high in price is not confirmed by a new high in MACD, and vice versa), suggesting a potential failure and reversal.\n", + "- After a signal line crossover, it is recommended to wait for three or four days to confirm that it is not a false move\n", + "- When market trends are improving, short term averages will rise more quickly than long term averages. MACD line turn up\n", + "- When market trands are losing strength, shorter term averages will tend to flatten, ultimately falling below longer term averages if declines continue. MACD line fall below 0\n", + "- Weaking trends are reflected in changes of direction of MACD reading, but clear trend reversals are not usually considered as confirmed until other indications, which will be discussed, take place.\n", + "- During the course of price movement, short term moving averages will move apart (diverge) and move together (converge) with longer term moving average- hence, the indicator name \"moving average convergence-divergence\"\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### MACD graphical Illustration\n", + "\n", + "\"drawing\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"drawing\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Signal line\n", + "- The signal line is an exponential average of MACD levels, not of the price of the investment. \n", + "- Signal lines are usually created employing 3-day to 9-day exponential averages of MACD lines.\n", + "- The shorter the average the more sensitive will be the signal line.\n", + "\n", + "\"drawing\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### MACD Buy and Sell Signal\n", + "- Short term moving average = STMA\n", + "- Long term moving average = LTMA\n", + "- MACD = STMA - LTMA\n", + "- When STMA crosses LTMA from top, this is a signal to sell the stock\n", + " - When MACD touches zero line from top, this is a signal to sell stock\n", + "- When STMA crosses LTMA from bottom, this is a signal to buy the stock\n", + " - When MACD touches zero line from bottom, this is a signal to buy stock\n", + " \n", + "### Buy and Cell signal explained\n", + "- Changes in MACD direction (from down to up and vice versa) and crossing of MACD lines above and below 0 carry significance.\n", + "- Crosses of MACD from below to above its signal line and from above to below its signal line carry additional significance of their own.\n", + "- As a general rule, crossing of MACD from below to above its signal line may be taken as confirmation of buy signals orignally indicated when changes in direction have taken places in MACD from down to up.\n", + "- Signal line crossing take place after MACD lines change direction " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Programming logis for MACD buy / sell signal\n", + "- Step 1: Get price data (adjusted closing price)\n", + "- Step 2: calculate STMA, LTMA, MACD\n", + "- Step 3: Get buy and sell signals" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Flow chart" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Get plugin in intellij\n", + "- diagram.net" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Sginal and trade\n", + "- Buy: 1\n", + "- sell : -1\n", + "- Hold: 0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/README.md b/README.md index aa0bff1..f6c3018 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Moving average convergence divergence indicator - Weaking trends are reflected in changes of direction of MACD reading, but clear trend reversals are not usually considered as confirmed until other indications, which will be discussed, take place. - During the course of price movement, short term moving averages will move apart (diverge) and move together (converge) with longer term moving average- hence, the indicator name "moving average convergence-divergence" -* Signal line - - The signal line is an exponential average of MACD levels, not of the price of the investment. +* Signal Line + - The signal line is an 'exponential average' of MACD levels, not of the price of the investment. - Signal lines are usually created employing 3-day to 9-day exponential averages of MACD lines. - The shorter the average the more sensitive will be the signal line. * Buy and Sell signal diff --git a/img/flow_macd_Darshan.png b/img/flow_macd_Darshan.png new file mode 100644 index 0000000..6d9f8dc Binary files /dev/null and b/img/flow_macd_Darshan.png differ