完整EA:Nerve Knife.ex4黄金交易策略_黄金趋势ea-CSDN博客
当大小趋势相同行情走向也相同,就会开仓做顺势单,并会顺势追单,以达到快速止盈平仓的效果。大趋势追求稳定,小趋势追求敏捷,行情走向比小趋势更敏捷,所以做单原则是以大趋势方向为准,小趋势作为行情判断的预判,行情不对先冷静。代码如下:
大趋势升:M30 heiken ashi smoothed 指标为蓝色、macd 柱位于正区间、macd柱小于信号线
大趋势降:M30 heiken ashi smoothed 指标为红色、macd 柱位于负区间、macd柱大于信号线
小趋势升:M5 heiken ashi smoothed 指标为蓝色、macd柱小于信号线
小趋势降:M5 heiken ashi smoothed 指标为红色、macd柱大于信号线
其它情况为趋势弱。代码如下:
int checkHASDown(int timeFrame, int offset)
{int MaPeriod = 6; double maOpen1=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_OPEN,0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_OPEN,1); double maClose1=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_CLOSE,0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_CLOSE,1) ; double maLow1=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_LOW,0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_LOW,1); double maHigh1=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_HIGH,0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_HIGH,1);double maOpen2=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_OPEN,1 + 0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_OPEN,1 + 1); double maClose2=timeFrame != big_timeframe ? iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_CLOSE,1 + 0) : iMA(NULL,timeFrame,MaPeriod,0,MODE_SMMA,PRICE_CLOSE,1 + 1);double haOpen1 = (maOpen2 + maClose2) / 2;double haClose1 = (maOpen1 + maClose1 + maLow1 + maHigh1) / 4; double MacdCurrent0=timeFrame != big_timeframe ? iMACD(NULL,timeFrame,12,26,9,PRICE_CLOSE,MODE_MAIN,0) : iMACD(NULL,timeFrame,12,26,9,PRICE_CLOSE,MODE_MAIN,1);double SignalCurrent0=timeFrame != big_timeframe ? iMACD(NULL,timeFrame,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0) : iMACD(NULL,timeFrame,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);double haHigh1=MathMax(maHigh1,MathMax(haOpen1,haClose1)); double haLow1=MathMin(maLow1,MathMin(haOpen1,haClose1));//6条30分k线内有一条出现8000点差判断为unknown,避免影响指标判断。修正:应该在线区间内才不做单。if(timeFrame == big_timeframe){for(int i=0;i<6;i++){int index = iHighest(Symbol(),big_timeframe,MODE_HIGH,1,i);double highPrice = iHigh(Symbol(), big_timeframe, index);index = iLowest(Symbol(),big_timeframe,MODE_LOW,1,i);double lowPrice = iLow(Symbol(), big_timeframe, index);if(highPrice - lowPrice > 8 && ((Ask > lowPrice && Ask < highPrice) || (Bid < highPrice && Bid > lowPrice)))//if(highPrice - lowPrice > 8){printfPro("6条30分k线内出现过一条8刀的k线,并且当前行情在此区间内,趋势的指标无法判断" , true);return UNKNOWN;}}}//增长无趋势时间,降低转换向前落单风险if(haOpen1>haClose1 && MacdCurrent0 > SignalCurrent0){//printfPro(timeFrame + ":" + 1, 1);return UNKNOWN;}if(haOpen1<haClose1 && MacdCurrent0 < SignalCurrent0){//printfPro(timeFrame + ":" + 1, 2);return UNKNOWN;}//使用MACD的辅助判断小趋势响应快,大趋势保持稳定if(haOpen1>haClose1 && ((timeFrame != big_timeframe) ? (MacdCurrent0 < SignalCurrent0) : MacdCurrent0 < 0)){//printfPro(timeFrame + ":" + 1, 3);return DOWN; //下降}if (haClose1 > haOpen1 && ((timeFrame != big_timeframe) ? (MacdCurrent0 > SignalCurrent0) : MacdCurrent0 > 0)){//printfPro(timeFrame + ":" + 1, 4);return UP;//上升}//printfPro(timeFrame + ":" + 1, 5);return UNKNOWN;}
另外,如下图,关注实时价格变动,如反向突破马上叫停开仓