Hi, I've redesigned the standard Macd Sample EA, adding multicurrency capabilities. The problem is that even though it opens trades as multicurrency, it only closes them on profit or trailing stop - although closing after changing the condition is also written in the EA. I am asking for help from our community :)
//+------------------------------------------------------------------+//| 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.
Guys, can you tell me how to deal with this, before everything was fine - reports were saved in opera... Now it's throwing up in the window when trying to save a strategy tester report.
Problem solved. Figured it out. My computer started opening html files with wordpress for some reason... I converted to opera - everything works as it should.
How to correct the "tradingexpert.mq4" EA from MQL4 tutorial. If I wanted to open a new order in that direction, and the EA would be waiting for a signal from the indicator to open in the opposite direction.
I was told to use the function aka KimIV - "GetTypeLastClosePos()". I tried to apply it, but trades are not opening. Please advise how to correct the EA. Here is the code with my changes highlighted in red.
Guys, can you tell me how to deal with this, before everything was fine - reports were saved in opera... Now it's throwing up in the window when trying to save a strategy tester report.
Problem solved. Figured it out. My computer started opening html files with wordpress for some reason... I converted to opera - everything works as it should.
Maybe your html files are opened with notepad by default? try looking in the control panel under the default program tab
and i wonder who is telepathically answering me ;)
maybe in the code it is necessary to add a condition that the account is a demo
I got the hint, but i can't show you the code.
Then the only advice I can give you is to put Prints in all the potentially problematic places, and give us the logs of the non-trading EA. Unless, of course, you can figure out the prints yourself.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Guys, can you tell me how to deal with this, before everything was fine - reports were saved in opera... Now it's throwing up in the window when trying to save a strategy tester report.
Problem solved. Figured it out. My computer started opening html files with wordpress for some reason... I converted to opera - everything works as it should.
Good afternoon. Please advise a newbie.
How to correct the "tradingexpert.mq4" EA from MQL4 tutorial. If I wanted to open a new order in that direction, and the EA would be waiting for a signal from the indicator to open in the opposite direction.
I was told to use the function aka KimIV - "GetTypeLastClosePos()". I tried to apply it, but trades are not opening. Please advise how to correct the EA. Here is the code with my changes highlighted in red.
Guys, can you tell me how to deal with this, before everything was fine - reports were saved in opera... Now it's throwing up in the window when trying to save a strategy tester report.
Problem solved. Figured it out. My computer started opening html files with wordpress for some reason... I converted to opera - everything works as it should.
Maybe your html files are opened with notepad by default? try looking in the control panel under the default program tab
Please advise how to write the condition "if the last closed order type was OP_BUY" in MQL4.
Please advise, I have written an EA, no errors, in the Strategy Tester it tests, but it won't trade on a demo account. What is the problem?
For such questions there is a special branch)))
aha x ))))))
I wonder who is telepathically answering me ;)
Maybe you need to add some condition to the code, that the account is a demo
I got your hint, but the code, unfortunately, can not put it out (
aha x ))))))
and i wonder who is telepathically answering me ;)
maybe in the code it is necessary to add a condition that the account is a demo
I got the hint, but i can't show you the code.