MT4货币斜率强度指标CurrencySlopeStrength源码带注释,计算货币斜率方法,货币斜率指标

指标介绍
MT4货币斜率强度指标( CurrencySlopeStrength )是一款国外开源的指标,源于网上下载。您可百度下,也有很多。此指标是2012年开发的,由于时间比较久了,拿到源码时还有错误。我们修改了一些细节并做了代码注释与一点汉化。现拿出来与大家分享,一起进步!

指标使用

如上图,单一货币显示时,我们用的时间周期是H1,红线下穿绿线(通过指标中计算美元走强),表示做空信号,反之,则做多。

注: 此指标与其它指标一样都有滞后与未来预测的通病。 仅供 技术研究 不作为市场投资建议,入市有风险,投资需注重多方面考量。

也可以显示多种货币曲线,如下图:



点击下载程序与源码 文件大小:8.21 KB

必须读我.txt 策汇在线.url MQL4/ MQL4/Indicators/ MQL4/Libraries/ MQL4/Indicators/CurrencySlopeStrength.mq4

MQL4/Indicators/CurrencySlopeStrength.mq4代码片段:

 //+------------------------------------------------------------------+ //| | //| CurrencySlopeStrength.mq4 | //| 此指标是一款国外开源的EA,源于网上下载,百度下,也有很多。此指标 | //| 是2012年开发的,由于时间比较久了,拿到源码时还有错误,我们修改了 | //| 一些细节并做了代码注释与一点汉化。希望能与大家分享,一起进步! | //| http://www.fxchs.com | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2012" #property link "http://www.fxchs.com" #property version "1.0" #property description "CurrencySlopeStrength指标是一款国外开源的EA,源于网上下载,百度下,也有很多。" #property description "此指标是2012年开发的,由于时间比较久了,拿到源码时还有错误。我们修改了" #property description "一些细节并做了代码注释与一点汉化。希望能与大家分享,一起进步!" #property description " " #property description "策汇在线 http://www.fxchs.com" #property strict // 子窗口显示 #property indicator_separate_window // 绘制缓冲区 #property indicator_buffers 8 #property indicator_levelcolor MediumOrchid #define EPSILON 0.00000001 // 参与计算的货币总数 #define CURRENCYCOUNT 8 extern string gen = "---- 常规参数设置 ----"; // s0 extern int BARS = 500; // 绘制计算K线柱子数量 // bool autoSymbols = false; // 是否启用自动货币对 extern string symbolsToWeigh = "GBPNZD,EURNZD,GBPAUD,GBPCAD,GBPJPY,GBPCHF,CADJPY,EURCAD,EURAUD,USDCHF,GBPUSD,EURJPY,NZDJPY,AUDCHF,AUDJPY,USDJPY,EURUSD,NZDCHF,CADCHF,AUDNZD,NZDUSD,CHFJPY,AUDCAD,USDCAD,NZDCAD,AUDUSD,EURCHF,EURGBP"; // 货币对权重 string nonPropFont = "Microsoft YaHei"; extern bool showOnlySymbolOnChart = true; // 是否仅显示当前货币在图表上 extern string ind = "---- 指标参数设置 ----"; // s1 int HalfLength = 20; extern int Price = PRICE_WEIGHTED; // 价格计算时采用方法 extern bool autoTimeFrame = true; // 自动时间周期 //extern string ind_tf = "timeFrame M1,M5,M15,M30,H1,H4,D1,W1,MN"; extern string timeFrame = "D1"; // 时间周期 extern bool ignoreFuture = false; // 是否允许对未来的预测 extern bool showCrossAlerts = true; // 当交叉时是否启用显示背景格子警戒区 extern double differenceThreshold = 0.8; // 参考阈值Threshold extern string cur = "---- 货币参数设置 ----"; // s2 extern bool USD = true; extern bool EUR = true; extern bool GBP = true; extern bool CHF = true; extern bool JPY = true; extern bool AUD = true; extern bool CAD = true; extern bool NZD = true; extern string col = "---- 颜色参数设置 ----"; // s3 extern color Color_USD = Green; extern color Color_EUR = DeepSkyBlue; extern color Color_GBP = Red; extern color Color_CHF = Chocolate; extern color Color_JPY = FireBrick; extern color Color_AUD = DarkOrange; extern color Color_CAD = Purple; extern color Color_NZD = Teal; extern color colorWeakCross = OrangeRed; // 货币交叉信号弱颜色 extern color colorNormalCross = Gold; // 货币交叉信号中等颜色 extern color colorStrongCross = LimeGreen; // 货币交叉信号强颜色 extern color colorDifference = 0x303000; extern int Line_Thickness = 2; // 线条宽度 //////////////////////////////////////////////////////////////////////////////////////////// // 指标名称,各种名称 string indicatorName = "CurrencySlopeStrength"; string shortName; int userTimeFrame; string almostUniqueIndex; // 货币数组 double arrUSD[]; double arrEUR[]; double arrGBP[]; double arrCHF[]; double arrJPY[]; double arrAUD[]; double arrCAD[]; double arrNZD[]; // 货币总数与货币名总数 int symbolCount; string symbolNames[]; // 货币对名,直盘与交叉盘货币名数组 string currencyNames[CURRENCYCOUNT] = { "USD", "EUR", "GBP", "CHF", "JPY", "AUD", "CAD", "NZD" }; /// 强度全局变量 double currencyValues[CURRENCYCOUNT]; // Currency slope strength double currencyValuesPrior[CURRENCYCOUNT]; // Currency slope strength prior bar double currencyOccurrences[CURRENCYCOUNT]; // Holds the number of occurrences of each currency in symbols color currencyColors[CURRENCYCOUNT]; // 货币标签对象位置偏移 int verticalShift = 14; int verticalOffset = 30; int horizontalShift = 100; int horizontalOffset = 10; //////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // 介绍: CurrencySlopeStrength 修改版 // // 原理: 通过公式计算出强度画出线条 // // 来自: 策汇在线: http://www.fxchs.com // // /////////////////////////////////////////////////////////////////////////////////////////////////////////// //+------------------------------------------------------------------+ //| 初始化 | //+------------------------------------------------------------------+ int init() { HalfLength = MathMax(HalfLength,1); initSymbols(); SetIndexBuffer(0,arrUSD); SetIndexLabel(0,"USD"); currencyColors[0] = Color_USD; SetIndexBuffer(1,arrEUR); SetIndexLabel(1,"EUR"); currencyColors[1] = Color_EUR; SetIndexBuffer(2,arrGBP); SetIndexLabel(2,"GBP"); currencyColors[2] = Color_GBP; SetIndexBuffer(3,arrCHF); SetIndexLabel(3,"CHF"); currencyColors[3] = Color_CHF; SetIndexBuffer(4,arrJPY); SetIndexLabel(4,"JPY"); currencyColors[4] = Color_JPY; SetIndexBuffer(5,arrAUD); SetIndexLabel(5,"AUD"); currencyColors[5] = Color_AUD; SetIndexBuffer(6,arrCAD); SetIndexLabel(6,"CAD"); currencyColors[6] = Color_CAD; SetIndexBuffer(7,arrNZD); SetIndexLabel(7,"NZD"); currencyColors[7] = Color_NZD; SetLevelValue(0,0); string now = TimeToString(TimeCurrent()); almostUniqueIndex = StringSubstr(now, StringLen(now) - 3); shortName = indicatorName; IndicatorShortName(shortName); return(0); } //+------------------------------------------------------------------+ //| 初始化货币对数组 | //+------------------------------------------------------------------+ int initSymbols() { int i; // 获取货币对是否有后缀,获取这个后缀,方便计算,比如EURUSDc string symbolExtraChars = StringSubstr(Symbol(),6,4); // 删除空格 symbolsToWeigh = StringTrimLeft(symbolsToWeigh); symbolsToWeigh = StringTrimRight(symbolsToWeigh); // 删除尾部的逗号,防止尾部含有逗号 if (StringSubstr(symbolsToWeigh, StringLen(symbolsToWeigh)-1) != ",") { symbolsToWeigh = StringConcatenate(symbolsToWeigh, ","); } //// 如果是自动货币对 //if (autoSymbols) //{ // createSymbolNamesArray(); //} //else // 将权重货币对组拆分到数组 { i = StringFind(symbolsToWeigh, ","); while (i != -1) { int size = ArraySize(symbolNames); ArrayResize(symbolNames, size + 1); symbolNames[size] = StringConcatenate(StringSubstr(symbolsToWeigh, 0, i),symbolExtraChars); symbolsToWeigh = StringSubstr(symbolsToWeigh, i + 1); i = StringFind(symbolsToWeigh, ","); } } // 是否要将货币显示在图表上 // 简单的说就是比如附加在 EURUSD上,找出EUR、USD两个货币,显示在图表上展示 if (showOnlySymbolOnChart) { // 货币总数 symbolCount = ArraySize(symbolNames); string tempNames[]; for (i = 0; i < symbolCount; i++) { for (int j = 0; j < CURRENCYCOUNT; j++) { if (StringFind( Symbol(), currencyNames[j] ) == -1) { break; } if (StringFind(symbolNames[i], currencyNames[j] ) != -1) { int size = ArraySize(tempNames); ArrayResize(tempNames, size + 1); tempNames[size] = symbolNames[i]; break; } } } for (i = 0; i < ArraySize(tempNames); i++) { ArrayResize(symbolNames, i+1); symbolNames[i] = tempNames[i]; } } // 货币总数 symbolCount = ArraySize(symbolNames); for (i = 0; i < symbolCount; i++) { int currencyIndex = GetCurrencyIndex(StringSubstr(symbolNames[i],0,3)); currencyOccurrences[currencyIndex]++; currencyIndex = GetCurrencyIndex(StringSubstr(symbolNames[i],3,3)); currencyOccurrences[currencyIndex]++; } // 使用哪个周期来计算,默认是按日周期计算 userTimeFrame = PERIOD_D1; if (autoTimeFrame) { userTimeFrame = Period(); } else { if (timeFrame == "M1" ) userTimeFrame = PERIOD_M1; else if (timeFrame == "M5" ) userTimeFrame = PERIOD_M5; else if (timeFrame == "M15") userTimeFrame = PERIOD_M15; else if (timeFrame == "M30") userTimeFrame = PERIOD_M30; else if (timeFrame == "H1" ) userTimeFrame = PERIOD_H1; else if (timeFrame == "H4" ) userTimeFrame = PERIOD_H4; else if (timeFrame == "D1" ) userTimeFrame = PERIOD_D1; else if (timeFrame == "W1" ) userTimeFrame = PERIOD_W1; else if (timeFrame == "MN" ) userTimeFrame = PERIOD_MN1; } return 0; } //+------------------------------------------------------------------+ //| 获取货币索引 | //+------------------------------------------------------------------+ int GetCurrencyIndex(string currency) { for (int i = 0; i < CURRENCYCOUNT; i++) { if (currencyNames[i] == currency) { return(i); } } return (-1); } //+------------------------------------------------------------------+ //| createSymbolNamesArray() | //+------------------------------------------------------------------+ // // ////+------------------------------------------------------------------+ ////| 自动创建货币对数组 | ////+------------------------------------------------------------------+ //void createSymbolNamesArray() //{ // // 读取货币对列表文件 // int hFileName = FileOpenHistory ("symbols.raw", FILE_BIN|FILE_READ); // int recordCount = FileSize (hFileName) / 1936; // int counter = 0; // // for (int i = 0; i < recordCount; i++) // { // string tempSymbol = StringTrimLeft (StringTrimRight (FileReadString (hFileName, 12))); // if (MarketInfo (tempSymbol, MODE_BID) > 0 && MarketInfo (tempSymbol, MODE_TRADEALLOWED)) // { // ArrayResize(symbolNames, recordCount + 1); // symbolNames[counter] = tempSymbol; // counter++; // } // FileSeek(hFileName, 1924, SEEK_CUR); // } // FileClose(hFileName); // // return; //} //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ // // //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { int windex = WindowFind (shortName); if (windex > 0) { ObjectsDeleteAll (windex); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ // // //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { // 获取需要计算K线柱子 int counted_bars=IndicatorCounted(); int i,j,limit; // 没有任何K线就返回 if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; // 限制计算柱子数量,默认就是500根K线柱子,大于500根K线就以500为准 limit=MathMin(Bars-1,Bars-counted_bars+HalfLength); if(limit>BARS)limit=BARS; for ( i = limit; i >= 0; i-- ) { // 设置线条风格 for (j = 0; j < CURRENCYCOUNT; j++) { SetIndexStyle(j,DRAW_LINE,STYLE_SOLID,Line_Thickness,currencyColors[j]); } //int index; double diff = 0.0; ArrayInitialize(currencyValues, 0.0); CalculateCurrencySlopeStrength(userTimeFrame,i); // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"USD") != -1)) || (!showOnlySymbolOnChart && USD)) { arrUSD[i] = currencyValues[0]; if (diff ==0) diff += currencyValues[0]; else diff -= currencyValues[0]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"EUR") != -1)) || (!showOnlySymbolOnChart && EUR)) { arrEUR[i] = currencyValues[1]; if (diff == 0) diff += currencyValues[1]; else diff -= currencyValues[1]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"GBP") != -1)) || (!showOnlySymbolOnChart && GBP)) { arrGBP[i] = currencyValues[2]; if (diff == 0) diff += currencyValues[2]; else diff -= currencyValues[2]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"CHF")!= -1)) || (!showOnlySymbolOnChart && CHF)) { arrCHF[i] = currencyValues[3]; if (diff == 0) diff += currencyValues[3]; else diff -= currencyValues[3]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"JPY")!= -1)) || (!showOnlySymbolOnChart && JPY)) { arrJPY[i] = currencyValues[4]; if (diff == 0) diff += currencyValues[4]; else diff -= currencyValues[4]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"AUD" )!= -1)) || ( !showOnlySymbolOnChart && AUD ) ) { arrAUD[i] = currencyValues[5]; if (diff == 0) diff += currencyValues[5]; else diff -= currencyValues[5]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"CAD")!= -1)) || (!showOnlySymbolOnChart && CAD)) { arrCAD[i] = currencyValues[6]; if (diff == 0) diff += currencyValues[6]; else diff -= currencyValues[6]; } // // // // // if ((showOnlySymbolOnChart && (StringFind(Symbol(),"NZD")!= -1)) || (!showOnlySymbolOnChart && NZD)) { arrNZD[i] = currencyValues[7]; if (diff == 0) diff += currencyValues[7]; else diff -= currencyValues[7]; } if ( i == 1 ) { ArrayCopy(currencyValuesPrior,currencyValues); } if ( i == 0 ) { ShowCurrencyTable(); } // 呈现交易区别 if (showOnlySymbolOnChart && MathAbs(diff) > differenceThreshold) { int windex = WindowFind (shortName); string objectName = almostUniqueIndex + "_diff_" + IntegerToString(i); if ( ObjectFind (objectName) == -1) { if (ObjectCreate (objectName, OBJ_VLINE, windex, Time[i], 0)) { ObjectSet (objectName, OBJPROP_COLOR, colorDifference); ObjectSet (objectName, OBJPROP_BACK, true); ObjectSet (objectName, OBJPROP_WIDTH, 8); } } } } return(0); } //+------------------------------------------------------------------+ //| GetSlope() | //+------------------------------------------------------------------+ // // //+------------------------------------------------------------------+ //| 根据货币对获取斜率 | //+------------------------------------------------------------------+ double GetSlope(string symbol, int tf, int shift) { double dblTma, dblPrev; double gadblSlope = 0.0; // 真实波幅的移动平均值 double atr = iATR(symbol,tf,100,shift+10) / 10; if (atr != 0) { // 如果允许预测的话 if (ignoreFuture) { dblTma = calcTmaTrue( symbol, tf, shift); dblPrev = calcPrevTrue(symbol, tf, shift); } else { dblTma = calcTma(symbol,tf,shift); dblPrev = calcTma(symbol,tf,shift+1); } // 斜率 = (均值 - 之前的均值) / 波幅 gadblSlope = (dblTma - dblPrev) / atr; } return (gadblSlope); } //+------------------------------------------------------------------+ //| 计算真实的均值 | //+------------------------------------------------------------------+ double calcTma(string symbol, int tf, int shift) { int jnx, knx; double dblSum = (HalfLength+1) * iMA(symbol,tf,1,0,MODE_SMA,Price,shift); double dblSumw = (HalfLength+1); for (jnx = 1, knx = HalfLength; jnx <= HalfLength; jnx++, knx--) { dblSum += iMA(symbol,tf,1,0,MODE_SMA,Price,shift+jnx)*knx; dblSumw += knx; if (jnx <= shift) { dblSum += iMA(symbol,tf,1,0,MODE_SMA,Price,shift-jnx)*knx; dblSumw += knx; } } return (dblSum/dblSumw); } //+------------------------------------------------------------------+ //| 计算线性平均值MA | //+------------------------------------------------------------------+ double calcTmaTrue(string symbol, int tf, int inx ) { return (iMA(symbol,tf,HalfLength,0, MODE_LWMA, PRICE_CLOSE,inx)); } //+------------------------------------------------------------------+ //| 预测下一个值 | //+------------------------------------------------------------------+ double calcPrevTrue( string symbol, int tf, int inx ) { double dblSum = (HalfLength+1) * iMA(symbol,tf,1,0,MODE_SMA,Price,inx+1); double dblSumw = (HalfLength+1); int jnx, knx; dblSum += HalfLength * iMA(symbol,tf,1,0,MODE_SMA,Price,inx); dblSumw += HalfLength; for ( jnx = 1, knx = HalfLength; jnx <= HalfLength; jnx++, knx-- ) { dblSum += iMA(symbol,tf,1,0,MODE_SMA,Price,inx+1+jnx ) * knx; dblSumw += knx; } return (dblSum/dblSumw); } //+------------------------------------------------------------------+ //| 计算货币斜率强度 | //+------------------------------------------------------------------+ void CalculateCurrencySlopeStrength(int tf, int shift) { int i; for ( i = 0; i < symbolCount; i++) { double slope = GetSlope(symbolNames[i], tf, shift); currencyValues[GetCurrencyIndex(StringSubstr(symbolNames[i],0,3))] += slope; currencyValues[GetCurrencyIndex(StringSubstr(symbolNames[i],3,3))] -= slope; } for (i = 0; i < CURRENCYCOUNT; i++) { currencyValues[i] /= currencyOccurrences[i]; } } //+------------------------------------------------------------------+ //| 显示货币表 | //+------------------------------------------------------------------+ void ShowCurrencyTable() { int i; int tempValue; string objectName; string showText; color showColor; int windex = WindowFind (shortName); // 是否仅显示当前货币在图表上,比如EURUSD,显示 EUR USD两个值 if (showOnlySymbolOnChart) { for (i = 0; i < 2; i++) { int index = GetCurrencyIndex(StringSubstr(Symbol(),3*i,3)); objectName = almostUniqueIndex + "_css_obj_column_currency_" + IntegerToString(i); if (ObjectFind (objectName) == -1) { if (ObjectCreate (objectName, OBJ_LABEL, windex, 0, 0)) { ObjectSet (objectName, OBJPROP_CORNER,1); ObjectSet (objectName, OBJPROP_XDISTANCE, horizontalShift * 0 + horizontalOffset + 70); ObjectSet (objectName, OBJPROP_YDISTANCE, (verticalShift + 6) * i + verticalOffset - 18); } } ObjectSetText (objectName, currencyNames[index], 14, nonPropFont, currencyColors[index]); objectName = almostUniqueIndex + "_css_obj_column_value_" + IntegerToString(i); if (ObjectFind (objectName ) == -1) { if (ObjectCreate (objectName, OBJ_LABEL, windex, 0, 0)) { ObjectSet (objectName, OBJPROP_CORNER, 1); ObjectSet (objectName, OBJPROP_XDISTANCE, horizontalShift * 0 + horizontalOffset - 65 + 70); ObjectSet (objectName, OBJPROP_YDISTANCE, (verticalShift + 6) * i + verticalOffset - 18); } } showText = RightAlign(DoubleToStr(currencyValues[index], 2), 5); ObjectSetText (objectName, showText, 14, nonPropFont, currencyColors[index]); } objectName = almostUniqueIndex + "_css_obj_column_currency_3"; if (ObjectFind ( objectName ) == -1) { if (ObjectCreate (objectName, OBJ_LABEL, windex, 0, 0)) { ObjectSet (objectName, OBJPROP_CORNER, 1); ObjectSet (objectName, OBJPROP_XDISTANCE, horizontalShift * 0 + horizontalOffset + 5); ObjectSet (objectName, OBJPROP_YDISTANCE, (verticalShift + 6) * 2 + verticalOffset - 10); } } showText = "threshold = " + DoubleToStr(differenceThreshold, 1); ObjectSetText (objectName, showText, 8, nonPropFont, Yellow); } else { // 显示7个货币对的强度信息,然后画对应的曲线 double tempCurrencyValues[CURRENCYCOUNT][3]; for (i = 0; i < CURRENCYCOUNT; i++) { tempCurrencyValues[i][0] = currencyValues[i]; tempCurrencyValues[i][1] = NormalizeDouble(currencyValuesPrior[i], 2); tempCurrencyValues[i][2] = i; } ArraySort(tempCurrencyValues, WHOLE_ARRAY, 0, MODE_DESCEND); int horizontalOffsetCross = 0; for (i = 0; i < CURRENCYCOUNT; i++) { objectName = almostUniqueIndex + "_css_obj_column_currency_" + IntegerToString(i); if (ObjectFind (objectName ) == -1) { if (ObjectCreate (objectName, OBJ_LABEL, windex, 0, 0)) { ObjectSet (objectName, OBJPROP_CORNER, 1); ObjectSet (objectName, OBJPROP_XDISTANCE, horizontalShift * 0 + horizontalOffset + 150); ObjectSet (objectName, OBJPROP_YDISTANCE, (verticalShift + 2) * i + verticalOffset - 18); } } tempValue = (int)tempCurrencyValues[i][2]; showText = currencyNames[tempValue]; ObjectSetText (objectName, showText, 12, nonPropFont, currencyColors[tempValue]); objectName = almostUniqueIndex + "_css_obj_column_value_" + IntegerToString(i); if (ObjectFind ( objectName ) == -1) { if (ObjectCreate (objectName, OBJ_LABEL, windex, 0, 0)) { ObjectSet (objectName, OBJPROP_CORNER, 1 ); ObjectSet (objectName, OBJPROP_XDISTANCE, horizontalShift * 0 + horizontalOffset - 55 + 150); ObjectSet (objectName, OBJPROP_YDISTANCE, (verticalShift + 2) * i + verticalOffset - 18); } } showText = RightAlign(DoubleToStr(tempCurrencyValues[i][0], 2), 5); ObjectSetText (objectName, showText, 12, nonPropFont, currencyColors[tempValue]); objectName = almostUniqueIndex + "_css_obj_column_cross_" + IntegerToString(i); if (showCrossAlerts && i < CURRENCYCOUNT-1 && NormalizeDouble(tempCurrencyValues[i][0],2) > NormalizeDouble(tempCurrencyValues[i+1][0],2) && tempCurrencyValues[i][1] < tempCurrencyValues[i+1][1]) { showColor = colorStrongCross; if (tempCurrencyValues[i][0] > 0.8 || tempCurrencyValues[i+1][0] < -0.8 ) { showColor = colorWeakCross; } else if (tempCurrencyValues[i][0] > 0.4 || tempCurrencyValues[i+1][0] < -0.4 ) { showColor = colorNormalCross; } DrawCell(windex,objectName,horizontalShift*0 + horizontalOffset + 88 + horizontalOffsetCross, (verticalShift + 2) * i + verticalOffset - 20, 1, 27, showColor ); if (horizontalOffsetCross == 0) { horizontalOffsetCross = -4; } else { horizontalOffsetCross = 0; } } else { DeleteCell(objectName); horizontalOffsetCross = 0; } } } } //+------------------------------------------------------------------+ //| 字符串右对齐 | //+------------------------------------------------------------------+ string RightAlign (string text, int length = 10, int trailing_spaces = 0) { string text_aligned = text; for (int i = 0; i < length - StringLen (text) - trailing_spaces; i++) { text_aligned = " " + text_aligned; } return (text_aligned); } //+------------------------------------------------------------------+ //| 画背景格子 | //+------------------------------------------------------------------+ void DrawCell (int nWindow, string nCellName, double nX, double nY, double nWidth, double nHeight, color nColor) { double iHeight, iWidth, iXSpace; int iSquares, i; if (nWidth > nHeight) { iSquares = (int)MathCeil (nWidth / nHeight); iHeight = MathRound((nHeight *100) / 77); iWidth = MathRound((nWidth * 100) / 77); iXSpace = iWidth / iSquares - ((iHeight / (9 - (nHeight / 100))) * 2); for (i = 0; i < iSquares; i++) { ObjectCreate (nCellName + IntegerToString(i), OBJ_LABEL, nWindow, 0, 0); ObjectSetText (nCellName + IntegerToString(i), CharToStr ( 110 ), (int)iHeight, "Wingdings", nColor); ObjectSet (nCellName + IntegerToString(i), OBJPROP_CORNER, 1); ObjectSet (nCellName + IntegerToString(i), OBJPROP_XDISTANCE, nX + iXSpace * i); ObjectSet (nCellName + IntegerToString(i), OBJPROP_YDISTANCE, nY); ObjectSet (nCellName + IntegerToString(i), OBJPROP_BACK, true); } } else { iSquares = (int)MathCeil (nHeight / nWidth); iHeight = MathRound ((nHeight* 100) / 77); iWidth = MathRound ((nWidth * 100) / 77); iXSpace = iHeight / iSquares - ((iWidth / (9 - (nWidth / 100))) * 2); for ( i = 0; i < iSquares; i++ ) { ObjectCreate (nCellName + IntegerToString(i), OBJ_LABEL, nWindow, 0, 0); ObjectSetText (nCellName + IntegerToString(i), CharToStr (110), (int)iWidth, "Wingdings", nColor); ObjectSet (nCellName + IntegerToString(i), OBJPROP_CORNER, 1); ObjectSet (nCellName + IntegerToString(i), OBJPROP_XDISTANCE, nX); ObjectSet (nCellName + IntegerToString(i), OBJPROP_YDISTANCE, nY + iXSpace * i); ObjectSet (nCellName + IntegerToString(i), OBJPROP_BACK, true); } } } //+------------------------------------------------------------------+ //| 删除背景格子 | //+------------------------------------------------------------------+ void DeleteCell(string name) { int square = 0; while (ObjectFind(name + IntegerToString(square)) > -1) { ObjectDelete(name + IntegerToString(square)); square++; } } //+------------------------------------------------------------------+