void OnTick()
{
//---
//работа по открытию бара
if(use_data_from_closed_candle)
{
if (Time[0] == prevtime) return;
prevtime = Time[0];
}
REVERSAL_Signal = iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,0);
REVERSAL_1 = iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,1);
REVERSAL_2 = iCustom(NULL,0,"REVERSAL",timeframe,Main_Period,Main_Price,Down_floor,Up_floor,Length,Phase,0,2);
REVERSAL_1_0 =
ask = NormalizeDouble (MarketInfo(Symbol(),MODE_ASK), Digits);
bid = NormalizeDouble (MarketInfo(Symbol(),MODE_BID), Digits);
_OR_err = GetLastError();
Total_SELL = CountTrades(OP_SELL);
Total_Buy = CountTrades(OP_BUY);
total_orders = OrdersTotal();
if ( REVERSAL_Signal < Up_floor && REVERSAL_1 < Up_floor && REVERSAL_2 >= Up_floor && REVERSAL_1_2 > Up_floor) {sell_signal =1; buy_signal=0;}
if ( REVERSAL_Signal > Down_floor && REVERSAL_1 > Down_floor && REVERSAL_2 <= Down_floor && REVERSAL_3_2 < Down_floor) {buy_signal=1; sell_signal =0; }
if(prevtime && M1_buy_signal == 1 && Total_Buy>=0 && Total_Buy < MaxOrders && !reverse ) //buy order
{
if (Total_SELL>0) CLOSEORDER(OP_SELL);//Close_Orders(OP_SELL,loging);//CLOSEORDER(OP_SELL);
ticket_buy = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging); //OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);
}
if(prevtime && M1_buy_signal == 1 && Total_SELL>=0 && Total_SELL < MaxOrders && reverse ) //buy Reverse order
{
if (Total_Buy>0) CLOSEORDER(OP_BUY);
ticket_buy = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
}
if(prevtime && M1_sell_signal == 1 && Total_SELL>=0 && Total_SELL < MaxOrders && !reverse ) // sell order
{
if (Total_Buy>0) CLOSEORDER(OP_BUY);//Close_Orders(OP_BUY,loging);
ticket_sell = OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);//OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrRed);//OrderSendReliable(Symbol(),OP_SELL,Lots,bid,Slippage,0,0,"",Magic,0,clrRed,loging);
}
if(prevtime && M1_sell_signal == 1 && Total_Buy>=0 && Total_Buy < MaxOrders && reverse ) // sell Reverse order
{
if (Total_SELL>0)CLOSEORDER(OP_SELL);
ticket_sell = OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);//OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,0,0,"",Magic,0,clrBlue);//OrderSendReliable(Symbol(),OP_BUY,Lots,ask,Slippage,0,0,"",Magic,0,clrGreen,loging);
}
}