Download MetaTrader 5
To add comments, please log in or register
Publish the program in the Market and sell it to millions of traders!
Gouveiaa
123
Gouveiaa 2016.09.02 16:30 
Hi, so instead of putting a Take profit in points, I used another expression
if(LongPositionOpen() == true && rate[1].close > BBMidle[1])
      {
             trade.PositionClose(_Symbol);
      }
And I have this, I have no Take Profit, but I have a Stop Loss
 if(!PositionSelect(_Symbol))
   { 
      
      request.action = TRADE_ACTION_DEAL;               // Immediate order execution
      request.price = NormalizeDouble(ask,_Digits);     // Lastest Ask price
      request.symbol=position_symbol;
      request.sl = NormalizeDouble(ask - STP*_Point,_Digits);                            // Stop Loss
      request.tp = 0;                          // Take Profit
      request.symbol = _Symbol;                         // Symbol
      request.volume = Lot;                             // Number of lots to trade
      request.magic = 0;                                // Magic Number
      request.type = ORDER_TYPE_BUY;                    // Buy Order
      request.type_filling = ORDER_FILLING_FOK;         // Order execution type
      request.deviation=5;                              // Deviation from current price
      return(OrderSend(request,result));               // Send order

      
   } 
The expert recognizes the Stop Loss but the position, when open, doesn't close when
rate[1].close > BBMidle[1])

Can someone help me? Regards

Pedro Quina
57
Pedro Quina 2016.09.03 03:28  
Gouveiaa:
Hi, so instead of putting a Take profit in points, I used another expression And I have this, I have no Take Profit, but I have a Stop LossThe expert recognizes the Stop Loss but the position, when open, doesn't close when

Can someone help me? Regards

Hi 

 

   Try this

 

PositionSelect(_Symbol);
if(LongPositionOpen() == true && rate[1].close > BBMidle[1])
      {
             trade.PositionClose(_Symbol); 

      } 

Gouveiaa
123
Gouveiaa 2016.09.03 10:17  
PedroQuina:

Hi 

 

   Try this

 

      } 

Can't do that, I have my fuction like this
bool LongPositionOpen()
 {
   
   MqlTradeRequest request;                             // Will be used for trade requests
   MqlTradeResult result;                               // Will be used for results of trade requests

   ZeroMemory(request);
   ZeroMemory(result);
   
   double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   string position_symbol=PositionGetString(POSITION_SYMBOL);
   double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
   double sl=PositionGetDouble(POSITION_SL);  // Stop Loss of the position
   ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
   
   
   if(!PositionSelect(_Symbol))
   { 
      
      request.action = TRADE_ACTION_DEAL;               // Immediate order execution
      request.price = NormalizeDouble(ask,_Digits);     // Lastest Ask price
      request.symbol=position_symbol;
      request.sl = NormalizeDouble(ask - STP*_Point,_Digits);                            // Stop Loss
      request.tp = 0;                          // Take Profit
      request.symbol = _Symbol;                         // Symbol
      request.volume = Lot;                             // Number of lots to trade
      request.magic = 0;                                // Magic Number
      request.type = ORDER_TYPE_BUY;                    // Buy Order
      request.type_filling = ORDER_FILLING_FOK;         // Order execution type
      request.deviation=5;                              // Deviation from current price
      return(OrderSend(request,result));               // Send order

      
   } 
   
   return (false);
   
   }
Gouveiaa
123
Gouveiaa 2016.09.05 20:11  
Anyone?
/
To add comments, please log in or register