想要找一些外汇MT4的指标,附有源码,交易的时候可以辅助,编写指标的时候可以参考学习,想改善的时候,可以编辑。
常规的外汇MT4软件交易界面,外汇投资是看一个品种一个周期,但这个界面往往不能满足交易遇的需求,哪这个时候你可以采用同时监控、快速切换货币兑,黄金、原油等外汇多品种、多周期的面板指标。
当显示的颜色为红色,表示当前为上涨状态;
当显示的颜色为绿色,表示当前为下跌状态。
MT4—监控面板指标源码
下方分享的技术指标为副图分析公式源码,适用于MT4软件,是根据常见的方式改写。仅作为策略思路拓展,不建议直接用于货币兑、黄金、原油等外汇投资实盘中(投资有风险,入市须谨慎)。
交易员可以根据艾云策略所提供的指标源码,结合平时的交易经验进行改编,形成自己的交易策略。
#property copyright “弱水三千.艾云策略”
#property link “www.aiycl.cn”
#property description “作者微信/QQ:289876878”
#property description “出租/搭建AI机器人,群智能提醒服务”
#property description “若需定制其他EA/指标功能,请联系作者!”
#property version “1.00”
//+——————————————————————+
//| BUTTONS_TRO_MODIFIED |
//+——————————————————————+
#property indicator_separate_window
#property indicator_buffers 0
#property strict
//+——————————————————————+
extern bool TURN_OFF = false ;
extern bool SHOW_CANDLE_COLOR = true;
extern string sOption = “Type ALL in Symbols for all symbols “;
extern string Symbols=”AUDCAD;AUDCHF;AUDJPY;AUDNZD;AUDUSD;CADCHF;CADJPY;CHFJPY;EURAUD;EURCAD;EURCHF;EURGBP;EURJPY;EURNZD;EURUSD;GBPAUD;GBPCAD;GBPCHF;GBPJPY;GBPNZD;GBPUSD;NZDCAD;NZDCHF;NZDJPY;NZDUSD;USDCAD;USDCHF;USDJPY;XAUUSD;BTCUSD”;
//extern string Symbols=”AUDJPY;AUDUSD;EURUSD;EURGBP;EURJPY;GBPUSD;GBPJPY;NZDUSD;USDCAD;USDCHF;USDJPY;XAUUSD”; // List of symbols (separated by “;”)
extern string Suffix=””;
extern string UniqueID=”changer”; // Indicator unique ID
extern int ButtonsInARow = 15; // Buttons in a horizontal row
extern int Corner = 2; // Corner
extern int XShift = 20; // Horizontal shift
extern int YShift = 20; // Vertical shift
extern int XSize = 60; // Width of buttons
extern int YSize = 16; // Height of buttons
extern int FSize = 8; // Font size
extern string FontType = “Consolas” ; // Font
extern color Bcolor=clrLightGray; // Button color
extern color Dcolor=clrDarkSlateBlue; // Button border color
extern color Tncolor=clrBlack; // Text color – normal
extern color Sncolor= clrBlue; // Text color – selected
extern bool Transparent= true; // Transparent buttons?
extern color colorUp = Lime ;
extern color colorDn = Red ;
//+——————————————————————+
string aSymbols[], tSymbols, xySymbol,yxSymbol,symbol ;
string CurrencyTable[] = {“AUD”,”CAD”,”CHF”,”EUR”,”GBP”,”JPY”,”NZD”,”USD”};
color FG, BG, XG, FGbuttonTF, BGbuttonTF;
string TF[] = { “1”,”5″,”15″,”30″,”H1″,”H4″,”D”,”W”,”M” } ;
int CP[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1 };
int CCPER,win ;
string text ;
//+——————————————————————+
bool IsLoaded( string list, string lookfor )
{
if(StringFind( list , lookfor, 0) ) { return(true) ; } else { return(false) ; }
}
//+——————————————————————+
int OnInit()
{
if( TURN_OFF ) { OnDeinit(0); return(0) ; }
IndicatorShortName(“Buttons”);
win = WindowFind(“Buttons”);
FG = Tncolor ;
BG = Bcolor ;
FGbuttonTF = Tncolor ;
BGbuttonTF = Bcolor ;
symbol = Symbol() ;
if(StringFind(AccountInfoString(ACCOUNT_COMPANY),”TW”,0) >= 0 && StringFind(Symbol(),”i”,0) >= 0) { Suffix = “i” ; } else
if(StringFind(AccountInfoString(ACCOUNT_COMPANY),”Gain”,0) >= 0) { Suffix = “pro” ; }
int pairlen = StringLen(symbol);
if(XSize < pairlen*10) { XSize = pairlen*10 -20; }
tSymbols = Symbols;
if(tSymbols == “ALL” )
{
Symbols = “” ;
for(int c=0;c<8;c++)
{
for(int d=c+1;d<8;d++)
{
xySymbol = CurrencyTable[c]+CurrencyTable[d]+Suffix;
yxSymbol = CurrencyTable[d]+CurrencyTable[c]+Suffix;
if( MarketInfo(xySymbol,MODE_BID) != 0.0 && IsLoaded( Symbols, xySymbol ) ) { Symbols = Symbols + xySymbol + “;” ; }
else if( MarketInfo(yxSymbol,MODE_BID) != 0.0 && IsLoaded( Symbols, yxSymbol ) ) { Symbols = Symbols + yxSymbol + “;” ; }
}
}
}
int xpos=0,ypos=0,maxx=0,maxy=0;
if(tSymbols != “NONE” )
{
Symbols=StringTrimLeft(StringTrimRight(Symbols));
if(StringSubstr(Symbols,StringLen(Symbols)-1,1)!=”;”)
Symbols=StringConcatenate(Symbols,”;”);
int s=0,i=StringFind(Symbols,”;”,s);
string current;
while(i>0)
{
current=StringSubstr(Symbols,s,i-s);
ArrayResize(aSymbols,ArraySize(aSymbols)+1);
aSymbols[ArraySize(aSymbols)-1]=current;
s = i + 1;
i = StringFind(Symbols,”;”,s);
}
ShellsortStringArray(aSymbols, 0, false) ;
// int xpos=0,ypos=0,maxx=0,maxy=0;
for(i=0; i<ArraySize(aSymbols); i++)
{
if(i>0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; }
text = StringSubstr(aSymbols[i],0,StringLen(aSymbols[i])-StringLen(Suffix));
createButton(UniqueID+”:symbol:”+string(i),text,XShift+xpos,YShift+ypos);
xpos+=XSize+1;
}
/*
xpos=0; ypos+=YSize*2;
for(i=0; i<ArraySize(sTfTable); i++)
{ if(i>0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; } createButton(UniqueID+”:time:”+string(i),sTfTable[i],XShift+xpos,YShift+ypos); xpos+=XSize+1; }
*/
setSymbolButtonColor();
}
xpos=0; ypos+=YSize*2;
for(int i=0; i<ArraySize(sTfTable); i++)
{ if(i>0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; } createButton(UniqueID+”:time:”+string(i),sTfTable[i],XShift+xpos,YShift+ypos); xpos+=XSize+1; }
setTimeFrameButtonColor();
return(0);
}
//+——————————————————————+
void ShellsortStringArray(string &a[], int size=0, bool desc=false) {
//+——————————————————————+
// Performs a shell sort (rapid resorting) of string array ‘a’
// default is ascending order, unless ‘desc’ is set to true
int n=ArraySize(a);
if (size>0) n=size;
int j,i, m;
string mid;
for(m=n/2; m>0; m/=2) {
for(j=m; j<n; j++) {
for(i=j-m; i>=0; i-=m) {
if (desc) {
if (a[i+m] <= a[i])
break;
else {
mid = a[i];
a[i] = a[i+m];
a[i+m] = mid;
} }
else {
if (a[i+m] >= a[i])
break;
else {
mid = a[i];
a[i] = a[i+m];
a[i+m] = mid;
} }
} } }
return ;
}
//+——————————————————————+
void OnDeinit(const int reason)
{
switch(reason)
{
case REASON_CHARTCHANGE :
case REASON_RECOMPILE :
case REASON_CLOSE : break;
default :
{
string lookFor = UniqueID+”:”;
int lookForLength = StringLen(lookFor);
for(int i=ObjectsTotal()-1; i>=0; i–)
{
string objectName=ObjectName(i); if(StringSubstr(objectName,0,lookForLength)==lookFor) ObjectDelete(objectName);
}
}
}
}
//+——————————————————————+
void createButton(string name,string caption,int xpos,int ypos)
{
if(ObjectFind(name)!=0)
ObjectCreate(name,OBJ_BUTTON,win,0,0);
ObjectSet(name,OBJPROP_CORNER,0);
ObjectSet(name,OBJPROP_XDISTANCE,xpos);
ObjectSet(name,OBJPROP_YDISTANCE,ypos);
ObjectSet(name,OBJPROP_XSIZE,XSize);
ObjectSet(name,OBJPROP_YSIZE,YSize);
ObjectSetText(name,caption,FSize,FontType,Tncolor);
ObjectSet(name,OBJPROP_FONTSIZE,FSize);
ObjectSet(name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSet(name,OBJPROP_COLOR,FG);
ObjectSet(name,OBJPROP_BGCOLOR,BG);
ObjectSet(name,OBJPROP_BACK,Transparent);
ObjectSet(name,OBJPROP_BORDER_COLOR,Dcolor);
ObjectSet(name,OBJPROP_STATE,false);
ObjectSet(name,OBJPROP_HIDDEN,true);
ObjectSet(name,OBJPROP_CORNER,Corner);
}
//+——————————————————————+
void setSymbolButtonColor()
{
string lookFor = UniqueID+”:symbol:”;
int lookForLength = StringLen(lookFor);
for(int i=ObjectsTotal()-1; i>=0; i–)
{
FG = Tncolor ;
BG = Bcolor ;
string objectName=ObjectName(i);
if(StringSubstr(objectName,0,lookForLength)==lookFor)
{
string symbol=ObjectGetString(0,objectName,OBJPROP_TEXT)+Suffix;
if(SHOW_CANDLE_COLOR)
{
if( iClose( symbol, PERIOD_CURRENT, 0 ) >= iOpen( symbol, PERIOD_CURRENT, 0 ) )
{ BG = colorUp ; } else { BG = colorDn ; }
if(symbol==_Symbol) { XG = FG; FG = BG; BG = XG ; }
ObjectSet(objectName,OBJPROP_COLOR,FG);
ObjectSet(objectName,OBJPROP_BGCOLOR,BG);
}
else
{
if(symbol!=_Symbol)
ObjectSet(objectName,OBJPROP_COLOR,Tncolor);
else ObjectSet(objectName,OBJPROP_COLOR,Sncolor);
}
}
}
}
//+——————————————————————+
void setTimeFrameButtonColor()
{
string lookFor = UniqueID+”:time:”;
int lookForLength = StringLen(lookFor);
for(int i=ObjectsTotal()-1; i>=0; i–)
{
FGbuttonTF = Tncolor ;
BGbuttonTF = Bcolor ;
string objectName=ObjectName(i);
if(StringSubstr(objectName,0,lookForLength)==lookFor)
{
string sTime = ObjectGetString(0,objectName,OBJPROP_TEXT) ;
int time = stringToTimeFrame(sTime);
if(time != _Period)
{
if(SHOW_CANDLE_COLOR)
{
if( iClose( symbol, time, 0 ) >= iOpen( symbol, time, 0 ) )
{ BGbuttonTF = colorUp ; } else { BGbuttonTF = colorDn ; }
ObjectSet(objectName,OBJPROP_COLOR,FGbuttonTF);
ObjectSet(objectName,OBJPROP_BGCOLOR,BGbuttonTF);
}
else
{
ObjectSet(objectName,OBJPROP_COLOR,Tncolor);
}
}
else
{
if(SHOW_CANDLE_COLOR)
{
if( iClose( symbol, time, 0 ) >= iOpen( symbol, time, 0 ) )
{ BGbuttonTF = colorUp ; } else { BGbuttonTF = colorDn ; }
XG = FGbuttonTF; FGbuttonTF = BGbuttonTF; BGbuttonTF = XG ;
ObjectSet(objectName,OBJPROP_COLOR,FGbuttonTF);
ObjectSet(objectName,OBJPROP_BGCOLOR,BGbuttonTF);
}
else { ObjectSet(objectName,OBJPROP_COLOR,Sncolor); }
}
}
}
}
//+——————————————————————+
string sTfTable[] = {“M1″,”M5″,”M15″,”M30″,”H1″,”H4″,”D1″,”W1″,”MN”};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
//+——————————————————————+
string timeFrameToString(int tf)
{
for(int i=ArraySize(iTfTable)-1; i>=0; i–)
if(tf==iTfTable[i]) return(sTfTable[i]);
return(“”);
}
//+——————————————————————+
int stringToTimeFrame(string tf)
{
for(int i=ArraySize(sTfTable)-1; i>=0; i–)
if(tf==sTfTable[i]) return(iTfTable[i]);
return(0);
}
//+——————————————————————+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
if(id==CHARTEVENT_OBJECT_CLICK && ObjectGet(sparam,OBJPROP_TYPE)==OBJ_BUTTON)
{
if(StringFind(sparam,UniqueID+”:symbol:”,0)==0) ChartSetSymbolPeriod(0,ObjectGetString(0,sparam,OBJPROP_TEXT)+Suffix,_Period);
if(StringFind(sparam,UniqueID+”:time:” ,0)==0) ChartSetSymbolPeriod(0,_Symbol,stringToTimeFrame(ObjectGetString(0,sparam,OBJPROP_TEXT)));
if(StringFind(sparam,UniqueID+”:back:” ,0)==0) ObjectSet(sparam,OBJPROP_STATE,false);
}
}
//+——————————————————————+
int start()
{
if(SHOW_CANDLE_COLOR)
{
setTimeFrameButtonColor() ;
setSymbolButtonColor() ;
}
return(0);
}
//+——————————————————————+