//+------------------------------------------------------------------+//| MACD Sample_1.mq4 |//| Corp. |//| http:// |//+------------------------------------------------------------------+externdouble Lots = 0.1;
externdouble TrailingStop = 50;
externdouble MACDOpenLevel=3;
externdouble MACDCloseLevel=2;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+string lSymbol;
int init(){lSymbol=Symbol(); return(0);}
int deinit(){return(0);}
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent; //значения индикаторовdouble SignalPrevious,bid,ask,point,digits;
int cnt, ticket, total; //вычисляемые значения
total=SymbolOrdersTotal(lSymbol);
if(total<1)
{
bid = MarketInfo(lSymbol,MODE_BID);
ask = MarketInfo(lSymbol,MODE_ASK);
point = MarketInfo(lSymbol,MODE_POINT);
digits= MarketInfo(lSymbol,MODE_DIGITS);
// on a chart of less than 100 barsif(Bars<100)
{
Print("bars less than 100");
return(0);
}
// to simplify the coding and speed up access// data are put into internal variables
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
// no opened orders identifiedif(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibilityif(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<=SignalPrevious &&
MathAbs(MacdCurrent)>(MACDOpenLevel*point) )
{
ticket=OrderSend(lSymbol,OP_BUY,Lots,ask,3,0,0,"macd sample new",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()," as ", lSymbol);
}
elsePrint("Error opening BUY order :",GetLastError()," as ", lSymbol);
return(0);
}
// check for short position (SELL) possibilityif(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>=SignalPrevious &&
MacdCurrent>(MACDOpenLevel*point) )
{
ticket=OrderSend(lSymbol,OP_SELL,Lots,bid,3,0,0,"macd sample new",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()," as ", lSymbol);
}
elsePrint("Error opening SELL order : ",GetLastError()," as ", lSymbol);
return(0);
}
return(0);
}
// it is important to enter the market correctly, // but it is more important to exit it correctly... for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==lSymbol) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>=SignalPrevious &&
MacdCurrent>(MACDCloseLevel*point))
{
OrderClose(OrderTicket(),OrderLots(),bid,3,Violet); // close positionreturn(0); // exit
}
// check for trailing stopif(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
else// go to short position
{
// should it be closed?if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
MacdPrevious<=SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*point))
{
OrderClose(OrderTicket(),OrderLots(),ask,3,Violet); // close positionreturn(0); // exit
}
// check for trailing stopif(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
return(0);
}
int SymbolOrdersTotal(string lSymbol)
{
int Res=0;
int total=OrdersTotal();
for (int i=0;i<total;i++)
{
if (OrderSelect(i, SELECT_BY_POS))
{
if (OrderSymbol()==lSymbol)
{
Res++;
}
}
}
return(Res);
}
// the end.
伙计们,你们能告诉我如何处理这个问题吗?以前一切都很好--报告被保存在opera...现在,当试图保存一份策略测试员报告时,它在窗口中抛出了。
问题解决了。弄明白了。我的电脑由于某种原因开始用wordpress打开html文件...我转换为歌剧--一切都在正常工作。
下午好。请为一个新手提供建议。
如何纠正MQL4教程中的 "tradingexpert.mq4 "EA。如果我想在那个方向开一个新的订单,而EA将等待指标的信号,在相反的方向开仓。
我被告知要使用KimIV这个函数--"GetTypeLastClosePos()"。我试图应用它,但交易没有打开。请告知如何纠正该EA。下面是代码,我的改动用红色标出。
伙计们,你们能告诉我如何处理这个问题吗?以前一切都很好--报告被保存在opera...现在,当试图保存一份策略测试员报告时,它在窗口中抛出了。
问题解决了。弄明白了。我的电脑由于某种原因开始用wordpress打开html文件...我转换为歌剧--一切都在正常工作。
也许你的HTML文件默认是用记事本打开的? 试着在控制面板的默认程序标签下找找看
请告知如何在MQL4中编写 "如果最后关闭的订单类型是OP_BUY "条件。
请指教,我写了一个EA,没有错误,在策略测试器中测试,但在模拟账户上不能交易。问题是什么?
对于这样的问题,有一个专门的分支))))。
aha x ))))))
我想知道谁在用心灵感应我;)
也许你需要在代码中添加一些条件,即该账户是一个演示账户。
我得到了你的提示,但代码,不幸的是,不能把它放出来(
aha x ))))))
我想知道谁在用心灵感应我;)
也许在代码中,有必要添加一个条件,即账户是模拟的。
我得到了提示,但我不能给你看代码。