Question about Exit (For Buy or Sell)

 

Hello: I am learning about MQL4. I would like to do this question:

1.- I can Exit, ( Buy Position ) with this statement?

If Ask > Ask + TakeProfit*Point then OrderClose(OrderTicket(),OrderLots(),Bid,3,Red)

2.- I can Exit, (Sell Position) with this statement?

If Bid < Bid + StopLoss*Point then OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow)

Thanks for your help....

Sincerely Regards.

 

Ask always is the current price for ASK. you can't use it at both side of > or < .

 

maybe this would work?


double orderprice=OrderOpenPrice();
double tp=5;
double ask = MarketInfo(Symbol(),MODE_ASK);
double hidden_tp= orderprice+tp*Point;

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(ask>=hidden_tp)

{

OrderClose(...);

}



 
23510 wrote >>

maybe this would work?

double orderprice=OrderOpenPrice();
double tp=5;
double ask = MarketInfo(Symbol(),MODE_ASK);
double hidden_tp= orderprice+tp*Point;

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(ask>=hidden_tp)

{

OrderClose(...);

}

Thanks.... Your solution is excellent!!