close order conditions

 

Hello all!


I hope someone can help me.

Following the close conditions from my EA.

I want to close the trade after becoms 25 ticks under opening price, but i cant programming because i'm a stupid beginner.....


Who can help me?


Thank you so much for help!!!


Best regards


dsl



void CheckForClose()
  {
   double ma;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Open[1]<ma) //OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]>ma)  //OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }
 
dsl2911:

Hello all!

I want to close the trade after becoms 25 ticks under opening price, but i cant programming because i'm a stupid beginner.....

You mean 25 pips under opening price? Do you want this for sell (takeprofit) or for buy (stoploss)?

 
gordon:

You mean 25 pips under opening price? Do you want this for sell (takeprofit) or for buy (stoploss)?

Hi Gordon!


It shout be an stoploss!


Buy: close 25 pips or more under the open

Sell: close 25 pips or more over the open


Thank you for your fast answer!


Werner

 
dsl2911 wrote >>

Hi Gordon!

It shout be an stoploss!

Buy: close 25 pips or more under the open

Sell: close 25 pips or more over the open

Thank you for your fast answer!

Werner

Sell: double Ps=(OrderOpenPrice()-OrderClosePrice())/Point;

Buy: double Pb=(OrderClosePrice()-OrderOpenPrice())/Point;

if Ps<-25 Close Sell

if Pb < -25 Close Buy

 

Try this out...

void CheckForClose()
  {
   double ma;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      RefreshRates();
      if(OrderType()==OP_BUY)
        {
         if(Open[1]<ma) 
            if(Bid < OrderOpenPrice() - 25*Point)
               OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]>ma)  
            if(Ask > OrderOpenPrice() + 25*Point)
               OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }

Just note that it's 25 points from the open price, so you should probably add spread to those 25 points...

 

Hi EADeveloper!


Thank you for Help!

It works!


Happy Trades at all!



Werner



 
gordon:

Try this out...

Just note that it's 25 points from the open price, so you should probably add spread to those 25 points...

Hi Gordon!



Thank you for Help!

It works!


Happy Trades at all!



Werner


Now i have two ways!