学习笔记
先要读懂ea
这是一个EA我要试着去逐行的解读
/+------------------------------------------------------------------+
//| 0088C.mq4 |
//+------------------------------------------------------------------+
extern int MagicNumber = 2009;
extern string TEST1=\"测试先头(启动/买BUY/卖SELL)\";
extern bool Test = false;
extern string TEST2=\"自动先头单方向(买BUY/卖SELL)\";
extern bool TestBuy = false;
extern bool TestSell = false;
extern bool Stair = true;
extern double Lots = 0.01;
extern double StairProfit = 1;
extern double SpreadPipLoss = 0.3;
extern int MaximumOrders = 70;
extern int MinimumOrders = 1;
extern double ProfitNotOpenOrdersAbove=50000;
extern double ProfitNotOpenOrdersBelow=-1;
extern double OpenOrdersBelow=20000;
extern double OpenOrdersAbove=0;
extern bool LevelClose = false;
extern double CloseUpper=20000;
extern double CloseLower=0;
extern bool ProfitClose = false;
extern double ProfitUpper=20000;
extern double ProfitLower=-10000;
extern bool Comments=true;//|--------------------allow comments on chart
extern string PLDTSL504E=\"504自动锁单追踪EA\";
extern string P1=\"先锁单后追踪\";
extern bool ProfitLockingthenProfitTrailing = True;
extern string SL=\"是否自动设置止损\";
extern bool SetLossing = False;
extern double MaximalLossing = 90;
extern string PL=\"N点锁/锁N点,N点追踪/保持N点\";
extern double ProfitLockingStop = 8;
extern double ProfitLockingStep = 1;
extern double TrailingStop = 500;
extern double TrailingStep = 400;
extern bool UseSound = False;
extern string NameFileSound = \"expert.wav\";
int start()
{
for (int i=0; i((((1+OrdersTotal())*OrdersTotal())/2)*StairProfit)-(OrdersTotal()*SpreadPipLoss)){
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,\"Sell\",MagicNumber,0,Red);
}
}
}
}
}
}
}
}
}
}
if(LevelClose==true){
if(CloseLower-Bid>=0 ){
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
Alert(\"Order \" , OrderTicket() , \" failed to close. Error:\" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
if(CloseUpper-Ask=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
Alert(\"Order \" , OrderTicket() , \" failed to close. Error:\" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
}
if (ProfitClose==true)
{
if (AccountProfit()>= ProfitUpper)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Pink);
break;
//Close opened short positions
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Pink);
}
if(result == false)
{
Sleep(3000);
}
}
Print (\"Account Profit Reached. All Open Trades Have Been Closed\");
return(0);
}
if (AccountProfit()=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Pink);
break;
//Close opened short positions
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Pink);
}
if(result == false)
{
Sleep(3000);
}
}
Print (\"Account Profit Reached. All Open Trades Have Been Closed\");
return(0);
}
}
if(Comments)
{
Comment(\"nCopyright 0088C 金字塔累加EA \",\"n买入 = \"+ DoubleToStr(Ask,5),\"n卖出 = \" + DoubleToStr(Bid,5),
\"n开仓单位大小 = \" + DoubleToStr(Lots,2),
\"n单子总数 = \" + DoubleToStr(OrdersTotal(),2),
\"n帐户担保资金 = \" + DoubleToStr(AccountMargin(),2),
\"n利润 = \" + DoubleToStr(AccountProfit(),2),
\"n余额 = \" + DoubleToStr(AccountBalance(),2),
\"n价值 = \" + DoubleToStr(AccountEquity(),2),
\"n收益多少元开始累加 = \" + DoubleToStr(StairProfit,2),
\"n点差损失 = \" + DoubleToStr(SpreadPipLoss,2),
\"n最多多少单子 = \" + DoubleToStr(MaximumOrders,2),
\"n利润大于多少禁止开仓 = \" + DoubleToStr(ProfitNotOpenOrdersAbove,2),
\"n利润小于多少禁止开仓 = \" + DoubleToStr(ProfitNotOpenOrdersBelow,2),
\"n在该价格以下开仓 = \" + DoubleToStr(OpenOrdersBelow,5),
\"n在该价格以上开仓 = \" + DoubleToStr(OpenOrdersAbove,5),
\"n价格大于多少自动关闭 = \" + DoubleToStr(CloseUpper,5),
\"n价格小于多少自动关闭 = \" + DoubleToStr(CloseLower,5),
\"n利润大于多少自动关闭 = \" + DoubleToStr(ProfitUpper,2),
\"n利润小于多少自动关闭 = \" + DoubleToStr(ProfitLower,2));
}
}
//+------------------------------------------------------------------+
void TrailingPositions() {
double pBid, pAsk, pp;
pp = MarketInfo(OrderSymbol(), MODE_POINT);
//+------------------------------------------------------------------+
if(AccountProfit()-ProfitNotOpenOrdersAbove0){
if(OrdersTotal()=MinimumOrders){
if (OpenOrdersBelow-Ask>0){
if (OpenOrdersAbove-Bid=ProfitLockingStop*pp) {
if ((pBid-OrderOpenPrice())TrailingStop*pp) {
if (OrderStopLoss()>pAsk+TrailingStep*pp|| OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStep*pp);
}
}
return;
}
}
}
if (SetLossing){
if (OrderType()==OP_BUY) {
pBid = MarketInfo(OrderSymbol(), MODE_BID);
if ((pBid-OrderOpenPrice()) |