How to code PipsToPrice or MoneyToPrice for all instruments?

 

Hi...
I've searched through the internet and could not find what I need.

I need a function to get a Take Profit / Stop Loss price with a certain points/pips/money from my opening price for all forex pairs, metals, cryptos etc...

I tried using OrderCalcProfit as follows but it is very slow....

I've tried PipsToPrice below, but it only applies to FOREX pairs...

double PipSize(string symbol)
{
   double point = SymbolInfoDouble(symbol,SYMBOL_POINT);
   return(((SymbolInfoInteger(symbol,SYMBOL_DIGITS)%2)==1)?point*10:point);
}

double PipsToPrice(double pips, string symbol) {return(pips*PipSize(symbol));}


double Pips2Prc(string symbol,double pips){
   double profit=0,prc=SymbolInfoDouble(symbol,SYMBOL_ASK),
          result=prc;
   do{
      result+=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
      if(OrderCalcProfit(ORDER_TYPE_BUY,symbol,1,prc,result,profit) && profit>0) Print("Profit:",profit);
   }while(profit<10*pips);
   return(result-prc); 

This Pips2Prc does the job but painfully slow...

I looked at DeltaValuePerLot() from William Rhoeder but still could not understand it...

Would anybody share a better & faster function than Money2Prc() above?

Any help is greatly appreciated....


Rgds,


Herman

 

Suppose, Open price is 1.00000

Take profit in pips : 10 pips

ie Take profit in points: 100 points


So the take profit price will be :  1.00000 + ( 100 / 100000 )  = 1.00100


How do you do it in coding? sending below. 

 
Satyam Shivam #:

Suppose, Open price is 1.00000

Take profit in pips : 10 pips

ie Take profit in points: 100 points


So the take profit price will be :  1.00000 + ( 100 / 100000 )  = 1.00100


How do you do it in coding? sending below. 

Hi Satyam,

Thanks for helping....

Your example applies only to EURUSD, GBPUSD, AUDUSD,NZDUSD and some other FOREX pairs....

And it also depends on number of digits given by a broker...

What I need is a generic function that applies to all instruments such as Crypto, Index, Metal etc....

I'm sure there is such function, I just don't have enough knowledge to make it yet...

I need a function, thus from there I will be able to trace the logic behind it.

Rgds,


Herman

 

There are no universally accepted values of a pip for any instruments other than Forex.

It would be better if everyone forgot about pips and just used points.

 
Keith Watford #:

There are no universally accepted values of a pip for any instruments other than Forex.

It would be better if everyone forgot about pips and just used points.

I made one by using OrderCalcProfit() called Money2Price(string symbol, double lotsize, double money) function....

It's similar to Pips2Prc() function I posted above, but it looks at the profit using lotsize as parameters...

It iterates the price and loops until the profit of OrderCalcProfit() >= money....

It worked except it took so long because I used SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE) for increment step...

I don't know what to use to speed things up....

I hope there is the reciprocal function of OrderCalcProfit() where the return value is the price instead of the profit

Any ideas?

Rgds,


Herman

Reason: