Shorten a double without rounding

Back to topics list To post a new topic, please log in or register
avatar
211
Subgenius 2014.11.30 01:37
 

If I want to display the value of lot * a takeprofit value..

My lot size is more than two decimals but the order shows only 2 decimals ("0.03") which I cannot seem to get.

For instance: Takeprofit is "0.5" pips, Lotsize is "0.0368" and I 'm trying to see "TP1 Value: 0.15"

How do we do it without rounding it? Do we turn it into a string and then back into a double?

If so, this doesnt work:

input double Lots = -3.68; double NewLot=Lots;
input int LotDecimalRounded= 4;
input double TakeProfit1 = 5.0;
if(Digits==3){double SymPt=0.01;}
if(Digits==5){SymPt=0.00010;}
//balance & equity is 100.00
if(NewLot<0)
   {//if percent of equity > percent of balance then use percent of account balance else use percent of equity
   if(NormalizeDouble(AccountEquity()*(MathAbs(NewLot)*SymPt),LotDecimalRounded)>
      NormalizeDouble(AccountBalance()*(MathAbs(NewLot)*SymPt),LotDecimalRounded))
       {NewLot=NormalizeDouble(AccountBalance()*(MathAbs(NewLot)*SymPt),LotDecimalRounded);} //percent of balance
   else{NewLot=NormalizeDouble(AccountEquity()*(MathAbs(NewLot)*SymPt),LotDecimalRounded);}  //percent of equity
   if(NewLot<0.01){NewLot=0.01;}                                                             //default
   }
//NewLot is "0.0368"
if(Lots<0){string nextlotsize="Next Lot: "+NewLot+" ("+MathAbs(Lots)+"% of equity)";}
      else{nextlotsize="Next Lot: "+NewLot;}
Comment("line 1"+
"\n"+nextlotsize+
"\n"+"TP1 Value: "+StrToDouble(StringSubstr(DoubleToStr(NewLot),5,StringLen(NewLot)))*TakeProfit1
);
avatar
211
Subgenius 2014.11.30 08:10 #
 

No one?  Couldn't find an answer in the forum or anywhare in mql4.com but i've managed to find the solution!

Lot Size

https://forum.mql4.com/37352#403025

MathFloor(var1*100)/100.;
avatar
13006
WHRoeder 2014.11.30 14:10 #
 
Subgenius: My lot size is more than two decimals.  If I want to display the value of lot * a takeprofit value..
StrToDouble(StringSubstr(DoubleToStr(NewLot),5,StringLen(NewLot)))*TakeProfit1
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Post the real code, DoubleToStr - MQL4 Documentation requires two arguments, so your posted code will not even compile. I assume a typo of DoubleToStr(NewLot,5)
  3. That code is equivalent to NormalizeDouble(NewLot,5)*TakeProfit1 and since NewLot doesn't have more than five significant digits, is equivalent to just NewLot. If you "want to display the value of lot * a takeprofit value," then just do that:
    DoubleToStr(NewLot * TakeProfit1, 2); // Currency to 2 places.
  4. Your real problem is that you must normalize your NewLot to what your broker requires.
avatar
211
Subgenius 2014.12.01 00:37 #
 
WHRoeder:
  1. That code is equivalent to NormalizeDouble(NewLot,5)*TakeProfit1 and since NewLot doesn't have more than five significant digits, is equivalent to just NewLot. If you "want to display the value of lot * a takeprofit value," then just do that:
  2. Your real problem is that you must normalize your NewLot to what your broker requires.


well,

 i send NewLot normalized double in the third decimal which looks like 0.0368 and the broker opens an order with 0.03..

when i'm trying to display this 0.03 * 5 take profit it wasn't looking like 0.15 but instead 0.0368 * 5 = 0.184 and the takeprofit value was 15 cents, not 18 cents

i said i have got it resolved using math floor but using strings and normalize didnt work

im with fx choice

avatar
13006
WHRoeder 2014.12.01 14:29 #
 
Subgenius: looks like 0.0368 and the broker opens an order with 0.03..
What part of
Your real problem is that you must normalize your NewLot to what your broker requires.
was unclear?
avatar
2
abdR 2016.07.15 16:50 #
 
Subgenius:

No one?  Couldn't find an answer in the forum or anywhare in mql4.com but i've managed to find the solution!

Lot Size

https://forum.mql4.com/37352#403025

Thanks Subgenius :) Hope you don't mind me using your formula :)
avatar
13006
WHRoeder 2016.07.15 22:12 #
 
  • 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
Back to topics list  

To add comments, please log in or register