Help Function Pip Value

 

Hello, I'm very beginer in mql4 and I know nothing in C or C++. Anybody can help me to create function to get pip value each time to increase or decrease.


Example:


Entry price is 0

if (price go up for 1 pip)

Pips=1

if (price go down for 1 pip)

Pips=-1


In my code I have:


extern int TakeProfit=30;

extern int FirstTarget=20;

extern int StopLoss=30;


if(Pips>=FirstTarget)

{

Move StopLoss to breakeven

}

if(Pips>=TakeProfit)

{

Close order to take profit

}

if(Pips<=-1*StopLoss)

{

Close order to lose money

}


I would like a function then I use with this 3 types of condition.


Thank's for your help!


Pascal

 

Pascal, you want to fill Pips variable? In case you have only 1 position open you must first select the position with OrderSelect, then determine current PL with OpenPrice()-Ask/Bid (depending long or short). This PL is in form of currency move in points. To convert to Pip you must simply do Pips=PL / Point. Description is kind of theoretic but you also shared only theoretic code.

 

Is it ok if I use this code. I can't try now "weekend", the market is closed.

Thank's


int PipsVal;

int Total = OrdersTotal();

int i;

//---- Function Get Pips Values
for(i=0;i<Total;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES==true))
{
if(OrderType()==0)
{
PipsVal=Ask-OrderOpenPrice()*Point;
}
else
{
PipsVal=OrderOpenPrice()-Bid*Point;
}
}
//---- End Function
 

http://www.fx1.net/mt4tick.php

this tool makes possible to debug EAs on weekends.


Without having tried;


PipsVal=(Ask-OrderOpenPrice()) / Point;


and


PipsVal=(OrderOpenPrice()-Bid) / Point;


and

if(OrderType()==0)


this isnt very good style. OrderType can be OP_BUY OP_SELL OP_BUYLIMIT OP_SELLLIMIT etc etc. Better use


If (OrderType()==OP_BUY)....

if (OrderType()==OP_SELL)...

 
fx1.net:

http://www.fx1.net/mt4tick.php

this tool makes possible to debug EAs on weekends.


Without having tried;


PipsVal=(Ask-OrderOpenPrice()) / Point;


and


PipsVal=(OrderOpenPrice()-Bid) / Point;


and

if(OrderType()==0)


this isnt very good style. OrderType can be OP_BUY OP_SELL OP_BUYLIMIT OP_SELLLIMIT etc etc. Better use


If (OrderType()==OP_BUY)....

if (OrderType()==OP_SELL)...


 

I am using something similar to the above to obtain pips movement in an EA but when the trade closes, I still want to acccess the pip movement up or down. How can I do this when OrderClosePrice() is 0 I tried this


if(BV == 1) totval = (Bid - last_close)*100000;
if(SV == 1) totval = last_close - Bid*100000;


and after my start I put

if(last_close == 0) last_close = Bid;else if(last_close == 0 && OrderClosePrice() > 0) last_close = OrderClosePrice();


seems to work but not as accurate as the code I was using previously namely

//start pip routine
totval = 0;
for(int pos=0; pos<=OrdersTotal(); pos++)
{
if(OrderSelect(pos, SELECT_BY_POS)==true)
{
if(OrderType() == OP_BUY)
//totval = (OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( OrderSymbol(), MODE_TICKVALUE);
totval = MathRound(OrderProfit() * 10);
else if(OrderType() == OP_SELL)
totval = MathRound(OrderProfit() * 10);
//totval = (OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( OrderSymbol(), MODE_TICKVALUE);
}}
//end pip routine


trouble is the above stops output as soon as the trade closes, I want it to still output thye pip movement value

Reason: