MQL4 - Get Price Difference between Position and current price

MQL4 Experts Scripts

Trabalho concluído

Tempo de execução 10 horas

Termos de Referência

MQL4 - Get Price Difference between Position and current price

 

Basically I want the following code

 

If i got 0 position, bool validGap = 0;

Then it open e.g UJ long at 99.00

 Now i got 1 order

UJ long at 99.00

My setting is gap 25 Points

if UJ goes to 99.25, i want to open 1 more position (add to winner)

or if UJ goes to 98.75 , I want to open 1 more position ( add to loser )

 

Take note the amount of digits or what symbol I playing need to be dynamic, no hardcoding.


My current code is something like this, however the EA keep open position despite there is no  25 * one Pip gap

 

Consider my gapTrade is value 25 

 

 double SL,TP,onePip;
 int Ticket;

onePip = 0.00;

if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) onePip = 0.0001;
else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) onePip = 0.01;
else onePip = MarketInfo(OrderSymbol(), MODE_POINT);

/***********************************/      
    
   //check if price match
   
   double currentPrice;
   currentPrice = MarketInfo(Symbol(),MODE_BID);
  
 bool validGap = false; // Initial - Not Okay.
 
  
   double minValue,maxValue,priceDiff;
   priceDiff = 0.00;
   minValue = 9999.0;
   
   for (int ii=OrdersTotal()-1 ; ii>=0 ; ii--)
   {
      if (!OrderSelect(ii,SELECT_BY_POS)) continue;
      if (OrderSymbol() == Symbol())
               if (OrderOpenPrice()  > maxValue)
               {
               maxValue = OrderOpenPrice();
               }
               if (OrderOpenPrice()  < minValue)
               {
               minValue = OrderOpenPrice();
               }
    }
   

  if(direction=="SELL")
  {
  priceDiff = currentPrice - maxValue;

  if( priceDiff > onePip*gapTrade)
  {
  validGap = true;
  }
  }
  
  if(direction=="BUY")
  {
  priceDiff =  minValue - currentPrice;
  //We use max value 
  if( priceDiff > onePip*gapTrade)
  {
  validGap = true;
  }
  }

  //Check if best trade in a buy is in profit
  /* ADD NEW POSITION TO A WINNING 1 */
  
  if(direction=="BUY")
  {
  priceDiff = currentPrice - maxValue;
  if( priceDiff > onePip*gapTrade)
  {
  validGap = true;
  }
  }

  if(direction=="SELL")
  {
  priceDiff = minValue - currentPrice;
  if( priceDiff > onePip*gapTrade)
  {
  validGap = true;
  }
  }

 

  

Respondido

1
Desenvolvedor 1
Classificação
(82)
Projetos
150
29%
Arbitragem
9
44% / 11%
Expirado
46
31%
Livre
2
Desenvolvedor 2
Classificação
(1235)
Projetos
2820
80%
Arbitragem
156
22% / 43%
Expirado
487
17%
Livre
3
Desenvolvedor 3
Classificação
(20)
Projetos
46
54%
Arbitragem
3
67% / 0%
Expirado
14
30%
Livre
4
Desenvolvedor 4
Classificação
(339)
Projetos
809
73%
Arbitragem
30
33% / 37%
Expirado
194
24%
Livre
5
Desenvolvedor 5
Classificação
(64)
Projetos
144
46%
Arbitragem
20
40% / 20%
Expirado
32
22%
Livre
6
Desenvolvedor 6
Classificação
(851)
Projetos
1462
72%
Arbitragem
122
29% / 48%
Expirado
357
24%
Trabalhando
Publicou: 3 artigos

Informações sobre o projeto

Orçamento
10 - 20 USD
Prazo
de 1 para 2 dias