How do i calculate LotSize right ?

 
//+------------------------------------------------------------------+
//|                                                      buytest.mq5 |
//|                                                             PAOM |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "PAOM"
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\Trade.mqh>
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
      double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      MqlTick tick;
      double margin;
      if(!SymbolInfoTick(Symbol(),tick)||!OrderCalcMargin(ORDER_TYPE_BUY,Symbol(),1.0,tick.ask,margin))return;
      double FreeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
      double DynLot     = NormalizeDouble((FreeMargin/(margin*10)),1);
      
      if(1<2 && PositionsTotal()==0)
      {
         trade.Buy(DynLot,NULL,Ask,Ask-5000*_Point,Ask+7500*_Point,NULL);
      }
   
  }
//+------------------------------------------------------------------+

Hi,


i am having a problem with the right calculation of the LotSize.

I just want the EA to open a new Position but with a LotSize accordingly calculated to my Freemargin.


For example if the margin for 1 Lot of GER30 is 60€ and the FreeMargin is at 1000€, he can only open a Position that equals 1.6 Lots. So that if the GER30 gains/loses 1 point my Equity gains/loses 1.6€.

But when i run the testing, my EA opens a position with the right number of Volume. But it seems the volume doesnt match the Lot that i intend the ea to open.

For Example a volume of 0.1 seems to be a Lotsize of 10.

What am i missing ?


Thanks in advance :)

Reason: