Why don't you simply calculate difference between OrderClosePrice() and OrderOpenPrice()?
Note that you have to take care of sign depending on the type of the order (buy or sell).
If you really need it, commission and swap can be approximated with point values, but those don't have anything to do with points because they are usually calculated based on the order lot size.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerlot + CommissionPerLot) (Note OOP-OSL includes the SPREAD)
- Do NOT use TickValue by itself - DeltaPerlot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
- Your GetPPP is gibberish. Replace with DeltaPerLot and thus EquivalentPips = (OP+OC+OS) / OrderLots / DeltaPerLots / pips2dbl;
- Don't hard code numbers (/10)
double pips2dbl = Digits%2==0 ? Point : 10*Point;
- Your GetPPP is gibberish. Replace with DeltaPerLot and thus EquivalentPips = (OP+OC+OS) / OrderLots / DeltaPerLots / pips2dbl;
- Don't hard code numbers (/10)
I did it in following way, But it showing zero divide error.
//---------------------------------- double profit = 0; for(int cnt=0; cnt<OrdersHistoryTotal(); cnt++) { if(OrderSelect(cnt,SELECT_BY_POS, MODE_HISTORY)) { if ( TimeToStr(TimeCurrent(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE) ) { profit = profit + (OrderProfit() + OrderCommission() + OrderSwap())/OrderLots()/DeltaValuePerLot(OrderSymbol())/pips2dbl(OrderSymbol()); } } } Alert("today's profit is ",profit); //----------------------------------------------------------- double DeltaValuePerLot(string pair){ return( MarketInfo(pair, MODE_TICKVALUE) / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point. } //--------------------------------------------------------- double pips2dbl( string A) { return(MathMod(MarketInfo(A,MODE_DIGITS),2)==0 ? MarketInfo(A,MODE_POINT) : 10*MarketInfo(A,MODE_POINT)); }
Why are you adding commission and swap to your profit?
First check your code without calculating in pip.
cashcube: I did it in following way, But it showing zero divide error.
|
|
cashcube: I did it in following way, But it showing zero divide error. |
|
I added OrderType() == OP_BUY || OrderType() == OP_SELL
Now variables,
OrderProfit() + OrderCommission() + OrderSwap() = 0.93
OrderLots() = 0.01
DeltaValuePerLot(OrderSymbol()) = 947.32
pips2dbl(OrderSymbol() = 0.01
Actual Net pl is +2.7 pips. but printf results shows -9.81 along with zero divide error.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi I have this following code to count net profit in pips. But the code shows positive pips in negative & data is slightly different than original.