想要找一些外汇MT4的指标,附有源码,交易的时候可以辅助,编写指标的时候可以参考学习,想改善的时候,可以编辑。做外汇的朋友都不会只关注一个品种,想同时监控多个品种的趋势,打开N个交易品种的K线图眼都花了。下方是100个交易品种(一般建议交易者关注十个以内就够了)1小时的Price、Spread、ATR、VOL、RSI、Stoch、SDX、Pivots、MA监控数据。 string INDI_NAME="MPSCN-";
input int TimerInterval=60; //Update interval (secs)input int FontSize=10; //Font Sizeinput string FontName="Calibri"; //Font Nameinput int ColumnHeight=50; //Max symbols per columninput string Group0; //---------------------------------------------------input bool ShowPrice=true; //Show Priceinput string Group01; //---------------------------------------------------input bool ShowSpread=true; //Show Spreadinput string Group1; //---------------------------------------------------input bool ShowATR=true; //Show ATRinput ENUM_TIMEFRAMES AtrTimeframe=PERIOD_H1; //ATR Timeframeinput int AtrPeriod=20; //ATR Periodinput string Group2; //---------------------------------------------------input bool ShowVolume=true; //Show Volumeinput ENUM_TIMEFRAMES VolumeTimeframe=PERIOD_H1; //Volume Timeframeinput int VolumePeriod=60; //Volume Periodinput string Group3; //---------------------------------------------------input bool ShowRsi=true; //Show RSIinput ENUM_TIMEFRAMES RsiTimeframe=PERIOD_H1; //RSI Timeframeinput int RsiPeriod=14; //RSI Periodinput int RsiUpperLevel = 75; //RSI Upper Levelinput int RsiLowerLevel = 25; //RSI Lower Levelinput string Group4; //---------------------------------------------------input bool ShowStoch=true; //Show Stochasticinput ENUM_TIMEFRAMES StochTimeframe=PERIOD_H1; //Stoch Timeframeinput int StochK = 5; //%K periodinput int StochD = 3; //%D periodinput int StochSlow = 3;//Slowinginput ENUM_MA_METHOD StochMethod=MODE_SMA; //MA Methodinput ENUM_STO_PRICE StochPrice=STO_LOWHIGH; //Price Fieldinput int StochUpperLevel = 80; //Stoch Upper Levelinput int StochLowerLevel = 20; //Stoch Lower Levelinput string Group5; //---------------------------------------------------input bool ShowAdx=true; //Show ADXinput ENUM_TIMEFRAMES AdxTimeframe=PERIOD_H1; //ADX Timeframeinput int AdxPeriod=20; //ADX Periodinput ENUM_APPLIED_PRICE AdxAppliedPrice=PRICE_CLOSE; //ADX Applied Priceinput string Group6; //---------------------------------------------------input bool ShowPivots=true; //Show Pivotsinput string Group7; //---------------------------------------------------input bool ShowMA=true; //Show MAinput ENUM_TIMEFRAMES MATimeframe=PERIOD_H1; //MA Timeframeinput int MAPeriod=60; //MA Periodinput ENUM_MA_METHOD MAMethod=MODE_SMA; //MA Methodinput ENUM_APPLIED_PRICE MAAppliedPrice=PRICE_CLOSE; //MA Appliedint GUIHeaderXOffset = 20;int GUIHeaderYOffset = 0;int ListXMultiplier = 10;int ListYMultiplier = 15;//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+//--- indicator buffers mapping ChartColorSet(CHART_COLOR_BACKGROUND,clrBlack); ChartColorSet(CHART_COLOR_FOREGROUND,clrWhite); ChartColorSet(CHART_COLOR_GRID,clrNONE); ChartColorSet(CHART_COLOR_VOLUME,clrNONE); ChartColorSet(CHART_COLOR_CHART_UP,clrNONE); ChartColorSet(CHART_COLOR_CHART_DOWN,clrNONE); ChartColorSet(CHART_COLOR_CHART_LINE,clrNONE); ChartColorSet(CHART_COLOR_CANDLE_BULL,clrNONE); ChartColorSet(CHART_COLOR_CANDLE_BEAR,clrNONE); ChartColorSet(CHART_COLOR_BID,clrNONE); ChartColorSet(CHART_COLOR_ASK,clrNONE); ChartColorSet(CHART_COLOR_LAST,clrNONE); ChartColorSet(CHART_COLOR_STOP_LEVEL,clrNONE); ChartModeSet(CHART_LINE);//+-------------------------------------------------------------------------------------------+ ObjectsDeleteAll(ChartID(),INDI_NAME);//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int OnCalculate(const int rates_total, const int prev_calculated, const long &tick_volume[],//--- return value of prev_calculated for next call//+------------------------------------------------------------------+//+------------------------------------------------------------------+ if(TimeSeconds(TimeCurrent())%TimerInterval==0)//+------------------------------------------------------------------+//+------------------------------------------------------------------+long getAvgVolume(string symbol,int period) for(int i=0; i<period; i++) volume_total+=iVolume(symbol,VolumeTimeframe,i); return volume_total / period;//+------------------------------------------------------------------+//+------------------------------------------------------------------+double getRange(string symbol,int period) int DataPeriod=PERIOD_D1; int DataBar=iBarShift(symbol,DataPeriod,Time[0]); double range = iHigh(symbol, period, DataBar) - iLow(symbol, period, DataBar); double point = MarketInfo(symbol, MODE_POINT); if(point > 0) return (NormalizeDouble(range / point, 0));//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawMissingTime(int deltaY=0) int x=GUIXOffset+ListXOffset,y=20; DrawLabel("CurTimeLbl",x,y,"Server Time:"+TimeToStr(TimeCurrent(),TIME_MINUTES),FontSize,FontName,clrWhite); DrawLabel("LocalTimeLbl",x+=150,y,"Local Time:"+TimeToStr(TimeLocal(),TIME_MINUTES),FontSize,FontName,clrWhite); DrawLabel("TimeLeftLbl",x+=150,y,"Time until Candle close:",FontSize,FontName,clrWhite); DrawTimeMissingColum(PERIOD_M1,x+=150,y); DrawTimeMissingColum(PERIOD_M5,x+=GUIColOffset,y); DrawTimeMissingColum(PERIOD_M15,x+=GUIColOffset,y,30); DrawTimeMissingColum(PERIOD_H1,x+=GUIColOffset, y); DrawTimeMissingColum(PERIOD_H4,x+=GUIColOffset, y); DrawTimeMissingColum(PERIOD_D1,x+=GUIColOffset, y);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawTimeMissingColum(int period,int x,int y,int dxOffset=25) string periodStr= GetPeriodStr(period); string timeLeft = GetTimeToClose(period, timeColor); DrawLabel("TimeLeftLbl_"+periodStr,dx,y,periodStr+":",FontSize,FontName,clrWhite); DrawLabel("TimeLeftVal_"+periodStr,dx+=dxOffset,y,timeLeft,FontSize,FontName,timeColor);//+------------------------------------------------------------------+//+------------------------------------------------------------------+string GetTimeToClose(int period,color &timeColor) int periodMinutes = periodToMinutes(period); int shift = periodMinutes*60; int currentTime = (int)TimeCurrent(); int localTime = (int)TimeLocal(); int barTime = (int)iTime(period); int diff = (int)MathMax(round((currentTime-localTime)/3600.0)*3600,-24*3600); string time=getTime(barTime+periodMinutes*60-localTime-diff,timeColor); time=(TerminalInfoInteger(TERMINAL_CONNECTED)) ? time : time+" x";//+------------------------------------------------------------------+void DrawLabel(string name,int x,int y,string label,int size=9,string font="Arial",color clr=DimGray,string tooltip="") ObjectCreate(name,OBJ_LABEL,0,0,0); ObjectSetText(name,label,size,font,clr); ObjectSet(name,OBJPROP_CORNER,0); ObjectSet(name,OBJPROP_XDISTANCE,x); ObjectSet(name,OBJPROP_YDISTANCE,y); ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);//ObjectSet(name, OBJPROP_ANCHOR, 0);//ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);//ObjectSet(name, OBJPROP_SELECTABLE, 0);//+------------------------------------------------------------------+//| The function sets chart background color. |//+------------------------------------------------------------------+bool ChartColorSet(int prop_id,const color clr,const long chart_ID=0)//--- reset the error value//--- set the chart background color if(!ChartSetInteger(chart_ID,prop_id,clr)) //--- display the error message in Experts journal Print(__FUNCTION__+", Error Code = ",GetLastError());//--- successful execution//+------------------------------------------------------------------+//| Set chart display type (candlesticks, bars or |//+------------------------------------------------------------------+bool ChartModeSet(const long value,const long chart_ID=0)//--- reset the error value if(!ChartSetInteger(chart_ID,CHART_MODE,value)) //--- display the error message in Experts journal Print(__FUNCTION__+", Error Code = ",GetLastError());//--- successful execution//+------------------------------------------------------------------+//+------------------------------------------------------------------+ Print("=============>DrawScanner"); for(int x=0; x<SymbolsTotal(true); x++) DrawSymbol(SymbolName(x,true),x);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawSymbol(string symbolName,int symbolIdx) int yMult = (int)fmod(symbolIdx, ColumnHeight); int xMult = (symbolIdx/ColumnHeight); int x= (GUIXOffset+GUIHeaderXOffset) + (NumVisibleColumns()*GUIColOffset)*xMult; int y= GUIYOffset+ListYOffset + ListYMultiplier * yMult; int colOffset=GUIColOffset; DrawSymbolColumn(symbolName,x,y,symbolName,FontSize,FontName); DrawPriceColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawSpreadColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawRangeColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawVolumeColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawRsiColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawStochColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawAdxColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawPivotsColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName); DrawMAColumn(symbolName,x+=colOffset,y,symbolName,FontSize,FontName);//+------------------------------------------------------------------+//+------------------------------------------------------------------+double getPoint(string symbol) return MarketInfo(symbol,MODE_POINT);//+------------------------------------------------------------------+//+------------------------------------------------------------------+double getModifier(string symbol) int digits=(int)MarketInfo(symbol,MODE_DIGITS); if(digits==3 || digits==5)//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawRsiColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") double rsi=NormalizeDouble(iRSI(symbolName,RsiTimeframe,RsiPeriod,PRICE_CLOSE,0),0); string tooltip=symbolName+"\n.: "+GetPeriodStr(RsiTimeframe)+" RSI ("+IntegerToString(RsiPeriod)+"):.\nCurrent ("+DoubleToStr(rsi,1)+")"; DrawLabel("rsi_"+symbolName,x,y,DoubleToStr(rsi,1),fontSize,fontName,GetRsiColor(rsi),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawStochColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") double stoch=iStochastic(symbolName,StochTimeframe,StochK,StochD,StochSlow,StochMethod,StochPrice,MODE_MAIN,0); string tooltip=symbolName+"\n.: "+GetPeriodStr(StochTimeframe)+" Stoch :.\nCurrent ("+DoubleToStr(stoch,1)+")"; DrawLabel("stoch_"+symbolName,x,y,DoubleToStr(stoch,1),fontSize,fontName,GetStochColor(stoch),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawAdxColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") double adx=iADX(symbolName,AdxTimeframe,AdxPeriod,AdxAppliedPrice,MODE_MAIN,0); string tooltip=symbolName+"\n.: "+GetPeriodStr(AdxTimeframe)+" ADX ("+IntegerToString(AdxPeriod)+"):.\nCurrent ("+DoubleToStr(adx,1)+")"; DrawLabel("adx_"+symbolName,x,y,GetAdxStr(adx),fontSize,fontName,GetAdxColor(adx),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+string GetAdxStr(double adx) return "Very Strong Trend";//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetAdxColor(double adx)//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawPriceColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") int digits=(int)MarketInfo(symbolName,MODE_DIGITS); double vAsk=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits); double vBid=NormalizeDouble(MarketInfo(symbolName,MODE_BID),digits); double vSpread=NormalizeDouble(MarketInfo(symbolName,MODE_SPREAD),digits); string tooltip=symbolName+"\n.: Price :.\nAsk: "+(string)vAsk+"\nBid: "+(string)vBid+"\nSpread: "+(string)vSpread; DrawLabel("price_"+symbolName,x,y,(string)vBid+":"+ IntegerToString(x),fontSize,fontName,clrWhite,tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawSpreadColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") int digits=(int)MarketInfo(symbolName,MODE_DIGITS); double vAsk=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits); double vBid=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits); double vSpread=NormalizeDouble(MarketInfo(symbolName,MODE_SPREAD),digits); string tooltip=symbolName+"\n.: SPREAD :.\nAsk: "+(string)vAsk+"\nBid: "+(string)vBid+"\nSpread: "+(string)vSpread; DrawLabel("spread_"+symbolName,x,y,(string)vSpread,fontSize,fontName,clrWhite,tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawPivotsColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") int digits=(int)MarketInfo(symbolName,MODE_DIGITS); double vAsk=MarketInfo(symbolName,MODE_BID); double pivot=NormalizeDouble((GetPivotValue(symbolName,PERIOD_D1)),digits); pivots[1]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,1)),digits); pivots[2]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,2)),digits); pivots[3]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,3)),digits); pivots[4]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,1)),digits); pivots[5]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,2)),digits); pivots[6]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,3)),digits); int closestIdx=GetClosestPivot(vAsk,pivots); double pips=vAsk-pivots[closestIdx]; string tooltip=symbolName+"\n.: Daily Pivots :.\nPP: "+DoubleToStr(pivots[0])+"\nR1: "+DoubleToStr(pivots[1]); string pivotText=GetPivotDirection(pips)+" "+GetPivotStr(closestIdx); DrawLabel("pivots_"+symbolName,x,y,pivotText,fontSize,fontName,GetPivotColor(closestIdx),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawMAColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") double ma=iMA(symbolName,MATimeframe,MAPeriod,0,MAMethod,MAAppliedPrice,0); string tooltip=symbolName+"\n.: "+GetPeriodStr(MATimeframe)+" MA ("+IntegerToString(MAPeriod)+"):.\nCurrent ("+DoubleToStr(ma,1)+")"; DrawLabel("ma_"+symbolName,x,y,GetMAStr(ma),fontSize,fontName,GetMAColor(ma),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetPivotColor(int pivotIdx)//+------------------------------------------------------------------+//+------------------------------------------------------------------+int GetClosestPivot(double ask,double &pivots[]) double minDistance=1.7976931348623158e+308; for(int i=0;i<ArraySize(pivots);i++) double dist=MathAbs(ask-pivots[i]);//+------------------------------------------------------------------+//+------------------------------------------------------------------+string GetPivotDirection(double value)//+------------------------------------------------------------------+//+------------------------------------------------------------------+double GetPivotValue(string symbolName,int timeframe)//Pivot point (PP) = (High + Low + Close) / 3 return (iHigh(symbolName,timeframe,1)+iLow(symbolName,timeframe,1)+iClose(symbolName,timeframe,1))/3;//+------------------------------------------------------------------+//+------------------------------------------------------------------+double GetPivotResistance(string symbolName,int timeframe,double pivotValue,int resistanceIdx=1) //Third resistance (R3) = High + 2(PP – Low) return iHigh(symbolName,timeframe,1) + 2*(pivotValue - iLow(symbolName,timeframe,1)); //Second resistance (R2) = PP + (High – Low) return pivotValue + (iHigh(symbolName,timeframe,1)-iLow(symbolName,timeframe,1)); //First resistance (R1) = (2 x PP) – Low return (2*pivotValue) - iLow(symbolName,timeframe,1);//+------------------------------------------------------------------+//+------------------------------------------------------------------+double GetPivotSupport(string symbolName,int timeframe,double pivotValue,int supportIdx=1) //Third support (S3) = Low – 2(High – PP) return iLow(symbolName,timeframe,1) - 2*(iHigh(symbolName,timeframe,1)-pivotValue); //Second support (S2) = PP – (High – Low) return pivotValue - (iHigh(symbolName,timeframe,1) - iLow(symbolName,timeframe,1)); //First support (S1) = (2 x PP) – High return (2*pivotValue) - iHigh(symbolName,timeframe,1);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawVolumeColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") long volume=iVolume(symbolName,VolumeTimeframe,0); double volAvg=(double)getAvgVolume(symbolName,VolumePeriod); double volPercent=(volume/volAvg)*100; string tooltip=symbolName+"\n.: "+GetPeriodStr(VolumeTimeframe)+" Volume ("+IntegerToString(VolumePeriod)+"):.\nCurrent ("+DoubleToStr(volume,0)+")\nAverage ("+DoubleToStr(volAvg,0)+")"; DrawLabel("vol"+symbolName,x,y,DoubleToStr(volPercent,2)+"%",fontSize,fontName,GetPercentColor(volPercent),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawRangeColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") double point=getPoint(symbolName); double modifier=getModifier(symbolName); if(point>0) atr=(NormalizeDouble(iATR(symbolName,AtrTimeframe,AtrPeriod,0)/point,0))/modifier; double range=getRange(symbolName,AtrTimeframe)/modifier; double rangePercent=(range/atr)*100; string tooltip=symbolName+"\n.: "+GetPeriodStr(AtrTimeframe)+" ATR ("+IntegerToString(AtrPeriod)+"):.\nCurrent ("+DoubleToStr(range,1)+")\nAverage ("+DoubleToStr(atr,1)+")"; DrawLabel("atr_"+symbolName,x,y,DoubleToStr(rangePercent,1)+"%",fontSize,fontName,GetPercentColor(rangePercent),tooltip);//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetRsiColor(double value)//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetMAColor(double value)//+------------------------------------------------------------------+//+------------------------------------------------------------------+string GetMAStr(double value)//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetStochColor(double value) if(value>=StochUpperLevel) if(value<=StochLowerLevel)//+------------------------------------------------------------------+//+------------------------------------------------------------------+color GetPercentColor(double value)//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawSymbolColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri") DrawLabel("lbl_"+symbolName,x,y,text,fontSize,fontName,clrWhite,symbolName);//+------------------------------------------------------------------+//+------------------------------------------------------------------+ int numColumns=(SymbolsTotal(true)/ColumnHeight)+1; int x=(GUIXOffset+GUIHeaderXOffset)+(NumVisibleColumns()*GUIColOffset)*i; int y=GUIYOffset+GUIHeaderYOffset; string n=IntegerToString(i); DrawLabel(objName+"name"+n,x,y,"Name",FontSize,FontName,clrWhite,"Name"); DrawHorizontalLine(objName+"namehline"+n,x,y,15); DrawLabel(objName+"price"+n,x+=GUIColOffset,y,"Price",FontSize,FontName,clrWhite,"Price"); DrawHorizontalLine(objName+"pricehline"+n,x,y,15); DrawLabel(objName+"spread"+n,x+=GUIColOffset,y,"Spread",FontSize,FontName,clrWhite,"Spread"); DrawHorizontalLine(objName+"spreadhline"+n,x,y,15); DrawLabel(objName+"range"+n,x+=GUIColOffset,y,"ATR ("+GetPeriodStr(AtrTimeframe)+")",FontSize,FontName,clrWhite,"Range"); DrawHorizontalLine(objName+"rangehline"+n,x,y,15); DrawLabel(objName+"curvolume"+n,x+=GUIColOffset,y,"Vol ("+GetPeriodStr(VolumeTimeframe)+")",FontSize,FontName,clrWhite,"Volume"); DrawHorizontalLine(objName+"volhline"+n,x,y,15); DrawLabel(objName+"rsi"+n,x+=GUIColOffset,y,"RSI ("+GetPeriodStr(RsiTimeframe)+")",FontSize,FontName,clrWhite,"Pivots"); DrawHorizontalLine(objName+"rsihline"+n,x,y,15); DrawLabel(objName+"stoch"+n,x+=GUIColOffset,y,"Stoch ("+GetPeriodStr(StochTimeframe)+")",FontSize,FontName,clrWhite,"Stochastic"); DrawHorizontalLine(objName+"stochhline"+n,x,y,15); DrawLabel(objName+",adx"+n,x+=GUIColOffset,y,"ADX ("+GetPeriodStr(AdxTimeframe)+")",FontSize,FontName,clrWhite,"ADX"); DrawHorizontalLine(objName+"adxhline"+n,x,y,15); DrawLabel(objName+"pivots"+n,x+=GUIColOffset,y,"Pivots",FontSize,FontName,clrWhite,"Pivots"); DrawHorizontalLine(objName+"pvotshline"+n,x,y,15); DrawLabel(objName+"ma"+n,x+=GUIColOffset,y,"MA",FontSize,FontName,clrWhite,"MA"); DrawHorizontalLine(objName+"maline"+n,x,y,15);//+------------------------------------------------------------------+//+------------------------------------------------------------------+//+------------------------------------------------------------------+//+------------------------------------------------------------------+void DrawHorizontalLine(string objName,int x,int y,int length=250) for(int i=0;i<length;i++) DrawLabel(objName+"1",x,y,line,FontSize,FontName,clrWhite,"");//DrawLabel(objName+"2",x+380,y,line,FontSize,FontName,clrWhite,"");//+------------------------------------------------------------------+int periodToMinutes(int period) static int _per[]={1,2,3,4,5,6,10,12,15,20,30,60,120,180,240,360,480,720,1440,10080,43200,0x4001,0x4002,0x4003,0x4004,0x4006,0x4008,0x400c,0x4018,0x8001,0xc001}; static int _min[]={1,2,3,4,5,6,10,12,15,20,30,60,120,180,240,360,480,720,1440,10080,43200}; if(period==PERIOD_CURRENT) for(i=0;i<20;i++) if(period==_per[i]) break;//+------------------------------------------------------------------+datetime iTime(int period) if(CopyTime(Symbol(),period,0,1,times)<=0)//+------------------------------------------------------------------+string getTime(int times,color &theColor) hours = (times-times%3600)/3600; minutes = (times-seconds)/60-hours*60; stime = stime+(string)hours+":0"; else stime = stime+(string)hours+":"; stime=stime+(string)minutes; stime=stime+":0"+(string)seconds; else stime=stime+":"+(string)seconds;//+------------------------------------------------------------------+string GetPivotStr(int pivotIdx)//+------------------------------------------------------------------+//+------------------------------------------------------------------+string GetPeriodStr(int period) case 1: TMz = "M1"; break; case 2: TMz = "M2"; break; case 3: TMz = "M3"; break; case 4: TMz = "M4"; break; case 5: TMz = "M5"; break; case 6: TMz = "M6"; break; case 7: TMz = "M7"; break; case 8: TMz = "M8"; break; case 9: TMz = "M9"; break; case 10: TMz = "M10"; break; case 11: TMz = "M11"; break; case 12: TMz = "M12"; break; case 13: TMz = "M13"; break; case 14: TMz = "M14"; break; case 15: TMz = "M15"; break; case 20: TMz = "M20"; break; case 25: TMz = "M25"; break; case 30: TMz = "M30"; break; case 40: TMz = "M40"; break; case 45: TMz = "M45"; break; case 50: TMz = "M50"; break; case 60: TMz = "H1"; break; case 120: TMz = "H2"; break; case 180: TMz = "H3"; break; case 240: TMz = "H4"; break; case 300: TMz = "H5"; break; case 360: TMz = "H6"; break; case 420: TMz = "H7"; break; case 480: TMz = "H8"; break; case 540: TMz = "H9"; break; case 600: TMz = "H10"; break; case 660: TMz = "H11"; break; case 720: TMz = "H12"; break; case 1440: TMz = "D1"; break; case 10080: TMz = "W1"; break; case 43200: TMz = "M1"; break;//+------------------------------------------------------------------+//+------------------------------------------------------------------+//| Create a trend line by the given coordinates |//+------------------------------------------------------------------+bool TrendCreate(const long chart_ID=0, // chart's ID const string name="TrendLine", // line name const int sub_window=0, // subwindow index datetime time1=0, // first point time double price1=0, // first point price datetime time2=0, // second point time double price2=0, // second point price const color clr=clrRed, // line color const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int width=1, // line width const bool back=false, // in the background const bool selection=true, // highlight to move const bool ray_right=false, // line's continuation to the right const bool hidden=true, // hidden in the object list const long z_order=0) // priority for mouse click//--- set anchor points' coordinates if they are not set ChangeTrendEmptyPoints(time1,price1,time2,price2);//--- reset the error value//--- create a trend line by the given coordinates if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) ": failed to create a trend line! Error code = ",GetLastError()); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);//--- set line display style ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);//--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);//--- enable (true) or disable (false) the mode of moving the line by mouse//--- when creating a graphical object using ObjectCreate function, the object cannot be//--- highlighted and moved by default. Inside this method, selection parameter//--- is true by default making it possible to highlight and move the object ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);//--- enable (true) or disable (false) the mode of continuation of the line's display to the right ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);//--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);//--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);//--- successful execution//+------------------------------------------------------------------+//| Check the values of trend line's anchor points and set default |//| values for empty ones |//+------------------------------------------------------------------+void ChangeTrendEmptyPoints(datetime &time1,double &price1, datetime &time2,double &price2)//--- if the first point's time is not set, it will be on the current bar//--- if the first point's price is not set, it will have Bid value price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);//--- if the second point's time is not set, it is located 9 bars left from the second one //--- array for receiving the open time of the last 10 bars CopyTime(Symbol(),Period(),time1,10,temp); //--- set the second point 9 bars left from the first one//--- if the second point's price is not set, it is equal to the first point's one//+------------------------------------------------------------------+
|