Рэндом писал(а):Выложите весь код.
#property copyright "MagistrSanich"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
input double Lots=0.01;
input int Slip=30;
input int Magic=0;
input int TakeProfit=300;
input int StopLoss=300;
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int counter(int type)// ФУНЦИЯ ПОДСЧЕТА ОРДЕРА, РАБОТАЕТ ПРАВИЛЬНО
{
int n=0;
for(int i=0;i<(OrdersTotal()+1);i++)
if(OrderSelect(i,SELECT_BY_POS)==true)
if(OrderMagicNumber()==Magic)
if(OrderType()==type)
n++;
return n;
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
int mod=-18;
void OnTick()
{
if(counter(OP_BUY)==0) mod=-199;
if(counter(OP_BUY)==0)//counter()-функция которая считает ордера
OrderSend(_Symbol,OP_BUY,Lots,Ask,Slip,0,Ask+60*_Point,"",Magic,0,clrBlue);//Устанавливается TakeProfit и StopLoss, который работает правильно
if(counter(OP_SELL)==5)
OrderSend(_Symbol,OP_SELL,Lots,Bid,Slip,0,0,"",Magic,0,clrRed);
int Namber=500;//Namber - это TP и SL
double tpB=NormalizeDouble((Namber*_Point+Ask),_Digits);
double tpS=NormalizeDouble((Bid-Namber*_Point),_Digits);
for(int i=0;i<OrdersTotal();i++)//Цикл перебораа ордеров
{
if(OrderSelect(i,SELECT_BY_POS)==true)
if(OrderMagicNumber()==Magic)
if(counter(OP_BUY)==1 || counter(OP_SELL)==1)
{
if(OrderType()==OP_BUY && counter(OP_BUY)==1)//Модификация BUY
mod=OrderModify(OrderTicket(),OrderOpenPrice(),tpS,tpB,0,clrGreen);
//После выполнения функции присваивает 1 если получилось и 0 если нет
if(OrderType()==OP_SELL && counter(OP_SELL)==1)//Модификация SELL
OrderModify(OrderTicket(),OrderOpenPrice(),tpB,tpS,0,clrGreen);
}
}
Comment("mod= ",mod,"\nBUY: ",counter(OP_BUY),"\nSELL: ",counter(OP_SELL));
}