Download MetaTrader 5
To add comments, please log in or register
Do you often publish source codes? Find out how to do that correctly!
geroge_jhon
13
geroge_jhon 2016.05.16 18:10 

Hey all the readers!

My programming skills are not that much good so i needed help.My problem is that

i have placed two orders one is pending order and one is market order . i want that when market order reaches at its take profit value or price level reaches to take profit level of market order than pending order must be deleted. My main problem is that how can i check that market order price has been reached to its take profit or not.

i have tried certain condition but none work so i requested all readers for help.

I will be very thankful  if any one can help me .

Fernando Carreiro
1523
Fernando Carreiro 2016.05.16 19:38  

Instead of posting an image, it might be best to post actual code (even if just for a small section) so that users here can offer code corrections or suggestions. You can use the SRC button to place your source code (or attach the file it if it is large).

geroge_jhon
13
geroge_jhon 2016.05.16 19:42  
FMIC:

Instead of posting an image, it might be best to post actual code (even if just for a small section) so that users here can offer code corrections or suggestions. You can use the SRC button to place your source code (or attach the file it if it is large).

Thanks for advising me
void OnStart()
  {   
if(rsi() ) // Order is placed on certain condition
 {
ordersendsell();   // market sell order
pendingsellorder0(); // pending sell limit order
if(OrderSelect(tickets, SELECT_BY_TICKET))  // market order has been selected  
  {    
  if ( condition i needed  )   // condition for checking price level and take profit value      
          
          
          {
          deleteallpendingorders2();
          }

  }
 }
}  
Fernando Carreiro
1523
Fernando Carreiro 2016.05.16 20:22  

Assuming that the Market Order always has a take-profit and a stop-loss defined, you can detect when an order has reached one of its targets and closed when the "OrderCloseTime()" function is not "0". You can then detect if it was closed in profit or in loss by using the "OrderProfit()".

void OnTick()
{   
   if( rsi() ) // Order is placed on certain condition
   {
      ordersendsell();   // market sell order
      pendingsellorder0(); // pending sell limit order
      if( OrderSelect( tickets, SELECT_BY_TICKET ) )  // market order has been selected  
      {    
         if( OrderCloseTime() > 0 ) // Check if Order has been closed
         {
            if( OrderProfit() > 0 ) // Check if Order was closed in Profit
               deleteallpendingorders2();
         }
      }
   }
}

Alternatively, you can also use the "OrderClosePrice()" to detect if a certain price level has been reached. The function "OrderClosePrice()" works for both open market orders and closed orders. When closed "( OrderCloseTime() > 0 )", this function gives the price at which the order was closed at, but when the order is open "( OrderCloseTime() == 0 )", it gives the current price for the order ("bid" for Buy Order and "ask" for Sell Order).

WARNING! "OnStart()" is for Scripts and not EA's so consider using the following layout:

#property strict

int OnInit()
{
   // ...
   return( INIT_SUCCEEDED );
}

void OnTick()
{   
   // ...
}
geroge_jhon
13
geroge_jhon 2016.05.16 20:52  
FMIC:

Assuming that the Market Order always has a take-profit and a stop-loss defined, you can detect when an order has reached one of its targets and closed when the "OrderCloseTime()" function is not "0". You can then detect if it was closed in profit or in loss by using the "OrderProfit()".

Alternatively, you can also use the "OrderClosePrice()" to detect if a certain price level has been reached. The function "OrderClosePrice()" works for both open market orders and closed orders. When closed "( OrderCloseTime() > 0 )", this function gives the price at which the order was closed at, but when the order is open "( OrderCloseTime() == 0 )", it gives the current price for the order ("bid" for Buy Order and "ask" for Sell Order).

WARNING! "OnStart()" is for Scripts and not EA's so consider using the following layout:

Thanks for your help . I hope that this would work fine else i will write my problem.

And again thanks  for helping.

geroge_jhon
13
geroge_jhon 2016.05.17 07:37  
geroge_jhon:

Thanks for your help . I hope that this would work fine else i will write my problem.

And again thanks  for helping.

i tried this on different time frames and on different charts  but it does not work .

any solution

Fernando Carreiro
1523
Fernando Carreiro 2016.05.17 08:38  
geroge_jhon:

i tried this on different time frames and on different charts  but it does not work .

any solution

"Does not work" has no meaning (to quote what WHRoeder usually says). You have to explain what you expect to happen and what did happen. We cannot read you mind!

If you really want us to help, you have to show us your "real" and "actual" code. All you provided was a sample section. Without knowing how it all fits and works, we can only point you in a direction and offer some guidance.

Without the actual code, I am unable to provide an exact solution. I gave you two possible alternatives - one based on "OrderProfit()" and another on "OrderClosePrice()". Obviously it seems you took the easy way and just did a copy/paste and hoped it would work on the first go.

/
To add comments, please log in or register