//+------------------------------------------------------------------+
//| sova.mq4 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "mql5.com"
#property version "1.00"
#property strict
extern int MaxRisk=0;
extern bool Buy=true; //для открытия ордера на покупку
extern bool Sell=true; //для открытия ордера на продажу
extern int TakeProfit=100;
extern int StopLoss=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double Free =AccountFreeMargin();
double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
double Step =MarketInfo(Symbol(),MODE_LOTSTEP);
double Lot =MathFloor(Free*MaxRisk/100/One_Lot/Step)*Step;
if(Lot<Min_Lot) Lot=Min_Lot;
if(Lot>Max_Lot) Lot=Max_Lot;
double buyTP=0; //тейкпрофит для покупки
double sellTP=0; //тейкпрофит для продажи
double buySL=0; //стоплосс для покупки
double sellSL=0; //стоплосс для продажи
if(TakeProfit>0)
{buyTP=Ask+TakeProfit*Point;
sellTP=Bid-TakeProfit*Point;}
if(StopLoss>0)
{buySL=Ask-StopLoss*Point;
sellSL=Bid+StopLoss*Point;}
while(!IsTradeAllowed()) Sleep(100);
if(Buy) OrderSend(Symbol(),OP_BUYSTOP,Lot,Ask+2*Point,3,buySL,buyTP,"",0,0,Blue);
while(!IsTradeAllowed()) Sleep(100);
if(Sell) OrderSend(Symbol(),OP_SELLSTOP,Lot,Bid-2*Point,3,sellSL,sellTP,"",0,0,Red);
}