- 显示:
- 1826
- 等级:
- 已发布:
- 2015.02.06 16:44
- 已更新:
- 2016.11.22 07:33
-
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
此指标计算相对于收盘价的增长或下降百分比。它通过使用面向对象的编程编写,并可以很容易地与任何 EA 或其它指标集成。
- 此指标计算 CH%, 相对于前日收盘价的变化的百分比。
- 在图表上创建对象。此指标是以面向对象的编程风格编写。
- 它可以很容易地与任何 EA 或其它指标集成。它足以描述一个类并致其激活。
您可以估算集成到另一个指标或 EA 的代码大小。
此处有 2 行:
CChmcYZ chmc;
chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate the current day CH%
面向对象编程提供了巨大的机会,编写必要的类,然后构建...
//+------------------------------------------------------------------+ //| yuraz_mcch.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // class calculation CH% // struct SymbolStruct { bool work; string sSymbol; int y; int x; double CH; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CChmcYZ { public: SymbolStruct sSymb; color lColorSym; color lColorChPlus; color lColorChMinus; color lColorCH; int indicatorWindow; // work in the main window void CChmcYZ() { indicatorWindow=0; lColorSym=DarkBlue; // DarkTurquoise lColorCH=DarkGreen; // White; lColorChPlus = Green; // LimeGreen; lColorChMinus = FireBrick ; // Red; } // constructor void RCH(string sSym,datetime db,datetime de); // Full calculation of one pair only without display void RCHsay(string sSym,datetime db,datetime de,int X,int Y); // Full calculation of one pair and its display private: color lColor; double dClose[7000]; // array for copying maximal prices }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CChmcYZ::RCH(string sSymbol,datetime DATEBEG,datetime DATEEND) { sSymb.CH = 0; int CountBar; DATEBEG = StringToTime( TimeToString(DATEBEG,TIME_DATE)); DATEEND = StringToTime( TimeToString(DATEEND,TIME_DATE)); CountBar= CopyClose(sSymbol,PERIOD_D1,DATEEND,2,dClose); if(CountBar>=0) { if(NormalizeDouble(dClose[1],5)!=0.0 && NormalizeDouble(dClose[0],5)!=0.0) { sSymb.CH=(dClose[1]*100)/dClose[0]-100; } } } //+------------------------------------------------------------------+ //| Расчет с выводом //+------------------------------------------------------------------+ void CChmcYZ::RCHsay(string sSym,datetime db,datetime de,int XD,int YD) // Full calculation of one pair only { RCH(sSym,db,de); if(ObjectFind(indicatorWindow,"oYZ"+sSym)==-1) { ObjectCreate(indicatorWindow,"oYZ"+sSym,OBJ_LABEL,indicatorWindow,0,0); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_XDISTANCE,XD); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_YDISTANCE,YD); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_CORNER,CORNER_LEFT_UPPER); ObjectSetString(indicatorWindow,"oYZ"+sSym,OBJPROP_TEXT,sSym); ObjectSetString(indicatorWindow,"oYZ"+sSym,OBJPROP_FONT,"Arial"); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_FONTSIZE,7); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_COLOR,lColorSym); ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_SELECTABLE,true); } if(ObjectFind(indicatorWindow,"oYZ_"+sSym)==-1) { ObjectCreate(indicatorWindow,"oYZ_"+sSym,OBJ_LABEL,indicatorWindow,0,0); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+45); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_YDISTANCE,YD); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_CORNER,CORNER_LEFT_UPPER); ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT,sSym); ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_FONT,"Arial"); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_FONTSIZE,7); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_COLOR,lColorCH); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_SELECTABLE,true); } YD=YD+11; lColor=lColorCH; if(sSymb.CH>0) { lColor=lColorChPlus; ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT," "+DoubleToString(sSymb.CH,5)); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+45); } if(sSymb.CH<0) { lColor=lColorChMinus; ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT,DoubleToString(sSymb.CH,5)); ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+46); } ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_COLOR,lColor); } // // end of class // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Code where the class is used in // CChmcYZ chmc; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate current day of CH% chmc.RCHsay("AUDUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12 ); chmc.RCHsay("GBPUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*2 ); chmc.RCHsay("USDCHF",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*3 ); chmc.RCHsay("USDCAD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*4 ); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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[]) { chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate current day of CH% chmc.RCHsay("AUDUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12 ); chmc.RCHsay("GBPUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*2 ); chmc.RCHsay("USDCHF",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*3 ); chmc.RCHsay("USDCAD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*4 ); return(rates_total); } void OnDeinit() { int i=ObjectsTotal(0); // remove our objects while( i > 0 ) { if(StringSubstr(ObjectName(0,i ),0,3)=="oYZ") { ObjectDelete(0,ObjectName(0,i )); } i--; } }
由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/11347