Calculate lots size

Back to topics list To post a new topic, please log in or register
avatar
41
KeepMarcos 2016.04.17 20:50
 
Hello people! It is a pleasure to be here in the forum.
I'm studying a lot calculator.
but it does not work. I tried everything.
Can anyone help me find the error?
Thanks a lot for the help.

*Sorry for English

 

avatar
41
KeepMarcos 2016.04.17 20:51 #
 
bool lotopt=true;
double mrg,lot;
double Lots = 1.0;
extern double               Lots = 1.0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int LotOpt() //--function: calculation Optimization Lots
   {
      if (lotopt==true) 
         {
           //----
           mrg = AccountBalance();
           if (mrg < 1000) {lot = 0.1;} 
           if ((mrg > 1000) && (mrg < 5000)) {lot = 0.1;}
           if ((mrg > 5000) && (mrg < 9000)) {lot = 0.2;}
           if ((mrg > 9000) && (mrg < 13000)) {lot = 0.3;}
           if ((mrg > 13000) && (mrg < 17000)) {lot = 0.4;}
           if ((mrg > 17000) && (mrg < 21000)) {lot = 0.5;}
           if ((mrg > 21000) && (mrg < 25000)) {lot = 0.6;}
           if ((mrg > 25000) && (mrg < 29000)) {lot = 0.7;}
           if ((mrg > 29000) && (mrg < 33000)) {lot = 0.8;}
           if ((mrg > 33000) && (mrg < 37000)) {lot = 0.9;}
           if ((mrg > 41000) && (mrg < 45000)) {lot = 1.0;}
           if (mrg > 45000) {lot = 1.5;}
         }
      else lot = Lots;
      return(lot);
      //----
   } //-end LotOpt()

void OnTick()
  {
//---

   OrderSend(Symbol(),OP_SELL,lot,Bid,0,0,0,NULL,1,0,Red);
  }

avatar
Moderator
3419
GumRai 2016.04.17 23:19 #
 
KeepMarcos:
but it does not work. I tried everything.

 

Have you tried calling the function before the OrderSend?
avatar
13006
WHRoeder 2016.04.18 03:40 #
 
  1. KeepMarcos: but it does not work.
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Your code has nothing to do with computing lot size from acceptable risk.
    • 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 = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (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