
//+------------------------------------------------------------------+
//| AAA+OGNSFA EA.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "AAA"
#property link "BBB"
#property version "1.00"
#property strict
//------------------------------------------------------------------
//-----------------------------------------------------------------
//--- Inputs
extern string Expert_settings = "====================Settings====================";
extern double Lots = 0.01;
extern double MaxLot = 1000;
extern double KLot = 1;
extern int Count = 1000;
extern int Exit = 14400;
extern int StopLoss = 50000;
extern int TakeProfit = 50000;
extern double KStep = 1;
extern int Slip = 100;
extern int Magic = 112233;
extern string Comments = "DDSS";
extern string IndName = "DSS Bressert Arrows TT";
extern int EMAPeriod = 12;
extern int StochPeriod = 14;
extern int Shift = 1;
double marginRequirement, maxLot, minLot, lotSize, points, commissionPoints;
double currentSpread, avgSpread, maxSpread;
int Ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
marginRequirement = MarketInfo( Symbol(), MODE_MARGINREQUIRED ) * 0.01;
maxLot = ( double ) MarketInfo( Symbol(), MODE_MAXLOT );
minLot = ( double ) MarketInfo( Symbol(), MODE_MINLOT );
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);
}
r=OrderSend(NULL,type,Lot(type),NormalizeDouble(price,Digits),Slip,sl,tp,Comments,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 ModifyOrders()
{
double allb=0,alls=0;
double countb=0,counts=0,tp=0,sl=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)
{
allb+=OrderOpenPrice()*OrderLots();
countb+=OrderLots();
}
if(OrderType()==1)
{
alls+=OrderOpenPrice()*OrderLots();
counts+=OrderLots();
}
}
}
}
if(countb>0)
allb=NormalizeDouble(allb/countb,Digits);
if(counts>0)
alls=NormalizeDouble(alls/counts,Digits);
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TakeProfit>0)
tp=NormalizeDouble(allb+TakeProfit*Point,Digits);
if(StopLoss>0)
sl=NormalizeDouble(allb-StopLoss*Point,Digits);
if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
else
if(OrderType()==OP_SELL)
{
if(TakeProfit>0)
tp=NormalizeDouble(alls-TakeProfit*Point,Digits);
if(StopLoss>0)
sl=NormalizeDouble(alls+StopLoss*Point,Digits);
if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot(int type)
{
double lot=Lots;
if(CountTrades(type)>0)
lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades(type)),2);
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
int dig=0;
double bid=0,ask=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
bid=MarketInfo(OrderSymbol(),MODE_BID);
dig=(int)MarketInfo(OrderSymbol(),MODE_DIGITS);
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(bid,dig),33,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
ask=MarketInfo(OrderSymbol(),MODE_ASK);
dig=(int)MarketInfo(OrderSymbol(),MODE_DIGITS);
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(ask,dig),33,White);
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double blue1 = iCustom(NULL,0,IndName,EMAPeriod,StochPeriod,1,Shift);
double red1 = iCustom(NULL,0,IndName,EMAPeriod,StochPeriod,2,Shift);
double blue2 = iCustom(NULL,0,IndName,EMAPeriod,StochPeriod,1,Shift+1);
double red2 = iCustom(NULL,0,IndName,EMAPeriod,StochPeriod,2,Shift+1);
if(CountTrades()<Count)
{
{
if((CountTrades(0)<1 && red2>0 && blue1>0))
{
PutOrder(0,Ask);
ModifyOrders();
}
if((CountTrades(1)<1 && red1>0 && blue2>0))
{
PutOrder(1,Bid);
ModifyOrders();
}
}
}
if(TimeCurrent()-OrderOpenTime()>=Exit)
{
CloseAll();
}
if(TimeCurrent()-OrderOpenTime()>=Exit)
{
CloseAll();
}
}
//--------------------------------------------
Пожалуйста, напишите это, чтобы торговать на таймфрейме M5.
Sirojiddin