please convert this method

Created at 11 Jul 2014, 07:43
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RO

RootFX

Joined 09.09.2013

please convert this method
11 Jul 2014, 07:43


hi 

i have this method MQL4 

 

 

double lotsoptimized(){
   double lot;
   if(stoploss>0)lot=AccountBalance()*(risk/100)/(stoploss*pt/MarketInfo(Symbol(),MODE_TICKSIZE)*MarketInfo(Symbol(),MODE_TICKVALUE));
   else lot=NormalizeDouble((AccountBalance()/1000)*minlot*risk,lotdigits);
   //lot=AccountFreeMargin()/(100.0*(NormalizeDouble(MarketInfo(Symbol(),MODE_MARGINREQUIRED),4)+5.0)/risk)-0.05;
   return(lot);
}

pt = Symbol.PointSize*10;

but in calgo lot just int 

and i dont know how convert mql to calgo :) 

please if you can convert this method 

thank you 

 


@RootFX
Replies

modarkat
11 Jul 2014, 09:29

Here you go

/forum/cbot-support/2929


@modarkat

RootFX
11 Jul 2014, 09:55 ( Updated at: 21 Dec 2023, 09:20 )

RE:

modarkat said:

Here you go

/forum/cbot-support/2929

 

but it's work like this method 100% .? 

double lotsoptimized(){
   double lot;
   if(stoploss>0)lot=AccountBalance()*(risk/100)/(stoploss*pt/MarketInfo(Symbol(),MODE_TICKSIZE)*MarketInfo(Symbol(),MODE_TICKVALUE));
   else lot=NormalizeDouble((AccountBalance()/1000)*minlot*risk,lotdigits);
   //lot=AccountFreeMargin()/(100.0*(NormalizeDouble(MarketInfo(Symbol(),MODE_MARGINREQUIRED),4)+5.0)/risk)-0.05;
   return(lot);
}

 


@RootFX

RootFX
11 Jul 2014, 10:12 ( Updated at: 21 Dec 2023, 09:20 )

why show Long volume .?

 


@RootFX

Invalid
11 Jul 2014, 10:41 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Either case normailizedVolume to int or change return type to long

1. 

return (int)normalizedVolume;

2. 

long lotsoptimized(){

RootFX said:

why show Long volume .?

 

 


@Invalid

RootFX
11 Jul 2014, 11:40

thank you 
but Volume it's Big 
cbot show message not mony enough .! 

please try this in calgo 


@RootFX

RootFX
14 Jul 2014, 22:11

ok how edit this method 

 protected int GetVolume
        {
            get
            {
                var risk = (int)(RiskPct * Account.Balance / 100);

                int volumeOnRisk = stoploss > 0 ? (int)(risk * Symbol.Ask / (Symbol.PipSize * stoploss)) : Volume;

                double maxVolume = Account.Equity * Leverage * 100 / 101;


                double vol = Math.Min(volumeOnRisk, maxVolume);

                return (int)Math.Truncate(Math.Round(vol) / 10000) * 10000;
                // round to 10K
            }
        }

you can set RiskPct like this 1% or 2 % ... etc 

but i want calc in stoploss 


@RootFX