//------------------------------------------------------------------
extern double Lots = 0.1;
extern int TakeProfit = 100;
extern int StopLoss = 20;
extern int Magic = 12111;
extern int Slippage = 3;
//------------------------------------------------------------------
extern string Wave = "Параметры индикатора";
extern int TimeFrame = 1;
extern int WavePeriod = 10;
extern int AvgPeriod = 23;
extern bool SoundAlert = FALSE;
extern bool EmailAlert = FALSE;
//------------------------------------------------------------------
double PriceHigh, PriceLow, SL, TP;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if (Digits == 3 || Digits == 5)
{
TakeProfit *= 10;
StopLoss *= 10;
Slippage *= 10;
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
PriceHigh = iCustom(NULL, 0, "TrendWave_My", TimeFrame, WavePeriod, AvgPeriod, 7, 0);
PriceLow = iCustom(NULL, 0, "TrendWave_My", TimeFrame, WavePeriod, AvgPeriod, 6, 0);
if (CountSell() == 0 && Bid >= PriceHigh)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "robot", Magic, 0, Red);
if (ticket > 0)
{
SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("ошибка модификации на продажу");
} else Print("ошибка ордера на продажу");
}
if (CountBuy() == 0 && Ask <= PriceLow)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "robot", Magic, 0, Blue);
if (ticket > 0)
{
TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
if (OrderSelect(ticket, SELECT_BY_TICKET))
if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))
Print("ошибка модификации на покупку");
} else Print("ошибка ордера на покупку");
}
if (Ask <= PriceLow && CountSell() > 0)
{
for(int i = OrdersTotal() -1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
if(!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))
Print("ошибка закрытия ордера на родажу");
}
}
}
if (Bid >= PriceHigh && CountBuy() > 0)
{
for(int i = OrdersTotal() -1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))
Print("ошибка закрытия ордера на покупку");
}
}
}
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for ( int trade = OrdersTotal()-1; trade>=0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() ==Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
count++;
}
}
return(count);
}
int CountBuy()
{
int count = 0;
for ( int trade = OrdersTotal()-1; trade>=0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() ==Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
count++;
}
}
return(count);
}
rollout