Download MetaTrader 5
To add comments, please log in or register
No time for trading? Subscribe to signals!
GoodPointMas
108
GoodPointMas 2015.05.17 11:31 

Hi there

I use prerrt coomon logic to calc lot size

extern double Depo        = 0;
extern double RiskPercent = 80;
extern double Lots        = 0;
extern int    Magic       = 113355;
extern int    Slippage    = 3;
extern double StopLoss    = 100;
extern double TakeProfit  = 50;

int OnInit()
  {
   if(Digits==3 || Digits ==5)
    {
     TakeProfit*=10;
     StopLoss*=10;
     Slippage *=10;
     CandelSize *=10;
    } 
   return(INIT_SUCCEEDED);
  }
void OnTick()
{
   ....
   point=MarketInfo(pairs[MaxIndex],MODE_POINT);
   dig=MarketInfo(pairs[MaxIndex],MODE_DIGITS);


   Lots=GetLots(pair);

   //SELL
   SL=NormalizeDouble(CurrentPriceAsk+StopLoss*point,dig);
   TP=NormalizeDouble(CurrentPriceBid-TakeProfit*point,dig);
   
  OrderSend(pair, OP_SELL, Lots,CurrentPriceBid, Slippage, SL,TP,"Sell",Magic,0,Blue)
  
  //BUY
  SL=NormalizeDouble(CurrentPriceBid-StopLoss*point,dig);
  TP=NormalizeDouble(CurrentPriceAsk+TakeProfit*point,dig);
  OrderSend(pair,OP_BUY, Lots, CurrentPriceAsk,Slippage, SL,TP,"Buy",Magic,0,Green)

}
 double GetLots(string pair)
 {
   double pipValue = MarketInfo(pair,MODE_TICKVALUE);
   double lot=0;
 
   if (Depo==0)
    Depo=AccountFreeMargin();
   
   lot=NormalizeDouble(Depo*RiskPercent/100.0/StopLoss/pipValue,2);

   return lot;
 }

it works fine for let's say AUDUSD, from depo $770  about 0.6 lot , or for EURJPG

but for GBPUSD got error "Not Enough Money"

whe I use diff lot's size scripts I get the same lot as per my script for GBPUSD 

any ideas why? 

Sherif Hasan
7221
Sherif Hasan 2015.05.17 12:46  

Every pair uses different margin. hope gbpusd has higher margin than audusd and eurjpy.

whroeder1
13590
whroeder1 2015.05.17 22:08  
  if(Digits==3 || Digits ==5)
     TakeProfit*=10;
     StopLoss*=10;
     Slippage *=10;
     CandelSize *=10;
Do not modify your externals. Every time you change timeframe or pair you get a deinit/init. Therefor your variable go 10x, 100x, 1000x etc. Global variable are not reset only on load (or recompile)
point=MarketInfo(pairs[MaxIndex],MODE_POINT);
   dig=MarketInfo(pairs[MaxIndex],MODE_DIGITS);
Do not code EA to trade multiple pairs, you can not use ANY predefined variables including your Digits. Code it to trade one pair, then put it on multiple charts. Done.
double pipValue = MarketInfo(pair,MODE_TICKVALUE);
Do not use tickvalue by itself.
  1. 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.
  2. Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  3. Do NOT use TickValue by itself - DeltaPerlot
  4. You must normalize lots properly and check against min and max.
  5. You must also check FreeMargin to avoid stop out
/
To add comments, please log in or register