My EA needs a close script

 

Hello guys, i have an EA that does not close trades when the opposite parameter is met.

Need help from programmers on what i should do.


Thanks guys.

 
shilox:

i have an EA that does not close trades when the opposite parameter is met.

What does that mean? Please explain.

 
gordon:

What does that mean? Please explain.

Its a Moving Average EA, with TP and SL as usual for a proper EA, but the problem is when the MA recrosses it doesnt exit trade.

 
 
shilox:

Its a Moving Average EA, with TP and SL as usual for a proper EA, but the problem is when the MA recrosses it doesnt exit trade.

Well that's very nice, but you are asking a general question about code that we can't see.

Try to pinpoint your problem (problem with order close loop? problem with close signal logic? etc.) and post the relevant code here.

 
gordon:

Well that's very nice, but you are asking a general question about code that we can't see.

Try to pinpoint your problem (problem with order close loop? problem with close signal logic? etc.) and post the relevant code here.

Attached is the EA. Thanks.

Files:
pipjhound.mq4  10 kb
 
      
    for(cnt = OrdersTotal(); cnt >= 0; cnt--)
       {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);       
       if(OrderSymbol() == symbol && OrderMagicNumber()==Magicbuy) 
         {
         ticketbuy=OrderTicket();OrderSelect(ticketbuy, SELECT_BY_TICKET, MODE_TRADES);
         lotsbuy2=OrderLots() ;
  
There is no orderSelect(OrdersTotal()) If you have one (1) order you can only orderSelect(0). You are not checking the return code from order select. Why are you selecting by ticket when you already selected by position?
for(int index = OrdersTotal() - 1; index >= 0; index--) if (
	OrderSelect(index, SELECT_BY_POS)			// Only my orders w/
&&	OrderMagicNumber()	== MagicNumber + Period.index	// my magic number
&&	OrderSymbol()		== Symbol() ) {			// and period and symbol
There is no difference between OrdersTotalMagicbuy and the sell version except for dxPoint and that code should be in Init:
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int init() {
    if (Digits == 5 || Digits == 3) {   // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0;
    }

On a 5 digit broker your slippage of 3 should be 3*pips2points. Check your OrderClose() for errors and add Print() statements.

As for your original question, when the stochastics say to buy, where to you call orderclosesell?

 
WHRoeder:
There is no orderSelect(OrdersTotal()) If you have one (1) order you can only orderSelect(0). You are not checking the return code from order select. Why are you selecting by ticket when you already selected by position? There is no difference between OrdersTotalMagicbuy and the sell version except for dxPoint and that code should be in Init:

On a 5 digit broker your slippage of 3 should be 3*pips2points. Check your OrderClose() for errors and add Print() statements.

As for your original question, when the stochastics say to buy, where to you call orderclosesell?

I really couln't and cant continue beyond this point where i have posted this.


Could you compile it like you are saying?


Thanks!

Reason: