MT4公式exp_Amstell-SL 指标源码
-
相关简介://+------------------------------------------------------------------+ //| exp_Amstell.mq4 | //|&nb
-
文章来源:股海网作者:股海网发布时间:2013-09-08浏览次数:
//+------------------------------------------------------------------+
//| exp_Amstell.mq4 |
//| Copyright � 2009, Yuriy Tokman |
//|
//+------------------------------------------------------------------+
#property copyright "Copyright � 2009, Yuriy Tokman"
#property link "
extern int TakeProfit = 30;
extern int StopLoss = 30;
extern double Lots = 0.01;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Magic=0;
for(int cnt=0;cnt<OrdersTotal();cnt++)// 襄疱徼疣屐 怦� 铕溴疣
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);//铕溴� 恹徼疣弪� 耩邃� 铗牮 � 铗腩驽眄 铕溴痤�
if( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)// 杨怙噤噱� 腓 耔焘铍 铕溴疣( 卿羼� 镱 磬漕犴铖蜩 妁� 爨汨� 祛骓� 镳钼屦栩�)
{
if(OrderType()==OP_BUY)//悟徼疣屐 镱玷鲨� 徉�
{
if(Bid-OrderOpenPrice()>TakeProfit*Point || OrderOpenPrice()-Ask>StopLoss*Point)//
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); //玎牮噱� 铕溴�
return(0); // 恹躅滂�
}//StopLoss
}
if(OrderType()==OP_SELL)//悟徼疣屐 镱玷鲨� 皴腚
{
if(OrderOpenPrice()-Ask>TakeProfit*Point || Bid-OrderOpenPrice()>StopLoss*Point)//
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //玎牮噱� 铕溴�
return(0); // 恹躅滂�
}
}
}
}
//----
int buy = 0, sell = 0;
//----
if(!ExistPositions(NULL,OP_BUY))buy=1;
else if(PriceOpenLastPos(NULL,OP_BUY)-Ask>10*Point)buy=1;
if(!ExistPositions(NULL,OP_SELL))sell=1;
else if(Bid-PriceOpenLastPos(NULL,OP_SELL)>10*Point)sell=1;
//----
if(buy==1)
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",0,0,Green);
if(sell==1)
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",0,0,Red);
//----
return(0);
}
bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
int i, k=OrdersTotal();
if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (ot<=OrderOpenTime()) return(True);
}
}
}
}
}
}
return(False);
}
double PriceOpenLastPos(string sy="", int op=-1, int mn=-1) {
datetime t;
double r=0;
int i, k=OrdersTotal();
if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderOpenTime()) {
t=OrderOpenTime();
r=OrderOpenPrice();
}
}
}
}
}
}
}
return(r);
}