Hello community,
unfortunately, I'm too stupid to find out whether, and if so, how, I can achieve the following:
Suppose I have a basket of positions:
- USDCAD, Sell, 0.05 lots @1.36300
- USDCAD, Sell, 0.08 lots @1.36600
- USDCAD, Buy, 0.05 lots @1.36900
Is there a way to calculate at what price the basket as a whole would reach or exceed a certain loss, say $-250?
I would like to use the determined price as SL or TP for the individual positions in the basket in order to limit the maximum loss.
Unfortunately I'm not a math whiz and I just haven't been able to figure it out for days :(
Many thanks for your help!
- Close the first order in multiple buys or sells
- position open price and stop loss as result of many orders opened at different times
- How to Determine Take Profit Level for Multiple Trades
Holger David Julian Krause:
Non linear multiple regression is what comes to my mind to calculate this but i could be wrong but what is certain is that the relationship of all positions there is non linear. But you can implement virtual stop loss by calculating the cumulative loss on the go as new tick comes
Hello community,
unfortunately, I'm too stupid to find out whether, and if so, how, I can achieve the following:
Suppose I have a basket of positions:
- USDCAD, Sell, 0.05 lots @1.36300
- USDCAD, Sell, 0.08 lots @1.36600
- USDCAD, Buy, 0.05 lots @1.36900
Is there a way to calculate at what price the basket as a whole would reach or exceed a certain loss, say $-250?
I would like to use the determined price as SL or TP for the individual positions in the basket in order to limit the maximum loss.
Unfortunately I'm not a math whiz and I just haven't been able to figure it out for days :(
Many thanks for your help!
Sardion Maranatha #:
Non linear multiple regression is what comes to my mind to calculate this but i could be wrong but what is certain is that the relationship of all positions there is non linear. But you can implement virtual stop loss by calculating the cumulative loss on the go as new tick comes
Hi Sardion,Non linear multiple regression is what comes to my mind to calculate this but i could be wrong but what is certain is that the relationship of all positions there is non linear. But you can implement virtual stop loss by calculating the cumulative loss on the go as new tick comes
thanks for your comment. I wanted to use a broker-side SL to be on the „safe side“ in case of connection losses etc. I‘ll try to look into multiple regression, otherwise I‘ll need to go with a virtual SL.
Holger David Julian Krause #:
Hi Sardion,
Hi Sardion,
thanks for your comment. I wanted to use a broker-side SL to be on the „safe side“ in case of connection losses etc. I‘ll try to look into multiple regression, otherwise I‘ll need to go with a virtual SL.
or use interpolation, for example
calculate the cumulative profit/loss (y1) when all positions has 10 points increase, x1(10)
calculate the cumulative profit/loss (y2) when all positions has 20 points increase, x2(20)
and interpolate x3 value when y3 = -250
Holger David Julian Krause:
Hello community,
unfortunately, I'm too stupid to find out whether, and if so, how, I can achieve the following:
Suppose I have a basket of positions:
- USDCAD, Sell, 0.05 lots @1.36300
- USDCAD, Sell, 0.08 lots @1.36600
- USDCAD, Buy, 0.05 lots @1.36900
Is there a way to calculate at what price the basket as a whole would reach or exceed a certain loss, say $-250?
I would like to use the determined price as SL or TP for the individual positions in the basket in order to limit the maximum loss.
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2020, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #include <Trade\PositionInfo.mqh> CPositionInfo m_position; double TotalBasketProfit = -250; // Target total basket profit in account currency int MagicNumber = 0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { double NetCost = 0; double NetVolume = 0; double AverageOpenPrice = 0; double NetProfit = 0; for(int i = 0; i < PositionsTotal(); i++) { if(m_position.SelectByIndex(i)) { if(m_position.Magic() == MagicNumber && m_position.Symbol() == Symbol()) { NetProfit += m_position.Profit() + m_position.Swap(); if(m_position.PositionType() == POSITION_TYPE_BUY) { NetCost += m_position.PriceOpen() * m_position.Volume(); NetVolume += m_position.Volume(); } if(m_position.PositionType() == POSITION_TYPE_SELL) { NetCost -= m_position.PriceOpen() * m_position.Volume(); NetVolume -= m_position.Volume(); } } } } if(NetCost !=0 && NetVolume != 0) { AverageOpenPrice = NetCost / NetVolume; } double TickSize = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE); double TickValue = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE); double DeltaTicks = -TotalBasketProfit / (NetVolume * TickValue); double StopLossPrice = AverageOpenPrice - (DeltaTicks * TickSize); if(NetVolume > 0) { PrintFormat("Net basket: BUY %.2f lots @ %.5f", NetVolume, AverageOpenPrice); PrintFormat("Stoploss order should be: SELL %.2f lots @ %.5f", NetVolume, StopLossPrice); } if(NetVolume < 0) { PrintFormat("Net basket: SELL %.2f lots @ %.5f", MathAbs(NetVolume), AverageOpenPrice); PrintFormat("Stoploss order should be: BUY %.2f lots @ %.5f", MathAbs(NetVolume), StopLossPrice); } //--- another option: close postions when reaching profit target if(NetProfit < TotalBasketProfit) { //CloseAllPositions(Symbol()); } } //+------------------------------------------------------------------+
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