Without else the first block is executed first, then the second. With else - either the first or the second.
ooo! logic is missing else!) I'll change it soon! yes, and on the fly: if I write everywhere in the text not with the 4th but with the 3rd, like this:
iFractals(Symbol(),PERIOD_H1,MODE_UPPER,3);
I have no trades, although the bars to the 3rd seem to be enough for everything to work, what's the problem?
And as for the logic of the indicator, I'm a bit confused. I know how the indicator works, I just need the algorithm to ensure that ifractals is not equal to zero, and you offer me to remove this condition, it is superfluous? Why do I write it twice?
Good evening, I'm asking for help with a multicurrency MACD Expert Advisor. The EA follows the position opening criteria correctly, but closing "on condition" does not work. I have certainly started to use a trailing stop, but the correct close does not give me a break.
This is what the main part looks like
And this is a close block. Please help me to find the error!
Sorry to repeat myself, but no matter how much I struggle, I can't find the error!
//+------------------------------------------------------------------+string lSymbol;
int init ()
{
lSymbol = Symbol();
return (0);
}
int deinit()
{return(0);}
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
double 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);
Так выглядит оснавная часть, а это злопалучный блок закрытия
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)
{
if(OrderStopLoss()<bid-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))
{
if((OrderStopLoss()>(ask+point*TrailingStop)) || (OrderStopLoss()==0))
{
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.
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.
Take apart the logic of the indicator completely.
Replace it first.
at
Also,
Without else the first block is executed first, then the second. With else - either the first or the second.
I have no trades, although the bars to the 3rd seem to be enough for everything to work, what's the problem?
And as for the logic of the indicator, I'm a bit confused. I know how the indicator works, I just need the algorithm to ensure that ifractals is not equal to zero, and you offer me to remove this condition, it is superfluous? Why do I write it twice?
Take apart the logic of the indicator completely.
Replace it first.
at
In addition,
Without else the first block is executed first, then the second. With else - either the first or the second.
It is possible to fight, and the work of the EA can be interrupted. We just need to change the approach.
How?
At the beginning of the code, go through all open orders, find and assign ticket values to orders, or is there some other way?
At the beginning of the code, go through all open orders, find and assign ticket values to orders, or is there some other way?
You can do this if the EA opens one or two positions.
You can do this, as long as the advisor opens one or two positions.
The EA is multi-currency, so simple operations do not always seem to be solved at once ((. And there is no experience.
My Expert Advisor is multicurrency, and simple operations do not always seem to be solved at once ((. And there is no experience.
You just have to do the order accounting correctly. There are a lot of examples.
And experience. Experience comes with the territory. It will not go anywhere.
You just have to make sure that the orders are recorded correctly. There are plenty of examples.
And experience. Experience comes with the territory. It's not going anywhere.
Thanks for the answers, I will dig through the archives.
Good evening, I'm asking for help with a multicurrency MACD Expert Advisor. The EA follows the position opening criteria correctly, but closing "on condition" does not work. I have certainly started to use a trailing stop, but the correct close does not give me a break.
This is what the main part looks like
And this is a close block. Please help me to find the error!
Sorry to repeat myself, but no matter how much I struggle, I can't find the error!
I replaced everything, but it's still skipping the same way for some reason...((((((