- Don't bother to paste ALL the code, make us guess what the datatypes are, what the functions return etc.
if(use_HA1 == true){ ha1 = HA1Control(); buyDecision = (buyDecision && (ha1 == OP_BUY)); sellDecision = (sellDecision && (ha1 == OP_SELL)); closeDesicion = (closeDesicion && (ha1 == 5)); }
What is the initial value of buyDecision, sell and close?- Simplify the code where possible.
buyDecision = (buyDecision && (ha1 == OP_BUY));
buyDecision &= (ha1 == OP_BUY);
if(buyDecision == true)
You would never say if( (2+2 == 4) == true) would you? if(buyDecision) or if (!buyDecision) is sufficient.
Your item #4 is incorrect. You have specified a bitwise operation AND assignment (&=). There is no logical assignment version (&&=).
initial values of close sell buy are true.
And bitwise operations can only be applied int data type said the compiler when I wrote
buyDecision &= (ha1 == OP_BUY);
I added my expert advisor in the attachment. I think there is a little mistake in my code. I coulndt fix it for days. If you guys can help me to fix it, I would be happiest in the world. You can find the code in the attachment.
Best Regards,
I just want to combine 4 or 3 or 2 indicators to work together.
I added my expert advisor in the attachment. I think there is a little mistake in my code. I coulndt fix it for days. If you guys can help me to fix it, I would be happiest in the world. You can find the code in the attachment.
You need to read this thread and implement what is described in it: What are Function return values ? How do I use them ?
nTicket is an int, OrderClose returns a bool . . . why are you trying to close the same order twice ?
else if(closeDesicion == true) { nTicket = OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); nTicket = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red); flag = 0; commonStatus = "CLOSE COMMON"; }
Each indicator works by ownself. When I select any of them true from expert properties. But they do not work as combine. I have no problem about close or open order in my code. (I think :))) )
I just want to combine 4 or 3 or 2 indicators to work together.
I'm sorry, but I don't understand what exactly do you expect from this code
if((OrdersTotal()==0) && (OrderType()==0)) if((OrdersTotal()==0)&& (OrderType()==1))
Can you please explain them to us ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm trying to write an EA and I want to control multiple indicators like
ind 1, ind 2, ind 3, ind 4
if, ind 1 buy and ind 2 buy ind 3 sell ind 4 buy
it should be closed.
if ind 1 buy and ind 2 buy ind 3 buy ind 4 buy
it should open buy order
if ind 1 sell and ind 2 sell ind 3 sell ind 4 sell
it should open sell order,
in other words,
I want to open buy or sell order when each indicator become same.
Otherwise I want to close.
I prepared an if conditon but it doesnt work
if(use_HA1 == true){
ha1 = HA1Control();
buyDecision = (buyDecision && (ha1 == OP_BUY));
sellDecision = (sellDecision && (ha1 == OP_SELL));
closeDesicion = (closeDesicion && (ha1 == 5));
}
if(use_HA2 == true){
ha2 = HA2Control();
buyDecision = (buyDecision && (ha2 == OP_BUY));
sellDecision = (sellDecision && (ha2 == OP_SELL));
closeDesicion = (closeDesicion && (ha2 == 5));
}
if(use_Parabolic == true){
par = parabolicControl();
buyDecision = (buyDecision && (par == OP_BUY));
sellDecision = (sellDecision && (par == OP_SELL));
closeDesicion = (closeDesicion && (par == 5));
}
if(use_BBand == true){
bband = bBandControl();
buyDecision = (buyDecision && (bband == OP_BUY));
sellDecision = (sellDecision && (bband == OP_SELL));
closeDesicion = (closeDesicion && (bband == 5));
}
if(buyDecision == true)
{
nTicket = OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"buy order",Magic,0,Green);
}
else if(sellDecision == true)
{
nTicket = OrderSend(Symbol(),OP_SELL,1,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"sell order",Magic,0,Red);
}
else if(closeDesicion == true)
{
nTicket = OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
nTicket = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
}
Each indicator works single with no problem. But when I start to combine, it cares just one indicator and it opens or closes according to just one of them.
Please Help