# 双均线模型

MT4跟MT5的寫法不一樣 你應該要註明清楚哪個版本的

Hung Wen Lin:
MT4跟MT5的寫法不一樣 你應該要註明清楚哪個版本的
MT4

```//+------------------------------------------------------------------+
//|                                                     叉叉交易.mq4 |
//|                                                        Submarine |
//|                         https://www.mql5.com/zh/users/carllin000 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict

input double Lots  = 0.1;
input int    Magic = 12345;
input string Comm  = "叉叉交易";

input int    Fast  = 5;
input int    Slow  = 10;

int BarCount;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(AccountProfit()>=5)
deleteorder(-100);

if(BarCount!=iBars(NULL,0))
BarCount=iBars(NULL,0);
else
return;

double SlowMA  = iMA(NULL,0,Fast,0,0,0,1);
double SlowMA1 = iMA(NULL,0,Fast,0,0,0,2);
double FastMA  = iMA(NULL,0,Slow,0,0,0,1);
double FastMA1 = iMA(NULL,0,Slow,0,0,0,2);

if(FastMA1<SlowMA1 && FastMA>SlowMA)
{
deleteorder(OP_SELL);
if(OrdersTotal()==0)
}

if(FastMA1>SlowMA1 && FastMA<SlowMA)
{
if(OrdersTotal()==0)
int b=OrderSend(NULL,OP_SELL,Lots,Bid,60,0,0,Comm,Magic,0,clrRed);
}
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
void deleteorder(int type)
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
if(OrderType()==type || type==-100)
{
if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),60)==false)
Print("ErrorDescription"+(string)GetLastError());
i=OrdersTotal();
}
}
}
```

Hung Wen Lin #:

Lin Luo #: