Download MetaTrader 5

Why CMoneySizeOptimized* fails in my code?

To add comments, please log in or register
stargazer
153
stargazer  

I have this entry function, but it keeps returning lot size=0....any guess?

//+------------------------------------------------------------------+
uint entry(string ins, ENUM_ORDER_TYPE type){
//+------------------------------------------------------------------+
   
   CMoneySizeOptimized* lotter=new CMoneySizeOptimized;
   
   lotter.Percent(Risk);
   lotter.DecreaseFactor(DecFactor);
   lotter.ValidationSettings();
   CTrade* trader=new CTrade;
   trader.SetExpertMagicNumber(eamagic);
   
    double pr=l_Price,sl=l_Loss,tp=l_Pft,Lot=0;
   double mprice,stloss,tprofit;   
   
   switch(type){
   case ORDER_TYPE_BUY: 
   mprice  =opNorm(ins,SymbolInfoDouble(ins,SYMBOL_ASK));
   stloss  =opNorm(ins,mprice - sl*SymbolInfoDouble(ins,SYMBOL_POINT));
   tprofit =opNorm(ins,mprice + tp*SymbolInfoDouble(ins,SYMBOL_POINT));
   
   Lot=lotter.CheckOpenLong(mprice,stloss);
   Lot=opNormL(ins,Lot);
   trader.Buy(Lot,ins,mprice,stloss,tprofit);  
   
    break;    
   
   case ORDER_TYPE_SELL:
   mprice   =opNorm(ins,SymbolInfoDouble(ins,SYMBOL_BID));
   stloss   =opNorm(ins,mprice + sl*SymbolInfoDouble(ins,SYMBOL_POINT));
   tprofit  =opNorm(ins,mprice - tp*SymbolInfoDouble(ins,SYMBOL_POINT)); 
   Lot=lotter.CheckOpenShort(mprice,stloss);
   Lot=opNormL(ins,Lot);
   trader.Sell(Lot,ins,mprice,stloss,tprofit); 
   break; 
To add comments, please log in or register