ea thread

 

if buy is true while sell is false,it will be 20 orders. if sell is true while buy is false,it will be 10 orders

the question is when buy and sell all true,ea will only do as sell is true ?

any advice?

start:

if (!ExistOrder(OP_BUY) && buy){
OpenOrder(OP_BUY);
}

if (!ExistOrder(OP_SELL) && sell){
OpenOrder(OP_SELL);

}

bool ExistOrder(int type) {

for (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {

if (OrderType()==type){

return(True);

} }}} }

return(false);

}

void OpenOrder(int type) {

string lsComm = GetCommentForOrder();

double ldLot = GetSizeLot();

double buyStop = GetStopLossBuy();

double sellStop = GetStopLossSell();

if(RealOrWarning){

int ticket=0;

if(type==OP_BUY)

ticket=OrderSend(Symbol(),OP_BUY,ldLot,NormalizeDouble(Ask,Digits),Slippage,NormalizeDouble(buyStop,Digits),0,lsComm,MAGIC,0,clOpenBuy);

if(type==OP_SELL)

ticket=OrderSend(Symbol(),OP_SELL,ldLot,NormalizeDouble(Bid,Digits),Slippage,NormalizeDouble(sellStop,Digits),0,lsComm,MAGIC,0,clCloseBuy);

}

}else{

PlaySound(BuyFileSound);

}

}

 
Please use this to post code . . . it makes it easier to read.

 
Where do the variables buy & sell get set or changed ?
 

In my early days when dealing with those types of logics, I opted to use Integer Variables. Also to make matters worse, I was making a mistake and my bools were not saving their values. Anyways, my suggestion is to try using an integer. Integers are more flexible. Example

if( Count(Op_Buy)>0 ){Integer=20;}else

if( Count(Op_Sell)>0 ){Integer=10;}else

if( Count(Op_Buy)>0 && Count(Op_Sell)>0 ){Integer=What_Ever_You_Want;}

Yeah sure bools are probably more resource friendly, but I find one usually need 2 bools for what 1 integer can do.

 
I have started using ints more recently in preference to bools in some situations for one very simple reason . . . an extern int can be used during optimization, extern bools can't.
 

i suggest to use int's and compare them with defined variables. This makes the code much more readable

 
RaptorUK:
I have started using ints more recently in preference to bools in some situations for one very simple reason . . . an extern int can be used during optimization, extern bools can't.
Don't kludge your code to get around the tester
extern int aInt_01 = 1; // tester limitation
:
bool realBool;
int init(){ realBool = aInt_01 == 1; } // aInt_01 used only here
:
if (realBool) ..
 
according to the documentation the compiler does implicit type casting so using an int as a bool should work without any intermediate conversion by the programmer
 
WHRoeder:
Don't kludge your code to get around the tester
LOL . . . what a great but simple idea . . . many thanks, yet again. :-)
 
it is not the code to be error, but i found for in for and in for loops will make system does not work well
Reason: