If you're looking for the total pips the basket have gain/lost then you're probably going about it the hard way. Here I'll give you a few of my function, hopefully you know how to use functions. If you're looking for something else like total_profit [with/without commissions], or total_points, or total x-currency value then please clarify.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int PipCntBuyOpn(){ int Res=0, Sign=0; for(int i=OrdersTotal()-1; i>=0; i--){ if(!OrderSelect(i,SELECT_BY_POS)){continue;} if(OrderMagicNumber()!=SystemMagic1){continue;} if(OrderSymbol()!=CurSetSymbol){continue;} if(OrderType()!=OP_BUY){continue;} double Oop=OrderOpenPrice(); double Ocp=OrderClosePrice(); int DifIntPip=p2i(MathAbs(Oop-Ocp)); double P=OrderProfit()+OrderCommission()+OrderSwap(); if(P>0){Sign=1;}else{Sign=-1;} Res+=(DifIntPip*Sign); } return(Res); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int PipCntSelOpn(){ int Res=0, Sign=0; for(int i=OrdersTotal()-1; i>=0; i--){ if(!OrderSelect(i,SELECT_BY_POS)){continue;} if(OrderMagicNumber()!=SystemMagic1){continue;} if(OrderSymbol()!=CurSetSymbol){continue;} if(OrderType()!=OP_SELL){continue;} double Oop=OrderOpenPrice(); double Ocp=OrderClosePrice(); int DifIntPip=p2i(MathAbs(Oop-Ocp)); double P=OrderProfit()+OrderCommission()+OrderSwap(); if(P>0){Sign=1;}else{Sign=-1;} Res+=(DifIntPip*Sign); } return(Res); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int p2i(double X){ /*Pip2Int or Price2Int*/ if(StringFind(CurSetSymbol,"JPY")>-1 || StringFind(CurSetSymbol,"XAG")>-1 || StringFind(CurSetSymbol,"XAU")>-1 ){ double Pips=0.01;}else{Pips=0.0001; } return(X/Pips); }
PipCntBuyOpn: Sums-up the total Pips [again its Pips not Point]. Pip_Count_Buy_Open.Orders.
mrmedia:
a) basketpips profit
b) basketpips breakeven point
- profit you already have.
ProfitB += OrderProfit() + OrderCommission() + OrderSwap();
- breakeven point is just lots weighted open price. Sum( OrderOpenPrice() * OrderLots() ) / Sum( OrderLots() )
- I renamed/modified PointValuePerLot:
double PipValuePerLot(string pair=""){return(DeltaValuePerLot(pair)*pips2dbl);} double DeltaValuePerLot(string pair=""){ if(pair == "") pair = Symbol(); //{Value in account currency of a Point of Symbol. // In tester I had a sale: open=1.35883 close=1.35736 (0.0147) // 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.0/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.0001 respectively, I've seen this (intermittently) change // to 14.00 and 0.0002 respectively (just example tick values to illustrate). // https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30: // MarketInfo(pair,MODE_TICKSIZE) returns 0.5 // MarketInfo(pair,MODE_DIGITS) return 1 // Point = 0.1 // Prices to open must be a multiple of ticksize //} return( MarketInfo(pair, MODE_TICKVALUE) / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point. }
As the comment says, do NOT use TICKVALUE by itself.// openpipsLongE += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()* // ((OrderClosePrice()-OrderOpenPrice())/PointValuePerLot()); openpipsLongE += ( OrderClosePrice()-OrderOpenPrice() ) * OrderLots() * DeltaPerLot();
for (int i = OrdersTotal() - 1; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
If the OrderSelect fails, so does everything below. What are Function return values ? How do I use them ? - MQL4 forum
Trying to put some meaning to it...
The brokers may have set a fixed value to each point movement but the calculator suggests its all
dynamic.
If 2xbuy and 4xsell that is net 2xsell.
I saw in i-Breakeven that it uses 'net'.
codebase.mql4.com/1097
If in the 'pipcalc' the result "Price of pip" = 20.00, that is what the exposure is up and down.
input 200000 net position size, choice base, input current.. etc. etc.
And i know that OrderProfit() + OrderCommission() + OrderSwap() = 880.00
So it must be 44pips.
which is approx (lots()*OOP-OCP - lots()*OCP-OOP)
(Maybe
....since in backtester you need a value for
usdjpy whilst trading audjpy - so you can calc MODE_TICKVALUE
you might use this
string pipFactor[] = {"SILVER","GOLD","AUDJPY","AUDUSD","GBPJPY","GBPCHF","EURAUD","EURJPY","EURCHF","EURGBP","USDCAD","USDJPY","USDCHF","GBPUSD","EURUSD","NAS100","CAC400"}; double pipFactors[] = { 5.000, 1.00, 1.020, 1.00000, 1.020, 1.07470, 0.90603, 1.020, 1.07470, 1.52538, 0.97154, 1.020, 1.07470, 1.00000, 1.00000, 1, 1};
No code yet but I want to ask the question
Exiting at $800 profit or 40pips .... why use pips?
Basketdollar vs basketpip. They ought to equal if you did the code right.
Though I guess if you target 20pips exit - the dollar amount will vary from instrument to instrument.
So maybe useful if reporting results in $ or pnt or pip depending on your liking.
assuming
void point2(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } }
ok here's the problem ... if tp at 20points and trail 50points it can be calculated as 87.124+10points-50points = 87.084 trailing stop but in dollars 87.124+$20-$50 = ?????
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
I think PointValuePerLot() is actually probably useful in lot size calcs - so it is probably being used incorrectly
Maybe part1 is accounting for commission so might be doing what i need.