Total SL amount or TP amount depending on given Horizontal line price

 

hi guys I'm trying to make a label on my EA that will display the possible loss amount of my current open multiple sell orders. I have a horizontal line that will give the price, the price that was given by the horizontal line is will be used as Stop Loss price on my formula that will compute my total loss of all my open sell orders. My problem is the Stop loss amount label is not displaying the right amount. Below are the codes I used.

this is the code that i used to get the price. I have no problem on this code, it gives the right price.

StopLossLine = DoubleToStr(ObjectGetDouble(0,"Stop Loss Line",OBJPROP_PRICE),Digits);  


im having problem on this code the one that computes the amount that will be displayed. Why am i getting a different amount? hmm. thanks guys

double LossPerTradeOnSell; 
double TotalLossOFAllSell = 0;

for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
      {     

 if(OrderType() == OP_SELL && OrderMagicNumber()== MagicNumberSellOrder)  
              LossPerTradeOnSell = (((MarketInfo(Symbol(), MODE_TICKVALUE) * OrderLots() * ((OrderOpenPrice()-StopLossLine)/pips))*pips)/ticksize);  
              TotalLossOFAllSell += LossPerTradeOnSell ;    
        
        
                                                               
      }       
}
 
mark692:

hi guys I'm trying to make a label on my EA that will display the possible loss amount of my current open multiple sell orders. I have a horizontal line that will give the price, the price that was given by the horizontal line is will be used as Stop Loss price on my formula that will compute my total loss of all my open sell orders. My problem is the Stop loss amount label is not displaying the right amount. Below are the codes I used.

this is the code that i used to get the price. I have no problem on this code, it gives the right price.


im having problem on this code the one that computes the amount that will be displayed. Why am i getting a different amount? hmm. thanks guys

It should be like Lots * SLinpoints*ticksize
 
Daniel Cioca #:
It should be like Lots * SLinpoints*ticksize
Oh thats the formula? Ok ill try that.
 

Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk. Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

  1. 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.

  2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP but it takes account of the exchange rates of the pair vs. your account currency.)

  3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
              Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
              Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

  4. You must normalize lots properly and check against min and max.

  5. You must also check FreeMargin to avoid stop out

  6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

 
Daniel Cioca #:
It should be like Lots * SLinpoints*ticksize

this is what i used 

for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
      {   
if(OrderSymbol()==Symbol() && OrderType() == OP_SELL)
TotalProfitofAllTPSell  += OrderLots()*((OrderOpenPrice()-OrderStopLoss())/pips)*ticksize;

     }       
}

and it works thank you for the idea :)