Манименеджмент. Лот от риска на стоп. |
lot=NormalizeDouble((AccountEquity()*Risk/100)/StopLoss,Round);
extern double Lots = 0.1; // лот
extern double Risk = 2; // риск
extern double Depo = 1000; // депо
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int BuySell = 0; // 1-Buy 2-Sell
extern int Round = 2; // округление
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Depo.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 2; // риск
extern double Depo = 1000; // депо
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int BuySell = 0; // 1-Buy 2-Sell
extern int Round = 2; // округление
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
if(AccountFreeMarginCheck(Symbol(),type,Lot())<=0)
{
Print("Недостаточно средств для открытия позиции объемом: ",Lot());
return;
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double maxl=MarketInfo(NULL,MODE_MAXLOT);
double minl=MarketInfo(NULL,MODE_MINLOT);
if(Lots==0)
{
lot=NormalizeDouble((AccountEquity()*Risk/100)/StopLoss,Round);
}
if(lot<minl) lot=minl;
if(lot>maxl) lot=maxl;
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(OrdersTotal()<1)
{
if(BuySell==1) PutOrder(0,Ask);
if(BuySell==2) PutOrder(1,Bid);
}
Comment("\n Lot: ",NormalizeDouble((Depo*Risk/100)/StopLoss,Round));
}
//+------------------------------------------------------------------+
21 июля 2016
|
23 августа 2016
|
Комментарии (5)
www.mql5.com/en/forum/68910
www.mql5.com/ru/forum/92360
27 Oxy Сообщений: 3418 - ..ιllιlι.lι.ιllι.ιlι..
11 preasto Сообщений: 445
12 vypchela Сообщений: 112
12 vypchela Сообщений: 112
Не лишним было попутно выводить (для проверки) и значение свободной маржи. Редактирован: 18 апреля 2022, 15:31
6 kvashnin007 Сообщений: 521 - Андрей
Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий