[MT4指标]四色均线指标
主图指标
mt4指标类型:趋势指标
是否能用在mt4手机版上:否
是否含有未来函数:无
一个指标里显示四条均线 简化添加指标的流程
//+------------------------------------------------------------------+
//| Four_MA_Ind.mq4 |
//| Copyright ? 2006, Robert Hill |
//| Written by Robert Hill with addition of LSMA MA_Mode 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright ? 2006, Robert Hill)"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Yellow
#property indicator_color4 Aqua
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
extern int MA_Period1 = 5;
extern int MA_Mode1 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int PriceMode1 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Period2 = 10;
extern int MA_Mode2 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int PriceMode2 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Period3 = 20;
extern int MA_Mode3 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int PriceMode3 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Period4 = 30;
extern int MA_Mode4 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int PriceMode4 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
double MA1;
double MA2;
double MA3;
double MA4;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
SetIndexDrawBegin(0,MA_Period4);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,MA1) &&
!SetIndexBuffer(1,MA2) &&
!SetIndexBuffer(2,MA3) &&
!SetIndexBuffer(3,MA4))
Print("cannot set indicator buffers!");
//---- initialization done
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| LSMA with PriceMode |
//| PrMode 0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, |
//| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4 |
//+------------------------------------------------------------------+
double LSMA(int Rperiod, int prMode, int shift)
{
int i;
double sum, pr;
int length;
double lengthvar;
double tmp;
double wt;
length = Rperiod;
sum = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
switch (prMode)
{
case 0: pr = Close[length-i+shift];break;
case 1: pr = Open[length-i+shift];break;
case 2: pr = High[length-i+shift];break;
case 3: pr = Low[length-i+shift];break;
case 4: pr = (High[length-i+shift] + Low[length-i+shift])/2;break;
case 5: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift])/3;break;
case 6: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift] + Close[length-i+shift])/4;break;
}
tmp = ( i - lengthvar)*pr;
sum+=tmp;
}
wt = sum*6/(length*(length+1));
return(wt);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit, i;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i = 0; i <= limit; i++) {
if (MA_Mode1 == 4)
{
MA1 = LSMA(MA_Period1, PriceMode1, i);
}
else
{
MA1 = iMA(NULL, 0, MA_Period1, 0, MA_Mode1, PriceMode1, i);
}
if (MA_Mode2 == 4)
{
MA2 = LSMA(MA_Period2, PriceMode2, i);
}
else
{
MA2 = iMA(NULL, 0, MA_Period2, 0, MA_Mode2, PriceMode2, i);
}
if (MA_Mode3 == 4)
{
MA3 = LSMA(MA_Period3, PriceMode3, i);
}
else
{
MA3 = iMA(NULL, 0, MA_Period3, 0, MA_Mode3, PriceMode3, i);
}
if (MA_Mode4 == 4)
{
MA4 = LSMA(MA_Period4, PriceMode4, i);
}
else
{
MA4 = iMA(NULL, 0, MA_Period4, 0, MA_Mode4, PriceMode4, i);
}
}
return(0);
}
Four_MA_Ind.jpg
发表于:2014-03-31 11:36只看该作者
2楼
谢谢分享
韬客社区www.talkfx.co
发表于:2014-04-11 11:45只看该作者
3楼
谢谢分享。。。。
韬客社区www.talkfx.co
发表于:2015-04-20 11:56只看该作者
4楼
缺钱,灌水赚通宝,谢谢分享!!
韬客社区www.talkfx.co
发表于:2015-04-21 15:43只看该作者
5楼
直接用MT4上的4条均线不行啊?
韬客社区www.talkfx.co
发表于:2015-05-26 05:05只看该作者
6楼
看看再说
韬客社区www.talkfx.co
发表于:2015-05-26 05:07只看该作者
7楼
看看再说
韬客社区www.talkfx.co
发表于:2015-06-07 04:50只看该作者
8楼
代码的渴求
韬客社区www.talkfx.co
发表于:2015-06-25 04:26只看该作者
9楼
谢谢分享~!!!
韬客社区www.talkfx.co
发表于:2015-06-27 03:05只看该作者
10楼
谢谢分享~!!!
韬客社区www.talkfx.co
发表于:2015-06-30 03:04只看该作者
11楼
惺惺相惜
韬客社区www.talkfx.co
发表于:2015-07-01 10:47只看该作者
12楼
感谢分享
韬客社区www.talkfx.co
发表于:2015-07-06 05:45只看该作者
13楼
啊啊啊啊啊啊啊啊啊啊
发表于:2015-07-06 12:06只看该作者
14楼
谢谢分享。。。。
韬客社区www.talkfx.co
发表于:2015-12-03 01:47只看该作者
16楼
老大,在不?
我用的是香港第一金的mt4
为嘛复制代码后生成的指标不能用?
然后,想请教你个事,方便的话,回复我一下呗,谢谢了!
韬客社区www.talkfx.co
发表于:2015-12-03 01:54只看该作者
17楼
大佬啊,刚刚导入了,但是只有一根红线,没有四根,不知道为什么
韬客社区www.talkfx.co
发表于:2015-12-30 09:32只看该作者
18楼
感谢您分享
韬客社区www.talkfx.co
发表于:2016-02-25 02:27只看该作者
19楼
韬客社区www.talkfx.co
发表于:2016-03-04 06:06只看该作者
20楼
顶
韬客社区www.talkfx.co