
Можно ли ожидать?это новый заказ с поручителем
//+------------------------------------------------------------------+
//| MA1.mq4 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // торговый объем ордера
extern double MaxLot = 5; // максимальный торговый объем
extern double KLot = 1; // увеличение лота
extern double Profit = 0; // язь в рублях
extern int StopLoss = 0; // лось
extern int TakeProfit = 100; // язь
extern int CloseTime = 0; // время закрытия в минутах
extern int MA = 30; // период MA
extern int Step = 200; // шаг
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
double p=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
p=Bid;
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;
datetime expiration=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);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(int type=-1)
{
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type || type==-1)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,_Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,_Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(CountTrades()>0)
{
lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
}
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Время открытия позиции |
//+------------------------------------------------------------------+
datetime TimeOrderOpen()
{
datetime tm=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
tm=OrderOpenTime();
break;
}
}
}
}
return(tm);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
bool buy=1, sell=1;
double ma=iMA(NULL,0,MA,0,0,0,0);
int delta=int(TimeCurrent()-TimeOrderOpen());
if(AllProfit()>Profit && Profit>0)
CloseAll();
if(delta>CloseTime*60 && CloseTime>0)
CloseAll();
buy=Bid>ma;
sell=Bid<ma;
if(CountTrades()<1)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
if(Bid-p>Step*_Point && buy)
{
PutOrder(0,Ask);
p=Bid;
}
if(p-Bid>Step*_Point && sell)
{
PutOrder(1,Bid);
p=Bid;
}
Comment("\n Lots: ",Lot(),
"\n Trades: ",CountTrades(),
"\n Profit: ",AllProfit(),
"\n Time: ",TimeOrderOpen(),
"\n Time Delta: ",int(TimeCurrent()-TimeOrderOpen()));
}
//+------------------------------------------------------------------+
Я смотрю ты всерьез собрался торговать этой совой и заработать 600% годовых. Только вначале надо бы протестировать на тиковых котировках. Иначе вместо 600% будет слив.
AM2