//+----------------------------------------------- -------------------+ //| 版權資訊 //+----------------------------------------------- -------------------+ #property copyright "Copyright 2012, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //+----------------------------------------------- -------------------+ //| EA初始化1 //+----------------------------------------------- -------------------+ #include<Trade\Trade.mqh>//包含執行的交易庫 #include<Trade\PositionInfo.mqh>//包含部位的資訊庫 CTrade m_Trade; //執行交易的結構體 CPositionInfo m_Position; //獲取持倉信息的結構體 //歐元 660 60 10 1% //英鎊 320 180 10 1% //澳幣 1160 160 10 1% //日幣 360 130 10 1% input int 長w=15 , 中w=9 ,短w=7 ; input double 停利率=0.01,i目前成本=0; input double 下單量=0.01; input int 偏差值=99,睡覺 =999; input int 順勢=1; // 順勢 : 1 ; 逆勢 : -1 double 目前成本=i目前成本,目前獲利; input int 已有部位=0; //已有部位 : 多填1,空填-1,空手填0 int iMyPositions=已有部位,pMyPositions=已有部位; bool SendNotification,Redone,可下單,強平; int CLocation,pCLocation,SLocation,pSLocation; int CheckNewBar,Kcount,pKcount; double wr長,wr中,wr短,Close_buf[],High_buf[],Low_buf[]; long Week_buf[],Day_buf[]; //存儲每個柱形收盤價格的動態數組 input int 下單週=0; // 下單週:1~5;0等於全部 看看第幾週最差 input int 可下單倒數日 = 6; // 可下單倒數日:1~6;6等於全部 input int 不下單倒數日 = 0; // 不下單倒數日:1~5;0等於全部 int 週數,倒數日; #property indicator_separate_window #property indicator_minimum -100 #property indicator_maximum 0 #property indicator_buffers 3 #property indicator_plots 3 #property indicator_level1 -50.0 #property indicator_levelstyle STYLE_DOT //點點分界 #property indicator_levelcolor Silver //Blue #property indicator_levelwidth 1 //--- plot Label1 #property indicator_label1 "標籤一" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "標籤l2" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDarkOrange #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Label3 #property indicator_label3 "標籤l3" #property indicator_type3 DRAW_LINE #property indicator_color3 clrYellow #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- indicator buffers double ExtWPRBuffer1[]; // Label1Buffer[]; double ExtWPRBuffer2[]; // Label2Buffer[]; double ExtWPRBuffer3[]; // Label3Buffer[]; //--- global variables int 短參數=短w; int 中參數=中w; int 長參數=長w; int OnCalculate(const int rates_total, // size of input time series const int prev_calculated, // bars handled in previous call const datetime &Time[], const double &Open[], const double &High[], const double &Low[], const double &Close[], const long &TickVolume[], const long &Volume[], const int &Spread[]) { //--- start working int i短=prev_calculated-1; int i中=prev_calculated-1; int i長=prev_calculated-1; //---- insufficient data if(rates_total<短參數) return(0); if(rates_total<中參數) return(0); if(rates_total<長參數) return(0); //--- correct position if(i短<短參數-1) i短=短參數-1; if(i中<中參數-1) i中=中參數-1; if(i長<長參數-1) i長=長參數-1; //--- main cycle 1 while(i短<rates_total) { //--- calculate maximum High double dMaxHigh=MaxAr(High,短參數,i短); //--- calculate minimum Low double dMinLow=MinAr(Low,短參數,i短); //--- calculate WPR if(dMaxHigh!=dMinLow) ExtWPRBuffer1[i短]=-(dMaxHigh-Close[i短])*100/(dMaxHigh-dMinLow); else ExtWPRBuffer1[i短]=ExtWPRBuffer1[i短-1]; //--- increment i for next iteration i短++; } //--- return new prev_calculated value // return(rates_total); //--- main cycle 2 while(i中<rates_total) { //--- calculate maximum High double dMaxHigh=MaxAr(High,中參數,i中); //--- calculate minimum Low double dMinLow=MinAr(Low,中參數,i中); //--- calculate WPR if(dMaxHigh!=dMinLow) ExtWPRBuffer2[i中]=-(dMaxHigh-Close[i中])*100/(dMaxHigh-dMinLow); else ExtWPRBuffer2[i中]=ExtWPRBuffer2[i中-1]; //--- increment i for next iteration i中++; } //--- return new prev_calculated value //return(rates_total); //--- main cycle 3 while(i長<rates_total) { //--- calculate maximum High double dMaxHigh=MaxAr(High,長參數,i長); //--- calculate minimum Low double dMinLow=MinAr(Low,長參數,i長); //--- calculate WPR if(dMaxHigh!=dMinLow) ExtWPRBuffer3[i長]=-(dMaxHigh-Close[i長])*100/(dMaxHigh-dMinLow); else ExtWPRBuffer3[i長]=ExtWPRBuffer3[i長-1]; //--- increment i for next iteration i長++; } //--- return new prev_calculated value return(rates_total); } // OnCalculate //+----------------------------------------------- -------------------+ //| EA初始化2 //+----------------------------------------------- -------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtWPRBuffer1,INDICATOR_DATA); SetIndexBuffer(1,ExtWPRBuffer2,INDICATOR_DATA); SetIndexBuffer(2,ExtWPRBuffer3,INDICATOR_DATA); //--- digits IndicatorSetInteger(INDICATOR_DIGITS,1); //小數點 ArraySetAsSeries (Close_buf,true ); //將Close_buf數組的索引設置為時間序列 ArraySetAsSeries (High_buf, true ); //將Close_buf數組的索引設置為時間序列 ArraySetAsSeries (Low_buf,true); //將Close_buf數組的索引設置為時間序列 return(0); //返回0,初始化結束 //+------------------------------------------------------------------+ //| Williams’ Percent Range | //+------------------------------------------------------------------+ } //+----------------------------------------------- -------------------+ //| EA去初始化函數| //+----------------------------------------------- -------------------+ void OnDeinit(const int reason) { ArrayFree(Close_buf); ArrayFree(High_buf);ArrayFree(Low_buf); //釋放動態數組 } //+----------------------------------------------- -------------------+ //| EA的tick函數| //+----------------------------------------------- -------------------+ void OnTick() { int err4=0,err5=0,err6=0; //用於存儲價格圖表處理結果的變量 err4= CopyClose (Symbol(),Period(),0 , 2 ,Close_buf); //將價格數據拷貝到動態數組,以進一步處理 err5= CopyHigh (Symbol(),Period(),0 , 2 ,High_buf); //將價格數據拷貝到動態數組,以進一步處理 err6= CopyLow (Symbol(),Period(),0 , 2 ,Low_buf); //將價格數據拷貝到動態數組,以進一步處理 if( err4<0 || err5<0 || err6<0) //如果出錯 { Print("Failed to copy data from buffer or price "); //打印相關錯誤信息到日誌文件 return; //並退出函數 } Kcount=SeriesInfoInteger(Symbol(),Period(),SERIES_BARS_COUNT); if(Kcount==0) pKcount=Kcount; if(pKcount==pKcount) CheckNewBar=0; if(pKcount!= Kcount) CheckNewBar=1; //確認新k棒給1 if(CheckNewBar==1) //////////////新Bar後動作 超大if { int UPindex長=iHighest(Symbol(),Period(),MODE_HIGH,長w,1); double h長=iHigh(Symbol(),Period(),UPindex長); int Downindex長=iLowest(Symbol(),Period(),MODE_LOW,長w,1); double l長=iLow(Symbol(),Period(),Downindex長); int UPindex中=iHighest(Symbol(),Period(),MODE_HIGH,中w,1); double h中=iHigh(Symbol(),Period(),UPindex中); int Downindex中=iLowest(Symbol(),Period(),MODE_LOW,中w,1); double l中=iLow(Symbol(),Period(),Downindex中); int UPindex短=iHighest(Symbol(),Period(),MODE_HIGH,短w,1); double h短=iHigh(Symbol(),Period(),UPindex短); int Downindex短=iLowest(Symbol(),Period(),MODE_LOW,短w,1); double l短=iLow(Symbol(),Period(),Downindex短); wr長 = -1*( h長 - Close_buf[1] ) / ( h長 - l長 ); wr中 = -1*( h中 - Close_buf[1] ) / ( h中 - l中 ); wr短 = -1*( h短 - Close_buf[1] ) / ( h短 - l短 ); CLocation = 0 ; if(-0.5 <= wr長) CLocation= 1*順勢+CLocation; if(-0.5 <= wr中) CLocation= 1*順勢+CLocation; if(-0.5 <= wr短) CLocation= 1*順勢+CLocation; if(-0.5 > wr長) CLocation=-1*順勢+CLocation; if(-0.5 > wr中) CLocation=-1*順勢+CLocation; if(-0.5 > wr短) CLocation=-1*順勢+CLocation; // SLocation=0; // if(Close_buf[ 1 ]>wMA3_buf[ 1 ]) SLocation= 1*順勢+SLocation; // if(Close_buf[ 1 ]<wMA3_buf[ 1 ]) SLocation=-1*順勢+SLocation; //input int 下單週 = 0 ; // 下單週:1~5;0等於全部 看看第幾週最差 //input int 可下單倒數日 = 6; // 可下單倒數日:1~6;6等於全部 //input int 不下單倒數日 = 0; // 不下單倒數日:1~5;0等於全部 //做多_平空單 if(iMyPositions<0 && CLocation==3 && pCLocation<=2 ) { Redone=true; do { m_Trade.PositionClose(Symbol(),偏差值); Sleep(睡覺); Print(Symbol(),"做多_平空單 = ",m_Trade.ResultRetcode()+". Code description: ",m_Trade.ResultRetcodeDescription()); if(m_Trade.ResultRetcode()==10009) Redone=false; if(m_Trade.ResultRetcode()==10036) Redone=false; } while(Redone); iMyPositions=0; } //做多_淨多單 Week_buf Day_buf 下單週 可下單倒數日 不下單倒數日 if(iMyPositions==0 && CLocation==3 && pCLocation<=2 ) { Redone=true; do { m_Trade.Buy(下單量,Symbol(),0.0,0.0,0.0,"做多_淨多單");Sleep(睡覺); Print(Symbol(),"做多_淨多單 = ",m_Trade.ResultRetcode()+". Code description: ",m_Trade.ResultRetcodeDescription()); } while(m_Trade.ResultRetcode()!=10009); iMyPositions=1; 目前成本=Close_buf[1]; } //做空_平多單 if(iMyPositions>0 && CLocation==-3 && pCLocation>=-2 ) { Redone=true;do { m_Trade.PositionClose(Symbol(),偏差值);Sleep(睡覺); Print(Symbol(),"做空_平多單 = ",m_Trade.ResultRetcode()+". Code description: ",m_Trade.ResultRetcodeDescription()); if(m_Trade.ResultRetcode()==10009) Redone = false; if(m_Trade.ResultRetcode()==10036) Redone = false; } while(Redone); iMyPositions=0; } //做空_淨空單 if(iMyPositions==0 && CLocation==-3 && pCLocation>=-2 ) { Redone=true;do { m_Trade.Sell(下單量,Symbol(),0.0,0.0,0.0,"做空_淨空單"); Sleep(睡覺); Print(Symbol(),"做空_淨空單 = ",m_Trade.ResultRetcode()+". Code description: ",m_Trade.ResultRetcodeDescription()); } while(m_Trade.ResultRetcode()!=10009); iMyPositions=-1; 目前成本=Close_buf[1]; } //停利 }//////////////新Bar 超大if pCLocation = CLocation; pSLocation = SLocation; pMyPositions=iMyPositions; pKcount=Kcount; } //+----------------------------------------------- -------------------+ //+------------------------------------------------------------------+ //| Maximum High 可共用函數? | //+------------------------------------------------------------------+ double MaxAr(const double &array[],int period,int cur_position) { double Highest=array[cur_position]; for(int i=cur_position-1;i>cur_position-period;i--) { if(Highest<array[i]) Highest=array[i]; } return(Highest); } //+------------------------------------------------------------------+ //| Minimum Low 可共用函數? | //+------------------------------------------------------------------+ double MinAr(const double &array[],int period,int cur_position) { double Lowest=array[cur_position]; for(int i=cur_position-1;i>cur_position-period;i--) { if(Lowest>array[i]) Lowest=array[i]; } return(Lowest); } //+------------------------------------------------------------------+

- www.mql5.com
不能放在一起。
MT5的应用程序分三类: EA,Indicator,Script
每类应用程序必须有一个主函数且只能有一个主函数。
EA的主函数是OnTick(),Indicator的主函数是OnCalculate(),Script的主函数是OnTick().
EA与Script的区别是,EA可以一直执行OnTick(), 而Script则是只执行一次OnTick(),程序就退出。
請問 EA 要如何改變句柄的顏色呢?
例如目前的三條均線都是紅色
想要讓其中一條變成黃色
可以嗎?
EA改变句柄的颜色?你这句话表达的有问题。
句柄(handle)是指标(indicator)的一个数字标识(是一个整数),用该数字来代表指标。
当我们在EA中调用 iCustom(... some indiactor name...)时,就创建了该indicator的一个标识(handle),创建handle成功后,
当EA中需要获取该指标的数据时,通过CopyBuffer(handle...) 就能获得数据。
EA中被创建的指标的数据的实时更新由系统负责。
因此,我们在EA中需要用到某个指标时,只需要用iCustom(...some indicator name...) 来创建该指标的一个句柄即可,通过CopyBuffer(handle...) 获得数据,而不需要在EA中实现指标的代码。
你要想改变线的颜色,应该在指标的代码中修改。
你想在EA中用到该指标,你只需要在EA中创建该指标的handle,然后指标就在EA中自动运行了(由系统负责)。
建议你去 codebase 先学习下如何编写指标,编写EA对你来说太复杂了,很多基本概念你都没理清。
你想在EA中用到该指标,你只需要在EA中创建该指标的handle,然后指标就在EA中自动运行了(由系统负责)。
可以舉簡單例子嗎? 例如有一個"低低指標"會回傳前n天的最低點
要如何在EA 引用"低低指標" 然後站上做多 跌破做空?
你想在EA中用到该指标,你只需要在EA中创建该指标的handle,然后指标就在EA中自动运行了(由系统负责)。
可以舉簡單例子嗎? 例如有一個"低低指標"會回傳前n天的最低點
要如何在EA 引用"低低指標" 然後站上做多 跌破做空?
你想在EA中用到该指标,你只需要在EA中创建该指标的handle,然后指标就在EA中自动运行了(由系统负责)。
这句话的意思是指标的计算是系统负责,但那是指标并不会显示在图表上。
你要想指标显示在图表,你得把指标加载到图表。
我免费给你写个EA?这是不可能的。
你愿意付费,那里有很多人给你写:https://www.mql5.com/en/job

- www.mql5.com
你想在EA中用到该指标,你只需要在EA中创建该指标的handle,然后指标就在EA中自动运行了(由系统负责)。
这句话的意思是指标的计算是系统负责,但那是指标并不会显示在图表上。
你要想指标显示在图表,你得把指标加载到图表。
我免费给你写个EA?这是不可能的。
你愿意付费,那里有很多人给你写:https://www.mql5.com/en/job
恩恩 謝謝
請問指標跟EA程式碼合併成新EA放在一起 是不能自動交易的?
我是用三個威廉50來判斷多空