如何在交易平台中使用 MA指标
1.使用MA,通常是对不同的参数同时使用,而不是仅仅用一个。按各人的不同,参数的选择上会有些差别,但是都包括长期、中期和短期三类MA。长、中、短是相对的,可以自己确定。在国内股市中,常利用的移动平均线组合为5日(黄色)、10日(紫色)、30日(绿色)、60日(白色)、120日(蓝色)、250日(红色)线。其中250日长期移动平均线作为牛市与熊市的分界线。
MA指标 买卖时机
MA指标 拓展知识
MA指标 MA
计算公式: MA = (C1+C2+C3+C4+C5+. +Cn)/n C 为收盘价,n 为移动平均周期数例如,现货黄金的 5 日移动平均价格计算方法为: MA 5 = (前四天收盘价+前三天收盘价+前天收盘价+昨天收盘价+今天收盘价)/5
【量化课堂】MACD均线择时策略
> MACD思想————均线位置与买卖时机判断
MACD是从双指数移动平均线发展而来的,由快的指数移动平均线(EMA12)减去慢的指数移动平均线(EMA26)得到快线DIF,再用2×(快线DIF-DEA)得到MACD柱。MACD的意义和双移动平均线相似,即由快、慢均线的离散、聚合来显示当前的多空状态和股价可能的发展变化趋势并对买进、卖出时机作出研判,但MACD阅读起来更方便。
总体而言:
当MACD从负数转向正数,即买入信号
当MACD从正数转向负数,即卖出信号
当MACD以大角度变化,表示快的移动平均线和慢的移动平均线的差距非常迅速的拉开,代表了一个市场大趋势的转变
> DIF与DEA金叉的使用
当白线即短期快线DIF向上穿过黄色的长期慢线DEA时,即“快线高于慢线”,属于做多金叉信号。然而实际中需要进行“金叉+零轴”的综合考虑。
> 当零轴之下出现金叉时,股价属于弱势市场,金叉为弱势金叉,股价极有可能短期弱势反弹或暂时止跌后再度夭折,一般没有做多价值。
> 当零轴之上发生金叉时,股价属于强势市场,金叉为强势金叉,股价后市成功惯性上攻的概率较高。若零轴之上出现二次金叉信号时,又称零上二次红金叉,属于股价强势中的强势,此时跟进做多,股价往往容易出现加速上涨。属于短线极佳买点。
> DIF与DEA死叉的使用
当白线即短期快线DIF向下穿过黄色的长期慢线DEA时,即“快线低于慢线”,属于做空死叉信号。死叉同样需要结合零轴。
> 当零轴之上出现死叉时,一般认为是股价上升趋势途中的短暂回调,后市股价仍有再次走强的可能。
> 当零轴之下发生死叉时,一般认为是股价下跌趋势途中的继续回调,后市股价惯性下跌的概率较高,尤其是MACD零轴之下出现二次死叉时,股价更容易出现加速下跌行情,所以零轴之下,无论出现的是一次死叉或二次死叉,投资者都应当空仓观望,静观其变。
策略内容
了解了MACD的基本情况,我们就能够制定本次利用技术指标构建的策略内容。
翻译成计算机语言即:
1.运用 get_fundalmentals 函数查询相关财务数据并筛选出符合条件的股票
2.运用 talib 读取MACD相关指标数值
3.利用 if 条件语句以及 and 、 or 逻辑语句进行买入卖出条件设置
2 基本框架构建
在之前的教程中,我们基本上已经整理出交易之前策略构成的基本框架。下面我们对这一内容再次进行细化:
首先是 initialize() 函数的设置。这里我们沿用之前的做法,将其分为多个自定义函数的形式:
3 MACD数据读取
根据我们策略的内容,我们采用的思路是:筛选出股票池中质量较高的股票-->查询MACD指数-->买入卖出条件
再次复习我们熟悉的选股方法:财务指标。这里我们挑选出符合:
100.3,净资产收益率(roe)>15,净利润环比增长率>0.3,并按照市净率进行升序排列,取前五十只。
对于筛选出来的股票依次读取MACD数据。这里就需要用到 talib 库中 MACD 函数。TA-Lib中文全称为技术分析库,是一个广泛用在程序化交易中进行金融市场数据的技术分析的函数库。它提供了多种技术分析的函数,包含多种指标如ADX, MACD, RSI, 布林轨道等等,可以极大地方便我们量化投资中编程工作。
传入函数的三个参数分别为短线周期、长线周期以及MACD的移动平滑周期。这里我们使用最常用的(12,26,9)组合。 MACD() 函数返回值共有三个,分别为DIF,DEA和MACD
> 答疑与延伸:
> -为什么要通过macd_tmp[0]来读取数据? 因为MACD返回的是一个包括三个元素的序列array,和从list中取元素类似,我们通过在其后加上0的方式分别取第一个元素和第二个元素。
> -为什么要选取300日的历史数据? MACD存在一个问题,即若选取时间较短,则可能出现不收敛的状况,因此这里我们选取300日的数据。
4 买入卖出条件设置
策略中我们要判断长线和短线的位置问题。这里我们做一些简化,判断当日和三日前的MACD正负情况。
当日MACD为正且三日前MACD为负-->金叉形成 买入
当日MACD为负且三日前MACD为正-->死叉形成 卖出
将股票代码通过 append() 函数放在相应的买卖列表当中。
当对筛选后保留的股票进行循环之后,符合条件的股票已经被放入买入或卖出列表中。下面查看当前所持有的股票,如果在卖出列表当中则全部卖出,不是则保留,并将股票代码放入hold[]列表中
这是我见过最全最易懂的策略指南:指数移动平均线交易策略
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.
What are Moving averages?
Moving averages are among the most widely used and efficient indicators for technical analysis. Traders of all levels determine long term trends using this tool. We’ll cover how to define a trend, how to implement this indicator for support and resistance levels, and how to use it as trade entry and exit signal.
What are Moving Averages?
Moving averages (MA) indicate the average trend within the chosen period, smooth out price action and filter out the noise. They are formed using the average closing price over a set number of periods. For example, a ten-day simple moving average is a total of the closing prices during a period of ten days divided by ten.
The most commonly used moving averages are:
Simple Moving Average (SMA), which indicates the average movement of price during a particular time period;
Exponential Moving Average (EMA), which is similar to SMA, but applies a greater weight to more recent prices.
Adding Moving Averages to your chart in MetaTrader 4
You can add moving averages to your chart simply by clicking the ‘indicators list’ icon in the toolbar and selecting ‘moving average’. From there you can choose the period and the type of MA you want to work with. If you’re using multiple moving averages you can change the color in order to identify them easily.
Simple Moving Averages vs. Exponential Moving Averages
SMA are slower than EMA in responding to price action. Consequently, they indicate trends or trend reversals 如何在交易平台中使用 MA指标 more slowly, but are less prone to false signals. EMA are better at catching trends early, though they will give you more false signals during consolidation periods.
Using several types of moving averages will give you a broader outlook. For instance, a trader might choose longer period SMA to help understand the broader trend, and shorter period EMA for entry signals.
SMA may 如何在交易平台中使用 MA指标 better identify support and resistance levels since they reflect a balanced average of prices over a 如何在交易平台中使用 MA指标 set time period.
How to determine a trend using MA?
When a price action remains above a moving average, it signals that the price has an uptrend. Conversely, if a price action stays below the MA it indicates a downtrend.
Using several MA simultaneously can be beneficial in determining a trend. Make sure the MA 如何在交易平台中使用 MA指标 lines are set in the correct order (from fastest to slowest in an uptrend, from slowest to fastest in a downtrend) to confirm that you are in a strong uptrend or downtrend.
Moving Average Crossovers
MA crossovers help to determine when a new trend starts and when an existing one is about to reverse.
Upward momentum is confirmed with a bullish crossover, when short-term MA crosse above longer-term MA. This can be called a ‘Golden Cross’. Downward momentum is confirmed 如何在交易平台中使用 MA指标 with a bearish crossover, when short-term MA cross below longer-term MA, also known as a ‘Death 如何在交易平台中使用 MA指标 Cross’. Short term MA can be used for 如何在交易平台中使用 MA指标 intraday trading, for instance, EMA with 5 and 10 periods.
Longer-term traders might prefer SMA crossovers with 50 and 200 periods.
On one hand, MA crossovers tend to work well in trending markets, while on the other, they can be worthless in sideways or consolidating markets.
Moving Averages as Dynamic Support and Resistance Levels
MA can also be used as support in an uptrend and resistance in a downtrend. For example, a short-term uptrend might find support near the 21-day EMA, while a long-term uptrend might find support near the 200-day SMA.
50 and 200-period SMA are mostly followed on the daily chart and often represent key support and resistance levels. Keep in mind that the levels are not exact, and MA more often represent areas of support and resistance. Levels are also dynamic, as they are constantly changing based on recent price action.
MA is a multi-faceted indicator that can help you to define a trend, support and resistance. It can also show when a new trend starts and when a trend is about to reverse. Set different periods of MA to determine what works best for your trading strategy.