//+------------------------------------------------------------------+
//| Подсчет позиций |
//+------------------------------------------------------------------+
int CountTrades(int ot=-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()==0 && (ot==0 || ot==-1))
count++;
if(OrderType()==1 && (ot==1 || ot==-1))
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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=1;
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int FindOrderType()
{
int type=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
type=OrderType();
break;
}
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double FindLastBuyPrice()
{
double p=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==Magic)
{
p=OrderOpenPrice();
break;
}
}
}
return(p);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double FindLastSellPrice()
{
double p=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==Magic)
{
p=OrderOpenPrice();
break;
}
}
}
return(p);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ModifyOrders()
{
bool mod=1;
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()==0)
{
if(TakeProfit>0)
tp=NormalizeDouble(allb+TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(allb-StopLoss*_Point,_Digits);
if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
else
if(OrderType()==1)
{
if(TakeProfit>0)
tp=NormalizeDouble(alls-TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(alls+StopLoss*_Point,_Digits);
if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double lim=iCustom(NULL,0,IndName2,5,Shift);
double tom=iCustom(NULL,0,IndName2,4,Shift);
bool buy = lim!=EMPTY_VALUE && tom>0;
bool sell = tom!=EMPTY_VALUE && lim>0;
if(CountTrades()<1)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
if(CountTrades()<Count)
{
if(FindOrderType()==0 && FindLastBuyPrice()-Ask>Step*_Point)
{
PutOrder(0,Ask);
ModifyOrders();
}
if(FindOrderType()==1 && Bid-FindLastSellPrice()>Step*_Point)
{
PutOrder(1,Bid);
ModifyOrders();
}
}
if(CloseSig>0)
{
if(sell)
{
CloseAll(0);
}
if(buy)
{
CloseAll(1);
}
}
Comment("\n lim: ",lim,
"\n tom: ",tom);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Usrednitel_Sniper Scalp_SMF.mq4 |
//| Copyright 2022, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 99999; // максимальный лот
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Step = 500; // шаг
extern int Count = 100; // число поз
extern int Slip = 30; // реквот
extern int CloseSig = 1; // 1-закрытие по сигналу
extern int Shift = 1; // бар индикатора
extern int Magic = 1; // магик
extern string Comm = "Wave";
extern string IndName2 = "Sniper Scalp_SMF";
extern double Period1 = 0;
extern double Period2 = 0;
extern double Period3 = 24;
extern double DevStep1 = 0;
extern double DevStep2 = 0;
extern double DevStep3 = 3.8;
datetime t=0;
//+------------------------------------------------------------------+
//| 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);
}
r=OrderSend(NULL,type,Lot(type),NormalizeDouble(price,_Digits),Slip,sl,tp,Comm,Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
{
//--- время начала сессии
int StartTime=3600*aStartHour+60*aStartMinute;
//--- время окончания сессии
int StopTime=3600*aStopHour+60*aStopMinute;
//--- текущее время в секундах от начала дня
aTimeCur=aTimeCur%86400;
if(StopTime<StartTime)
{
//--- переход через полночь
if(aTimeCur>=StartTime || aTimeCur<StopTime)
{
return(true);
}
}
else
{
//--- внутри одного дня
if(aTimeCur>=StartTime && aTimeCur<StopTime)
{
return(true);
}
}
return(false);
}
да я в курсе, но он нужен чтобы не перерисовывал даже если результат будет так себе
каким образом вы предлагаете написать нерисующий индикатор на основе рисующих?
mishelbb