#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double Lots = 0.1;
extern int TakeProfit = 100 ;
extern int StopLoss = 50 ;
extern int Slippage = 5;
extern string comment = "WT BOT";
extern int Magic = 123;
double Sig1, Sig2, Sig3, Sig4, SL, TP;
int ticket;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
if (Digits == 3 || Digits == 5)
{
TakeProfit *= 10;
StopLoss *= 10;
Slippage *= 10;
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Signal_1,Signal_2 ;
// индикатор в осциллографе
Sig1 = iCustom(Symbol(), 0, "SFCC5", 3, 1); //зеленый
Sig1 = NormalizeDouble(Sig1,Digits);
Sig2 = iCustom(Symbol(), 0, "SFCC5", 4, 1); //красный
Sig2 = NormalizeDouble(Sig2,Digits);
// индикатор на графике
Sig3 = iCustom(Symbol(), 0, "SFCS5", 1, 1); //зеленый
Sig3 = NormalizeDouble(Sig3,Digits);
Sig4 = iCustom(Symbol(), 0, "SFCS5", 0, 1); //красный
Sig4 = NormalizeDouble(Sig4,Digits);
{
if( Sig1 != EMPTY_VALUE && Sig2 == EMPTY_VALUE)Signal_1=1;//зеленый
if( Sig1 == EMPTY_VALUE && Sig2!= EMPTY_VALUE)Signal_1=2;//красный
if( Sig3 != EMPTY_VALUE && Sig4 == EMPTY_VALUE)Signal_2=1;//зеленый
if( Sig3 == EMPTY_VALUE && Sig4 != EMPTY_VALUE)Signal_2=2;//красный
}
if((Signal_1 ==1 && Signal_2 == 1) && (CountSell() > 0)) //зеленый и есть ордера на продажу. то закрываем
{
for (int i = OrdersTotal ()-1; i >=0; i--)
{
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderMagicNumber () == Magic && OrderType() == OP_SELL )
OrderClose (OrderTicket(), OrderLots (), Ask, Slippage, Black);
}
}
}
if((Signal_1 == 2 && Signal_2 == 2) && (CountBuy() > 0))//красный и есть ордера на покупку. то закрываем
{
for (i = OrdersTotal ()-1; i >=0; i--)
{
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderMagicNumber () == Magic && OrderType() == OP_BUY )
OrderClose (OrderTicket(), OrderLots (), Bid, Slippage, Black);
}
}
}
if((Signal_1 == 1 && Signal_2 == 1) && (CountBuy() == 0))//зеленый и нет ордера на покупку. то открываем
{
SL = NormalizeDouble(Ask - StopLoss * Point, Digits);
TP = NormalizeDouble(Ask + TakeProfit * Point, Digits);
ticket = OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, comment, Magic, 0, Blue);
if (ticket > 0)
{
if( OrderSelect (ticket, SELECT_BY_TICKET, MODE_TRADES) == true)
OrderModify (ticket, OrderOpenPrice(), SL, TP, 0);
}
}
if((Signal_1 == 2 && Signal_2 == 2) &&( CountSell() == 0))//красный и нет ордера на продажу. то открываем
{
SL = NormalizeDouble(Bid + StopLoss * Point, Digits);
TP = NormalizeDouble(Bid - TakeProfit * Point, Digits);
ticket = OrderSend (Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, comment, Magic, 0, Red);
if (ticket > 0)
{
if( OrderSelect (ticket, SELECT_BY_TICKET, MODE_TRADES) == true)
OrderModify (ticket, OrderOpenPrice(), SL, TP, 0);
}
}
return(0);
}
//+------------------------------------------------------------------+
int CountSell ()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade >= 0; trade--)
{
OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol () == Symbol()&& OrderMagicNumber () == Magic)
{
if (OrderType () == OP_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountBuy ()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade >= 0; trade--)
{
OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol () == Symbol()&& OrderMagicNumber () == Magic)
{
if (OrderType () == OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+]