发表于:2007-12-02 12:56只看该作者
2楼
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_color3 Green
extern int 显示均线=18;
extern int 条件均线1=10;
extern int 条件均线2=20;
extern int 条件均线3=40;
extern int 条件均线4=80;
extern int 条件均线5=160;
extern int 条件均线6=320;
double duo;
double kong;
double qita;
int init()
{
SetIndexBuffer(0,duo);
SetIndexBuffer(1,kong);
SetIndexBuffer(2,qita);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
IndicatorDigits(Digits);
return(0);
}
bool duotou(int t)
{
if( iMA(NULL,0,条件均线1,0,MODE_SMA,PRICE_CLOSE,t)>=iMA(NULL,0,条件均线2,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线2,0,MODE_SMA,PRICE_CLOSE,t)>=iMA(NULL,0,条件均线3,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线3,0,MODE_SMA,PRICE_CLOSE,t)>=iMA(NULL,0,条件均线4,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线4,0,MODE_SMA,PRICE_CLOSE,t)>=iMA(NULL,0,条件均线5,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线5,0,MODE_SMA,PRICE_CLOSE,t)>=iMA(NULL,0,条件均线6,0,MODE_SMA,PRICE_CLOSE,t)
) return(true);
else return(false);
}
bool kongtou(int t)
{
if( iMA(NULL,0,条件均线1,0,MODE_SMA,PRICE_CLOSE,t)<=iMA(NULL,0,条件均线2,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线2,0,MODE_SMA,PRICE_CLOSE,t)<=iMA(NULL,0,条件均线3,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线3,0,MODE_SMA,PRICE_CLOSE,t)<=iMA(NULL,0,条件均线4,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线4,0,MODE_SMA,PRICE_CLOSE,t)<=iMA(NULL,0,条件均线5,0,MODE_SMA,PRICE_CLOSE,t)
&& iMA(NULL,0,条件均线5,0,MODE_SMA,PRICE_CLOSE,t)<=iMA(NULL,0,条件均线6,0,MODE_SMA,PRICE_CLOSE,t)
) return(true);
else return(false);
}
int start()
{
double temp0,temp1;
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
duo=EMPTY_VALUE;
kong=EMPTY_VALUE;
qita=EMPTY_VALUE;
temp0=iMA(NULL,0,显示均线,0,MODE_SMA,PRICE_CLOSE,i);
temp1=iMA(NULL,0,显示均线,0,MODE_SMA,PRICE_CLOSE,i+1);
if(duotou(i)) {duo=temp0; if(!duotou(i+1)) duo[i+1]=temp1;}
else if(kongtou(i)) {kong=temp0; if(!kongtou(i+1)) kong[i+1]=temp1;}
else {qita=temp0; if( duotou(i+1) || kong[i+1]) qita[i+1]=temp1;}
}
return(0);
}bian.gif
顺势
发表于:2007-12-02 13:30只看该作者
3楼
上图中,
当均线系统多头排列时,此均线为红色
当均线系统空头排列时,此均线为黄色
当均线系统既不是多头也不是空头时,此均线为绿色
个人觉得 这样的颜色转换条件太多,失去了渐变过程,一下子全部变红色,一下子又全部变绿色,变化太突然
下面这样是不是会好一些:
当5天金叉10天时,5天线变红色,死叉则5天线变绿色,10天线不变色
当10金叉20时,10天线变红色,死叉则10天线变绿色,20天线不变色
以下类推。。。
源码如下#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Yellow
extern int 均线=18;
double duo;
double kong;
int init()
{
SetIndexBuffer(0,duo);
SetIndexBuffer(1,kong);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(0,均线);
SetIndexDrawBegin(1,均线);
IndicatorDigits(Digits);
return(0);
}
int start()
{
double temp0,temp1;
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
duo=EMPTY_VALUE;
kong=EMPTY_VALUE;
temp0=iMA(NULL,0,均线,0,MODE_SMA,PRICE_CLOSE,i);
temp1=iMA(NULL,0,均线,0,MODE_SMA,PRICE_CLOSE,i+1);
if(iMA(NULL,0,均线,0,MODE_SMA,PRICE_CLOSE,i)>=iMA(NULL,0,均线*2,0,MODE_SMA,PRICE_CLOSE,i))
{duo=temp0; duo[i+1]=temp1;}
else {kong=temp0; kong[i+1]=temp1;}
}
return(0);
}
[ 本帖最后由 秃鹫 于 2007-12-2 21:40 编辑 ]
顺势
4楼
谢谢秃鹫老师!不过我想在蜡烛线变颜色是怎样写?
韬客社区www.talkfx.co
发表于:2007-12-03 10:22只看该作者
5楼
6楼
称呼“老师”当之无愧! 下面是我收集蜡烛线变颜色的指标!老师看看能有用?
韬客社区www.talkfx.co
7楼
//+------------------------------------------------------------------+
//| Stoch Candle OverBought-Sold.mq4 |
//| Copyright ?2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| StochCandles.mq4 |
//| Colored Candles, based on Stochastic Signal. |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, Christof Risch (iya)"
#property link "http://www.forexfactory.com/showthread.php?t=13321"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 White
#property indicator_color2 Lime
#property indicator_color3 White
#property indicator_color4 Lime
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
#property indicator_color5 Orange
#property indicator_color6 Orange
#property indicator_color7 Orange
#property indicator_color8 Orange
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 3
#property indicator_width8 3
//---- stoch settings
extern double Stoch_K = 100.0,
Stoch_D = 3.0,
Stoch_Slowing = 3.0,
Upper_Level = 80,
Lower_Level = 20;
//---- input parameters
extern color BarUp = White,
BarDown = Lime,
BullCandle = White,
BearCandle = Lime,
BarUp2 = Orange,
BarDown2 = Orange,
MedCandle = Orange,
MedCandle2 = Orange;
extern int BarWidth = 1,
CandleWidth = 3,
BarWidth2 = 1,
CandleWidth2 = 3;
//---- buffers
double Buffer1;
double Buffer2;
double Buffer3;
double Buffer4;
double Buffer5;
double Buffer6;
double Buffer7;
double Buffer8;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth,BarUp);
SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth,BarDown);
SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth,BullCandle);
SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth,BearCandle);
SetIndexBuffer(0, Buffer1);
SetIndexBuffer(1, Buffer2);
SetIndexBuffer(2, Buffer3);
SetIndexBuffer(3, Buffer4);
SetIndexStyle(4,DRAW_HISTOGRAM,0,BarWidth2,BarUp2);
SetIndexStyle(5,DRAW_HISTOGRAM,0,BarWidth2,BarDown2);
SetIndexStyle(6,DRAW_HISTOGRAM,0,CandleWidth2,MedCandle );
SetIndexStyle(7,DRAW_HISTOGRAM,0,CandleWidth2,MedCandle2 );
SetIndexBuffer(4, Buffer5);
SetIndexBuffer(5, Buffer6);
SetIndexBuffer(6, Buffer7);
SetIndexBuffer(7, Buffer8);
return(0);
}
//+------------------------------------------------------------------+
double Stoch_Main (int i = 0) {return(iStochastic(NULL,0,Stoch_K,Stoch_D,Stoch_Slowing,MODE_SMA,0,MODE_MAIN, i));}
//double Stoch_Signal (int i = 0) {return(iStochastic(NULL,0,Stoch_K,Stoch_D,Stoch_Slowing,MODE_SMA,0,MODE_SIGNAL,i));}
//+------------------------------------------------------------------+
bool IsMedCandle(int i = 0)
{
if(i>=Bars)
return(false);
if(High==Low)
return(IsMedCandle(i+1));
return(Buffer5==High && Buffer6==Low);
}
//+------------------------------------------------------------------+
void SetBullCandle(int i = 0)
{
Buffer1 = High;
Buffer2 = Low;
Buffer3 = MathMax(Open,Close);
Buffer4 = MathMin(Open,Close);
}
//+------------------------------------------------------------------+
void SetBearCandle(int i = 0)
{
Buffer1 = Low;
Buffer2 = High;
Buffer3 = MathMin(Open,Close);
Buffer4 = MathMax(Open,Close);
}
//+------------------------------------------------------------------+
void SetMedCandle(int i = 0)
{
Buffer5 = Low;
Buffer6 = High;
Buffer7 = MathMin(Open,Close);
Buffer8 = MathMax(Open,Close);
}
//+------------------------------------------------------------------+
void SetMedCandle2(int i = 0)
{
Buffer5 = Low;
Buffer6 = High;
Buffer7 = MathMin(Open,Close);
Buffer8 = MathMax(Open,Close);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
for(int i = MathMax(Bars-1-IndicatorCounted(),1); i >= 0; i--)
{
// bool bull = Close > Open,
// bear = Close < Open;
double stochMain = Stoch_Main(i),
Med = Stoch_Main(i);
bool bull = (stochMain < Lower_Level),
bear = (stochMain > Upper_Level );
Med = ((stochMain < Upper_Level )&&(stochMain > 20));
if(!bull && !bear && !Med)
{
bull = (stochMain < Lower_Level);
bear = (stochMain > Upper_Level );
Med = ((stochMain < Upper_Level )&&(stochMain > Lower_Level));
}
if (bull) SetBullCandle(i);
else if (bear) SetBearCandle(i);
else if (IsMedCandle(i+1)) SetMedCandle(i);
else SetMedCandle2(i);
}
return(0);
}
//+------------------------------------------------------------------+
韬客社区www.talkfx.co
9楼
我看不懂?能解释吗?
韬客社区www.talkfx.co
发表于:2009-06-16 13:21只看该作者
10楼
绿色好像是在出,白线好像可以买了。但在2008年10份的白线出现时却不能买(4h)
韬客社区www.talkfx.co
发表于:2009-07-05 12:15只看该作者
11楼
这是根据KD线指标的多空转换编写,替代原来K线的指标。这指标俺也有,但只有两色。另外还有根据ADX交叉变色的。
韬客社区www.talkfx.co
发表于:2009-07-05 12:22只看该作者
12楼
我也想请老师帮个忙,能不能把lsma均线指标编成在附图栏里显示的光谱指标。或者是主图表中的变色K线。源码附录在后面。谢谢老师。
韬客社区www.talkfx.co
发表于:2009-07-05 12:22只看该作者
13楼
#property copyright "Copyright ?2005"
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DarkKhaki
#property indicator_color2 SeaGreen
#property indicator_color3 Maroon
//---- buffers
double ExtMapBuffer1;
double ExtMapBuffer2;
double ExtMapBuffer3;
int width;
extern int Rperiod = 25;
extern int Draw4HowLongg = 5000;
int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum;
int length;
double lengthvar;
double tmp ;
double wt;
int c;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(0,ExtMapBuffer3);
SetIndexBuffer(3,sum);
SetIndexBuffer(4,wt);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
//---- initialization done
return(0);
}
int start()
{ Draw4HowLong = Bars-Rperiod - 5;
length = Rperiod;
loopbegin = Draw4HowLong - length - 1;
for(shift = loopbegin; shift >= 0; shift--)
{
sum[1] = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
tmp = ( i - lengthvar)*Close[length-i+shift];
sum[1]+=tmp;
}
wt[shift] = sum[1]*6/(length*(length+1));
//========== COLOR CODING ===========================================
ExtMapBuffer3[shift] = wt[shift]; //red
ExtMapBuffer2[shift] = wt[shift]; //green
ExtMapBuffer1[shift] = wt[shift]; //yellow
// for(c=loopbegin;c==shift;c++)
// {
if (wt[shift+1] > wt[shift])
{
ExtMapBuffer2[shift+1] = EMPTY_VALUE;
// ObjectCreate("smiley_face", OBJ_ARROW, 0, Time[shift], Low[shift]-Point*20);
// Print("time= ",Time[shift]);
// ObjectSet("smiley_face", OBJPROP_ARROWCODE, 242);
// ObjectSet("smiley_face", OBJPROP_COLOR , Red);
// ObjectSet("smiley_face", OBJPROP_WIDTH , 1);
// ObjectsRedraw();
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else if (wt[shift+1] < wt[shift])
{
ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else
{
ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+
韬客社区www.talkfx.co