|
截图中有两种颜色,一个红色一个绿色,两种颜色都分粗细,并且各有颜色编号。请老师帮忙把红色粗细颜色合并成同一个红色编号,比如编号0,绿色粗细柱子合并成同一个绿色编号,比如编号1. 其他逻辑框架一切不变,只合并颜色编号。再次表示感谢! //------------------------------------------------------------------ #property copyright "外汇EA之家 修复版-保留跨周期 无致命重绘" #property link "https://www.eazhijia.com" #property version "2.00" //------------------------------------------------------------------ enum enMacdType { macd_onReg, // Regular macd macd_onZlag, // Macd based on zero lag ma(已去除回溯重绘) macd_onRsi, // Macd based on Rsi macd_onMom, // Macd based on Momentum macd_onCci, // Macd based on Cci macd_onSto // Macd based on Stochastic }; #property indicator_separate_window #property indicator_buffers 7 #property indicator_color1 clrGreen #property indicator_color2 clrGreen #property indicator_color3 clrRed #property indicator_color4 clrRed #property indicator_color5 clrGray #property indicator_color6 clrGold #property indicator_color7 clrDimGray #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 1 #property indicator_width4 2 #property indicator_width5 2 #property indicator_width6 1 input string inp_Macd_Set = "MACD settings"; input int FastEMA = 12; input int SlowEMA = 26; input int SignalEMA = 9; input ENUM_APPLIED_PRICE PriceType = PRICE_CLOSE; input bool ShowHisto = true; input bool ShowOSMA = false; input int OsmaMultiplier = 2; input bool ShowLines = true; input enMacdType MACDType = macd_onReg; input int RSIPeriod = 14; input int MOMPeriod = 14; input int CCIPeriod = 10; input int StoK_period = 14; input int StoD_period = 3; input int StoSl_period = 3; input int StoPriceField = 0; input int StoMain_MaMode = 0; input int StoSig_MaMode = 0; input int baseMaPeriod = 1; input int baseMaMode = 0; input string TimeFrame = "Current time frame"; input string inp_Alert_Set = "alerts"; input bool alertsOn = true; input bool MACDalerts = true; input bool OsMAalerts = true; input bool alertsMessage = true; input bool alertsSound = true; input bool alertsEmail = false; input string soundfile = "news.wav"; input string inp_Arrow_Set = "arrows"; input bool arrowsVisible = false; input bool arrowsOnNewest = false; input string arrowsIdentifier = "macd Arrows1"; input double arrowsUpperGap = 0.5; input double arrowsLowerGap = 0.5; input color arrowsUpColor = clrBlue; input color arrowsDnColor = clrCrimson; input int arrowsUpCode = 233; input int arrowsDnCode = 234; input int arrowsUpSize = 2; input int arrowsDnSize = 2; input string note_MACD_Types_ = "0 regularMACD 1ZeroLag(无回溯) 2MACDofRSI 3MACDofMomentum 4MACDofCCI 5MACDofStochastic"; input string Sto_PriceField_ = "0Low/High 1Close/Close"; double buffer1[]; double buffer2[]; double buffer3[]; double buffer4[]; double buffer5[]; double buffer6[]; double buffer7[]; double buffer8[],slope[]; string IndicatorName; int targetTF; string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; //+------------------------------------------------------------------+ int OnInit() { int i; // 全局函数内仅声明一次循环变量i IndicatorBuffers(9); SetIndexBuffer(0,buffer1,INDICATOR_DATA); SetIndexBuffer(1,buffer2,INDICATOR_DATA); SetIndexBuffer(2,buffer3,INDICATOR_DATA); SetIndexBuffer(3,buffer4,INDICATOR_DATA); SetIndexBuffer(4,buffer5,INDICATOR_DATA); SetIndexBuffer(5,buffer6,INDICATOR_DATA); SetIndexBuffer(6,buffer7,INDICATOR_DATA); SetIndexBuffer(7,buffer8,INDICATOR_DATA); SetIndexBuffer(8,slope,INDICATOR_DATA); bool local_ShowHisto = ShowHisto; if(ShowOSMA) local_ShowHisto = true; SetIndexStyle(6,DRAW_LINE); if(local_ShowHisto) { SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexStyle(3,DRAW_HISTOGRAM); } else { SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(2,DRAW_NONE); SetIndexStyle(3,DRAW_NONE); } if(ShowLines) { SetIndexStyle(4,DRAW_LINE); SetIndexStyle(5,DRAW_LINE); } else { SetIndexStyle(4,DRAW_NONE); SetIndexStyle(5,DRAW_NONE); } targetTF = StringToTimeFrame(TimeFrame); string tfName = TimeFrameToString(targetTF); IndicatorShortName(tfName+" MACD CrossTF Fixed"); IndicatorName = WindowExpertName(); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { int i; string filter = arrowsIdentifier+":"; int len = StringLen(filter); for(i=ObjectsTotal()-1; i>=0; i--) { string n = ObjectName(i); if(StringSubstr(n,0,len)==filter) ObjectDelete(0,n); } } //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i; // 本函数仅此处声明一次i,所有循环复用 double alpha = 2.0/(1.0+SignalEMA); int start = prev_calculated>0 ? prev_calculated-1 : 0; int limit = rates_total-1; double tf_base[]; ArraySetAsSeries(tf_base,true); ArrayResize(tf_base,limit+1); for(i=limit; i>=start; i--) { datetime barTime = time[i]; int shiftTF = iBarShift(_Symbol,targetTF,barTime,false); if(shiftTF<0) { buffer8[i]=0; continue; } switch(MACDType) { case macd_onRsi: buffer8[i] = iRSI(_Symbol,targetTF,RSIPeriod,PriceType,shiftTF); break; case macd_onMom: buffer8[i] = iMomentum(_Symbol,targetTF,MOMPeriod,PriceType,shiftTF); break; case macd_onCci: buffer8[i] = iCCI(_Symbol,targetTF,CCIPeriod,PriceType,shiftTF); break; case macd_onSto: buffer8[i] = iStochastic(_Symbol,targetTF,StoK_period,StoD_period,StoSl_period,StoMain_MaMode,StoPriceField,0,shiftTF); break; default: buffer8[i] = iMA(_Symbol,targetTF,baseMaPeriod,0,baseMaMode,PriceType,shiftTF); } } for(i=limit; i>=start; i--) { buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE; buffer4[i]=EMPTY_VALUE; slope[i] = (i==limit) ? 0 : slope[i+1]; double val_prev = 0.0; if(i < limit) val_prev = ShowOSMA ? (buffer5[i+1]-buffer6[i+1])*OsmaMultiplier : buffer5[i+1]; if(MACDType == macd_onZlag) { double mf = iMAOnArray(buffer8,0,FastEMA,0,MODE_EMA,i); double ms = iMAOnArray(buffer8,0,SlowEMA,0,MODE_EMA,i); double mf_next = mf,ms_next=ms; if(i < limit) { mf_next = iMAOnArray(buffer8,0,FastEMA,0,MODE_EMA,i+1); ms_next = iMAOnArray(buffer8,0,SlowEMA,0,MODE_EMA,i+1); } buffer5[i] = (mf*2 - mf_next) - (ms*2 - ms_next); } else { buffer5[i] = iMAOnArray(buffer8,0,FastEMA,0,MODE_EMA,i) - iMAOnArray(buffer8,0,SlowEMA,0,MODE_EMA,i); buffer6[i] = buffer6[i+1] + alpha*(buffer5[i] - buffer6[i+1]); } double val = ShowOSMA ? (buffer5[i]-buffer6[i])*OsmaMultiplier : buffer5[i]; if(val>0) { if(val>val_prev) buffer2[i]=val; else buffer1[i]=val; } else { if(val<val_prev) buffer4[i]=val; else buffer3[i]=val; } if(val>val_prev) slope[i]=1; if(val<val_prev) slope[i]=-1; if(i>=2 && arrowsVisible) ManageArrow(i,time[i]); if(ShowOSMA) buffer7[i] = val; } if(alertsOn && start>=2) { int c1=1,c2=2,c3=3; if(MACDalerts) { if(buffer5[c1]>0 && buffer5[c2]<0) DoAlert("MACD线上穿0轴 多头"); if(buffer5[c1]<0 && buffer5[c2]>0) DoAlert("MACD线下穿0轴 空头"); } if(MACDalerts || OsMAalerts) { if(buffer6[c1]<buffer5[c1] && buffer6[c2]>buffer5[c2]) DoAlert("MACD金叉"); if(buffer6[c1]>buffer5[c1] && buffer6[c2]<buffer5[c2]) DoAlert("MACD死叉"); } if(OsMAalerts) { if(buffer7[c1]>buffer7[c2] && buffer7[c3]>buffer7[c2]) DoAlert("OSMA柱拐头向上"); if(buffer7[c1]<buffer7[c2] && buffer7[c3]<buffer7[c2]) DoAlert("OSMA柱拐头向下"); } } return rates_total; } //+------------------------------------------------------------------+ void ManageArrow(int i,datetime t) { string objName = arrowsIdentifier+":"+(string)t; ObjectDelete(0,objName); if(slope[i]==slope[i+1]) return; double atrVal = iATR(_Symbol,_Period,20,i); datetime drawT = t; if(arrowsOnNewest) drawT += _Period*60-1; ObjectCreate(0,objName,OBJ_ARROW,0,drawT,0); ObjectSetInteger(0,objName,OBJPROP_WIDTH,slope[i]==1 ? arrowsUpSize : arrowsDnSize); ObjectSetInteger(0,objName,OBJPROP_ARROWCODE,slope[i]==1 ? arrowsUpCode : arrowsDnCode); ObjectSetInteger(0,objName,OBJPROP_COLOR,slope[i]==1 ? arrowsUpColor : arrowsDnColor); if(slope[i]==1) ObjectSetDouble(0,objName,OBJPROP_PRICE1,Low[i] - arrowsLowerGap*atrVal); else ObjectSetDouble(0,objName,OBJPROP_PRICE1,High[i] + arrowsUpperGap*atrVal); } //+------------------------------------------------------------------+ void DoAlert(string text) { static string lastMsg=""; static datetime lastT=0; string msg = StringFormat("%s | %s",_Symbol,text); datetime now = TimeCurrent(); if(lastMsg==msg && lastT==now) return; lastMsg=msg; lastT=now; if(alertsMessage) Alert(msg); if(alertsSound) PlaySound(soundfile); if(alertsEmail) SendMail("MACD交叉信号",msg); } //+------------------------------------------------------------------+ int StringToTimeFrame(string tfStr) { int i; string s = StringUpperCase(tfStr); for(i=0; i<ArraySize(iTfTable); i++) { if(s==sTfTable[i] || s==(string)iTfTable[i]) return iTfTable[i]; } return _Period; } //+------------------------------------------------------------------+ string TimeFrameToString(int tf) { int i; for(i=0; i<ArraySize(iTfTable); i++) if(iTfTable[i]==tf) return sTfTable[i]; return ""; } //+------------------------------------------------------------------+ string StringUpperCase(string str) { int i; string res=str; int len=StringLen(str); for(i=0; i<len; i++) { int c = StringGetChar(res,i); if(c>96 && c<123) StringSetChar(res,i,c-32); } return res; } |
指标发布