上图:外汇MT4交易自定义设置
一、自动止盈止损功能(EA:自动止盈止损mq4)
//+------------------------------------------------------------------+
//| 自动设置止损.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//--- input parameters
input int Input1=30;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
//for (buys=0,sells=0;)
double aa=MarketInfo(Symbol(),MODE_TICKSIZE)*300;
if (OrdersTotal()>0)
for(int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)& OrderStopLoss()==0 || OrderTakeProfit()==0)
{
//if (OrderType()==OP_BUYSTOP) OrderModify(OrderTicket(),OrderOpenPrice(),Ask+aa,Bid-aa,0,0);
if (OrderType()==OP_SELLLIMIT & Symbol()==OrderSymbol()) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+aa,Digits),NormalizeDouble(OrderOpenPrice()-aa,Digits),0,CLR_NONE );
if (OrderType()==OP_SELL & Symbol()==OrderSymbol()) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+aa,Digits),NormalizeDouble(Bid-aa,Digits),0,CLR_NONE );
if (OrderType()==OP_BUYLIMIT &Symbol()==OrderSymbol()) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-aa,Digits),NormalizeDouble(OrderOpenPrice()+aa,Digits),0,CLR_NONE );
if (OrderType()==OP_BUY & Symbol()==OrderSymbol()) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-aa,Digits),NormalizeDouble(Ask+aa,Digits),0,CLR_NONE );
Print(NormalizeDouble(OrderOpenPrice()+aa,Digits));
Print("订单类型:", OrderType(),"GGGH:",OrderOpenPrice()-aa);
//Print(OrderSymbol(),"止损:",OrderStopLoss());
Print(OrderSymbol(),"点差:",MarketInfo(Symbol(),MODE_SPREAD));
//Print(OrderSymbol(),"小数位:",MarketInfo(Symbol(),MODE_DIGITS));
Print(OrderSymbol(),"小数位:",aa);
//Print("ORDERTICKET",OrderTicket());
//Print("MAGICNUM:",OrderMagicNumber());
}
}
}
//+------------------------------------------------------------------+
功能:下单后,按照自编EA设置止盈止损位。
二、Stochastic指标多周期同图显示
自己偏爱Stochastic随机振荡指标,且H4为主,但要参考观察H1\D1\W1该指标情况(共振拐点出现后入场操作,即:改造Stochastic指标,H1,H4,D1,W1四周同图显示(只显示>=当前窗口周期该指标图)。
1、方向确定:W1大周期作为根本,运行至20(或15)以下超卖考虑做多方向,80(或85)以上超买做空方向;
2、场外观察:D1周期指标向下死叉、向上金叉W1周期指标;
3、场内观察:H4由高位下行,低位上行,一般死叉、金叉长周期指标。
4、下单时间:H1低位介入。
//+------------------------------------------------------------------+
//| eXclusive MTF Sto.mq4 |
//| Copyright ?2013, mt4exclusive.com |
//| http://www.mt4exclusive.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2013, mt4exclusive.com"
#property link "http://www.mt4exclusive.com"
#property indicator_color4 Blue
#property indicator_color5 White
#property indicator_color6 Aqua
#property indicator_color7 Yellow
#property indicator_color8 Moccasin
#property indicator_separate_window//单独窗口中显示指标
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 8//指标的“缓冲区数量”
#property indicator_level9 90,indicator_levelstyle STYLE_DASH,indicator_levelcolor clrSliver
#property indicator_level7 85
#property indicator_level5 80
#property indicator_level3 70//指标的“水平位”
#property indicator_level1 50
#property indicator_level2 30
#property indicator_level4 20
#property indicator_level6 15
#property indicator_level8 10,indicator_levelstyle STYLE_DASH,indicator_levelcolor clrSliver
//以下为指标的“输入参数”
extern int Kperiod=5;
extern int Dperiod=3;
extern int Slowing=3;
int DL=50;
extern bool ShowSto_M30 = true;
extern bool ShowSto_M60 = true;
extern bool ShowSto_M240= true;
extern bool ShowSto_M1440=true;
extern bool ShowSto_M10080=true;
extern color M30_color=Blue;
extern color M60_color=White;
extern color M240_color=Aqua;
extern color M1440_color=Yellow;
extern color M10080_color=Moccasin;
double M30Buffer[];
double M60Buffer[];
double M240Buffer[];
double M1440Buffer[];
double M10080Buffer[];
int TF30=30;
int TF60=60;
int TF240=240;
int TF1440=1440;
int TF10080=10080;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- indicators
//============================================================================================
//IndexBuffer为指标缓冲区(index英文有指标的意思,但也有索引的意思,即第几个指标缓冲区),指标缓冲区的个数由 IndicatorBuffers() 函数设定并且不能超过8个。
//SetIndexBuffer:即将第几个自定义的指标缓冲区绑定到指定数组array[]。
//SetIndexStyle() – 设置指定的指标线设置新类型、样式、宽度和颜色。
//void SetIndexStyle(int index, int type, void style, void width, void clr)
//index - 指标线。必须在0至7之间。
//type - 形状样式,可以是 划线形状样式列表 中任意一个。
//style - 线型。可以应用一个像素的粗线,可以是 划线形状样式列表 其中一个。EMPTY值表示线型不变。
//width - 线宽。有效值是1,2,3,4,5。EMPTY值表示线宽不变。
//clr - 线的颜色。省略本参数表示颜色将保持不变
//============================================================================================
SetIndexBuffer(3,M30Buffer);
SetIndexLabel(3,"M30 Sto");
SetIndexStyle(3,DRAW_LINE,0,2,M30_color);
//============================================================================================
SetIndexBuffer(4,M60Buffer);
SetIndexLabel(4,"H1 Sto");
SetIndexStyle(4,DRAW_LINE,0,2,M60_color);
//============================================================================================
SetIndexBuffer(5,M240Buffer);
SetIndexLabel(5,"H4 Sto");
SetIndexStyle(5,DRAW_LINE,0,2,M240_color);
//============================================================================================
SetIndexBuffer(6,M1440Buffer);
SetIndexLabel(6,"D1 Sto");
SetIndexStyle(6,DRAW_LINE,0,2,M1440_color);
//============================================================================================
SetIndexBuffer(7,M10080Buffer);
SetIndexLabel(7,"W1 Sto");
SetIndexStyle(7,DRAW_LINE,1,1,M10080_color);
//============================================================================================
IndicatorShortName("eXclusive MTF_Sto("+Kperiod+")");//指标窗口左上角显示的“指标名称”
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()//清空内存
{
//----
//The function removes the object with the specified name at the specified chart. There are two variants of the function:
//该函数在指定的图表中移除具有指定名称的对象。
ObjectDelete("H1_Sto");
ObjectDelete("H4_Sto");
ObjectDelete("D1_Sto");
ObjectDelete("W1_Sto");
ObjectDelete("H1Value_Sto");
ObjectDelete("H4Value_Sto");
ObjectDelete("D1Value_Sto");
ObjectDelete("W1Value_Sto");
//----
return(0);
}
//============================================================================================
int start()
{
//画副指标多时间周期文字,指标线
// if(ShowSto_M60 && Period()<=60) {start5();CreateLabel("H1_Sto",170,30,2,M60_color,"H1",10);CreateLabel("H1Value_Sto",170,10,2,M60_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF60,Kperiod,Dperiod,Slowing,0,0,0,0),1),1),10);}
double p_bs=1.5;
//M30------------------------
string vsto30=NormalizeDouble(iStochastic(NULL,TF30,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1)*p_bs;
if(ShowSto_M30 && Period()<=30 ) {start4();}
if (Period()==30) {SetIndexStyle(3,DRAW_LINE,0,3,M30_color);SetIndexStyle(4,DRAW_LINE,0,3,M60_color);SetIndexStyle(5,DRAW_LINE,0,1,M240_color);SetIndexStyle(6,DRAW_LINE,0,1,M1440_color);SetIndexStyle(7,DRAW_LINE,1,1,M10080_color);}
//1h------------------------
string vsto60=NormalizeDouble(iStochastic(NULL,TF60,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1)*p_bs;
if(ShowSto_M60 && Period()<=60 ) {start5();}
if (Period()==60) {SetIndexStyle(3,DRAW_LINE,0,3,M30_color);SetIndexStyle(4,DRAW_LINE,0,3,M60_color);SetIndexStyle(5,DRAW_LINE,0,1,M240_color);SetIndexStyle(6,DRAW_LINE,0,1,M1440_color);SetIndexStyle(7,DRAW_LINE,1,1,M10080_color);}
CreateLabel("H1_Sto",DL,95*p_bs,3,M60_color,"H1",10);CreateLabel("H1Value_Sto",DL,vsto60,3,M60_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF60,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1),1),10);
//4h-------------------
string vsto240=NormalizeDouble(iStochastic(NULL,TF240,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1)*p_bs;
if(ShowSto_M240 && Period()<=240) {start6();}
if (Period()==240) {SetIndexStyle(4,DRAW_LINE,0,1,M60_color);SetIndexStyle(5,DRAW_LINE,0,3,M240_color);SetIndexStyle(6,DRAW_LINE,0,1,M1440_color);SetIndexStyle(7,DRAW_LINE,1,1,M10080_color);}
CreateLabel("H4_Sto",DL+40,95*p_bs,3,M240_color,"H4",10);CreateLabel("H4Value_Sto",DL+40,vsto240,3,M240_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF240,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1),1),10);
//1d--------------
string vsto1440=NormalizeDouble(iStochastic(NULL,TF1440,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1)*p_bs;
if(ShowSto_M1440&& Period()<=1440) {start7();}
if (Period()==1440) {SetIndexStyle(4,DRAW_LINE,0,1,M60_color);SetIndexStyle(5,DRAW_LINE,0,1,M240_color);SetIndexStyle(6,DRAW_LINE,0,3,M1440_color);SetIndexStyle(7,DRAW_LINE,1,1,M10080_color);}
CreateLabel("D1_Sto",DL+2*40,95*p_bs,3,M1440_color,"D1",10);CreateLabel("DValue_Sto",DL+2*40,vsto1440,3,M1440_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF1440,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1),1),10);
//1w----------------------
string vsto10080=NormalizeDouble(iStochastic(NULL,TF10080,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1)*p_bs;
//if(ShowSto_M10080 && Period()<=10080 ) {start8();CreateLabel("W1_Sto",DL+3*40,95*p_bs,3,M10080_color,"W1",10);CreateLabel("W1Value_Sto",DL+3*40,vsto10080,3,M10080_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF10080,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1),1),10);}
start8();
if (Period()==10080) {SetIndexStyle(4,DRAW_LINE,0,1,M60_color);SetIndexStyle(5,DRAW_LINE,0,1,M240_color);SetIndexStyle(6,DRAW_LINE,0,1,M1440_color);SetIndexStyle(7,DRAW_LINE,1,2,M10080_color);}
CreateLabel("W1_Sto",DL+3*40,95*p_bs,3,M10080_color,"W1",10);CreateLabel("W1Value_Sto",DL+3*40,vsto10080,3,M10080_color,DoubleToStr(NormalizeDouble(iStochastic(NULL,TF10080,Kperiod,Dperiod,Slowing,0,0,MODE_SIGNAL,0),1),1),10);
return(0);
}
//============================================================================================
//============================================================================================
//============================================================================================
int start4()
//第4个缓冲区
{
datetime TimeArray4[];
int i,limit,y=0,counted_bars=IndicatorCounted();
//IndicatorCounted:The function returns the amount of bars not changed after the indicator had been launched last.
//该函数返回上次启动指示器后未更改的条数。
ArrayCopySeries(TimeArray4,MODE_TIME,Symbol(),TF30);
//ArrayCopySeries:Copies a series array to another one and returns the count of the copied elements.
//将序列数组复制到另一个数组,并返回复制的元素的计数。
//
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (y<ArraySize(TimeArray4)) {if(Time[i]<TimeArray4[y]) y++;}
//M60Buffer[i]=iRSI(NULL,TF60,RSIperiod,RSIprice,y);
M30Buffer[i]=iStochastic(NULL,TF30,Kperiod,Dperiod,Slowing,MODE_SMA,0,MODE_SIGNAL,y);
}
return(0);
}
//============================================================================================
int start5()
//第5个缓冲区
{
datetime TimeArray5[];
int i,limit,y=0,counted_bars=IndicatorCounted();
//IndicatorCounted:The function returns the amount of bars not changed after the indicator had been launched last.
//该函数返回上次启动指示器后未更改的条数。
ArrayCopySeries(TimeArray5,MODE_TIME,Symbol(),TF60);
//ArrayCopySeries:Copies a series array to another one and returns the count of the copied elements.
//将序列数组复制到另一个数组,并返回复制的元素的计数。
//
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (y<ArraySize(TimeArray5)) {if(Time[i]<TimeArray5[y]) y++;}
//M60Buffer[i]=iRSI(NULL,TF60,RSIperiod,RSIprice,y);
M60Buffer[i]=iStochastic(NULL,TF60,Kperiod,Dperiod,Slowing,MODE_SMA,0,MODE_SIGNAL,y);
}
return(0);
}
//============================================================================================
int start6()
{
datetime TimeArray6[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray6,MODE_TIME,Symbol(),TF240);
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (y<ArraySize(TimeArray6)) {if(Time[i]<TimeArray6[y]) y++;}
//M240Buffer[i]=iRSI(NULL,TF240,RSIperiod,RSIprice,y);
M240Buffer[i]=iStochastic(NULL,TF240,Kperiod,Dperiod,Slowing,MODE_SMA,0,MODE_SIGNAL,y);
}
return(0);
}
//============================================================================================
int start7()
{
datetime TimeArray7[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray7,MODE_TIME,Symbol(),TF1440);
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (y<ArraySize(TimeArray7)) {if(Time[i]<TimeArray7[y]) y++;}
//M1440Buffer[i]=iRSI(NULL,TF1440,RSIperiod,RSIprice,y);
M1440Buffer[i]=iStochastic(NULL,TF1440,Kperiod,Dperiod,Slowing,MODE_SMA,0,MODE_SIGNAL,y);
}
return(0);
}
//============================================================================================
int start8()
{
datetime TimeArray8[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray8,MODE_TIME,Symbol(),TF10080);
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (y<ArraySize(TimeArray8)) {if(Time[i]<TimeArray8[y]) y++;}
//M10080Buffer[i]=iRSI(NULL,TF10080,RSIperiod,RSIprice,y);
M10080Buffer[i]=iStochastic(NULL,TF10080,Kperiod,Dperiod,Slowing,MODE_SMA,0,MODE_SIGNAL,y);
}
return(0);
}
//============================================================================================
//============================================================================================
void CreateLabel(string name,int x,int y,int corner,int z,string text,int size,
string font="Arial")
{
ObjectCreate(name,OBJ_LABEL,WindowFind("eXclusive MTF_Sto("+Kperiod+")"),0,0);
//ObjectCreate:The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart.
//该函数在指定图表的"指定图表子窗口"中创建具有指定名称、类型和初始坐标的对象。有两个变形函数。
//WindowFind:Returns the window index containing this specified indicator.返回包含指定指标的窗口索引号。否则返回-1。
//NOTE:Coordinates must be passed in pairs: time and price.Objects of the OBJ_LABEL type ignore the coordinates. Use the ObjectSet() function to set up the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
//注意:坐标须成对标传递:时间和价格。签类型的对象忽略坐标。使用ObjectSet()函数设置标签对象的X、Y属性.
ObjectSet(name,OBJPROP_CORNER,corner);
ObjectSet(name,OBJPROP_COLOR,z);
ObjectSet(name,OBJPROP_XDISTANCE,x);
ObjectSet(name,OBJPROP_YDISTANCE,y);
ObjectSetText(name,text,size,font,z);
}
//自定义函数CreateLable
//CreateLabel("H1_RSI",170,30,2,M60_color,"H1",10)
//CreateLabel("H1Value_RSI",170,10,2,M60_color,DoubleToStr(NormalizeDouble(iRSI(NULL,TF60,RSIperiod,0,0),1),1),10)
//============================================================================================
三、均线主图指标
只使用50\100均线
系统均线即可,修改参数,50,100。