根据变色均线信号交易的EA Exp_KalmanFilter.mq5-MT5 EA-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 5 > MT5 EA > 正文

根据变色均线信号交易的EA Exp_KalmanFilter.mq5

Exp_KalmanFilter EA根据变色均线指标的信号在进行自动交易。

源码:

//+------------------------------------------------------------------+
//|                                             Exp_KalmanFilter.mq5 |
//|                                Copyright  2015, Nikolay Kositsin | 
//+------------------------------------------------------------------+
#property copyright "Copyright  2015, Nikolay Kositsin"
#property link      "http://www.125808047.com"
#property version   "1.00"

#include <TradeAlgorithms.mqh>

enum Applied_price_
  {
   PRICE_CLOSE_ = 1,     //Close
   PRICE_OPEN_,          //Open
   PRICE_HIGH_,          //High
   PRICE_LOW_,           //Low
   PRICE_MEDIAN_,        //Median Price (HL/2)
   PRICE_TYPICAL_,       //Typical Price (HLC/3)
   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)
   PRICE_SIMPL_,         //Simpl Price (OC/2)
   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 
   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 
   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price 
   PRICE_DEMARK_         //Demark Price
  };

enum Signal_mode
  {
   Trend, 
   Kalman 
  };
  
input double MM=0.1;              
input MarginMode MMMode=LOT;
input int    StopLoss_=1000;
input int    TakeProfit_=2000;
input int    Deviation_=10;
input bool   BuyPosOpen=true;
input bool   SellPosOpen=true;
input bool   BuyPosClose=true;
input bool   SellPosClose=true;

input ENUM_TIMEFRAMES InpInd_Timeframe=PERIOD_H3;
input double Kf=1.0;
input Applied_price_ IPC=4; 
input Signal_mode Signalf=Kalman;
input uint SignalBar=1;

int TimeShiftSec;
int InpInd_Handle;
int min_rates_total;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   InpInd_Handle=iCustom(Symbol(),InpInd_Timeframe,"KalmanFilter",Kf,IPC,Signalf,0,0);
   if(InpInd_Handle==INVALID_HANDLE)
     {
      Print("KalmanFilter");
      return(INIT_FAILED);
     }
   TimeShiftSec=PeriodSeconds(InpInd_Timeframe);
   min_rates_total=2;
   min_rates_total+=int(3+SignalBar);
   Comment("www.125808047.com"); 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   GlobalVariableDel_(Symbol());
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(BarsCalculated(InpInd_Handle)<min_rates_total) return;
   LoadHistory(TimeCurrent()-PeriodSeconds(InpInd_Timeframe)-1,Symbol(),InpInd_Timeframe);
   double Col[3];
   static bool Recount=true;
   static bool BUY_Open=false,BUY_Close=false;
   static bool SELL_Open=false,SELL_Close=false;
   static datetime UpSignalTime,DnSignalTime;
   static CIsNewBar NB;
   if(!SignalBar || NB.IsNewBar(Symbol(),InpInd_Timeframe) || Recount)
     {
      BUY_Open=false;
      SELL_Open=false;
      BUY_Close=false;
      SELL_Close=false;
      Recount=false;
      if(CopyBuffer(InpInd_Handle,1,SignalBar,3,Col)<=0) {Recount=true; return;}
      if(Col[1]==1)
        {
         if(BuyPosOpen && Col[0]==0) BUY_Open=true;
         if(SellPosClose) SELL_Close=true;
         UpSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
      if(Col[1]==0)
        {
         if(SellPosOpen && Col[0]==1) SELL_Open=true;
         if(BuyPosClose) BUY_Close=true;
         DnSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
        }
     }
   BuyPositionClose(BUY_Close,Symbol(),Deviation_);
   SellPositionClose(SELL_Close,Symbol(),Deviation_);
   BuyPositionOpen(BUY_Open,Symbol(),UpSignalTime,MM,MMMode,Deviation_,StopLoss_,TakeProfit_);
   SellPositionOpen(SELL_Open,Symbol(),DnSignalTime,MM,MMMode,Deviation_,StopLoss_,TakeProfit_);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 根据变色均线信号交易的EA Exp_KalmanFilter.mq5
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏