Download MetaTrader 5

Cannot detect value of Profit

To add comments, please log in or register
Shaharudin Ahmad
934
Shaharudin Ahmad  

Hi,

I trying the get the value of negatif profit using POSITION_PROFIT but the result show the positif value.

 

//+------------------------------------------------------------------+
//|                                                           rt.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 int ii;
 for(ii=0;ii<PositionsTotal();ii++)
     
          {
                       
          PositionSelect(PositionGetSymbol(ii));
          if(PositionGetSymbol(ii)==_Symbol)
            {
              if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetDouble(POSITION_PROFIT)<=-300)
              {
              Print("Profit Now ",POSITION_PROFIT);
              }     

            }
          }
 
  }
//+------------------------------------------------------------------+

 

But the result

2013.03.12 13:37:12 rt (EURUSD,M30) Profit Now 10

Anybody can tell me what wrong? or my coding wrong?

tq 

Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
jelam:

Hi,

I trying the get the value of negatif profit using POSITION_PROFIT but the result show the positif value.

 But the result

2013.03.12 13:37:12 rt (EURUSD,M30) Profit Now 10

Anybody can tell me what wrong? or my coding wrong?

tq 

Shouldn't it be this ?

Print("Profit Now ", PositionGetDouble(POSITION_PROFIT) );
Pasi Hakamaki
6326
Pasi Hakamaki  
RaptorUK:

Shouldn't it be this ?

I believe RaptorUK is correct. Strange thought that POSITION_PROFIT initializes as 10 :)

Br, Candles

EDIT: OK, all of the ENUM_POSITION_PROPERTY_DOUBLE have initial integer  values. Probably has some deeper meaning which I cannot understand :)

My apologies for the OT.

Alain Verleyen
Moderator
33339
Alain Verleyen  
Candles:

I believe RaptorUK is correct. Strange thought that POSITION_PROFIT initializes as 10 :)

Br, Candles

EDIT: OK, all of the ENUM_POSITION_PROPERTY_DOUBLE have initial integer  values. Probably has some deeper meaning which I cannot understand :)

My apologies for the OT.

POSITION_PROFIT is from an ENUM and is an integer constant.

PositionGetDouble(POSITION_PROFIT) is a function that return a double and take an ENUM (integer with limited dataset) as parameter.

Nothing with "some deeper meaning" here.

Shaharudin Ahmad
934
Shaharudin Ahmad  
RaptorUK:

Shouldn't it be this ?

Thank RaptorUK for your advise. It work now.

To add comments, please log in or register