Except that
I want to calculate profit before the price comes to profit.
For example,
1. long L0.1 1.3580
2. long L0.1 1.3570
3. long L0.1 1.3560
4. long L0.2 1.3550
current price is = 1.3551 if I use AccountProfit()>=10$ price close all in current price is = 1.3565
but
I wont calculate price close all (1.3565) when current price is = 1.3551 (and OrderModify() 1.2.3.4. TP = 1.3565)
please help
You have to calculate at what TP will all open positions combined create a profit of $10.
not compiled not tested double computeTP(double profitWanted){ double perLotPerPoint = PointValuePerLot(), TP=Bid; for (int itt=5; itt>0; itt--){ int oo.count = 0; double oo.lots = 0, proftAtTP = 0; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) ){ // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and period and symbol if (oo.count==0){ // One time init. if (OrderType() == OP_BUY){ open.to.Bid = Bid-Ask; // Open at Ask. stop.to.Bid = 0; // Stop at Bid. DIR = +1.; } else { open.to.Bid = 0; // Open at Bid. stop.to.Bid = Bid-Ask; // Stop at Ask. DIR = -1.; } } oo.count++; double oo.price = OrderOpenPrice(), oo.size = OrderLots(); pips = (TP+stop.to.Bid) - (oo.price+open.to.Bid), profAtTP = pips * DIR * oo.size / perLotPerPoint; oo.lots += oo.size; profitAtTP += profAtTP; } TP += DIR*(profitWanted-profitAtTP)/(totalLots*perLotPerPoint) * 0.95; } return(TP); } double PointValuePerLot() { // Value in account currency of a Point of Symbol. /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147) * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip. * IBFX demo/mini EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000 * IBFX demo/standard EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000 * $1.00/point or $10.00/pip. * * https://www.mql5.com/en/forum/127584 CB: MODE_TICKSIZE will usually return the * same value as MODE_POINT (or Point for the current symbol), however, an * example of where to use MODE_TICKSIZE would be as part of a ratio with * MODE_TICKVALUE when performing money management calculations which need * to take account of the pair and the account currency. The reason I use * this ratio is that although TV and TS may constantly be returned as * something like 7.00 and 0.00001 respectively, I've seen this * (intermittently) change to 14.00 and 0.00002 respectively (just example * tick values to illustrate). */ return( MarketInfo(Symbol(), MODE_TICKVALUE) / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point. }
HI
thaks for reply
I add modifications becose is not compilet:
After my modifications is a lot error (bactest) log:
2011.01.21 17:51:53 TestGenerator: unmatched data error (volume limit 127 at 2011.01.14 20:30 exceeded)
what I did wrong?
double computeTP(double profitWanted) { double perLotPerPoint = PointValuePerLot(), TP=Bid; double stop.to.Bid,open.to.Bid,profitAtTP,totalLots,pips,profAtTP; int DIR; for (int itt=5; itt>0; itt--) { int oo.count = 0; double oo.lots = 0, proftAtTP = 0; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) { if (OrderSelect(pos, SELECT_BY_POS) ) { // Only my orders w/ if( OrderMagicNumber() == 0 // my magic number && OrderSymbol() == Symbol()) { // and period and symbol if (oo.count==0) { // One time init. if (OrderType() == OP_BUY) { open.to.Bid = Bid-Ask; // Open at Ask. stop.to.Bid = 0; // Stop at Bid. DIR = +1.; } else { open.to.Bid = 0; // Open at Bid. stop.to.Bid = Bid-Ask; // Stop at Ask. DIR = -1.; } } } } oo.count++; double oo.price = OrderOpenPrice(), oo.size = OrderLots(); pips = (TP+stop.to.Bid) - (oo.price+open.to.Bid); profAtTP = pips * DIR * oo.size / perLotPerPoint; oo.lots += oo.size; profitAtTP += profAtTP; } TP += DIR*(profitWanted-profitAtTP)/(totalLots*perLotPerPoint) * 0.95; } return(TP); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I need help writing function.
How to use MQL to calculate static TP for all open positions so that Tp was set price to Profit 10 pips or 10$?