//+------------------------------------------------------------------+
//|                                						  Trend Power.mq4 |	based on: Сила трендаWD-ProbMeter_v1.1
//|                                      Copyright © 2010, komposter |
//|                                       mailto:komposter@gmail.com |
//+------------------------------------------------------------------+
#property copyright "задумщик sever11 и  старшой komposter"
#property link      "mailto:komposter@gmail.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100

//--функция для получения размеров экрана и динамического размещения графики
#import "user32.dll"
	bool	GetWindowRect		( int h, int& pos[4] );
#import

extern string	GeneralSettings		= "-------Общие настройки-------";
extern string	UseTimeFrames			= "MN1,W1,D1,H4,H1,M30,M15,M5,M1";	//--используемые ТФ
extern int		FontSize					= 0;											//--размер шрифта. 0 - подстраивать автоматически

extern string	IndicatorProperties	= "-------Настройки индикаторов-------";
extern string	MACD_settings			= "----MACD----";
extern int		Fast_EMA					= 5;
extern int		Slow_EMA					= 13;
extern int		MACD_SMA					= 1;

extern string	Stoch_settings			= "----Stochastic----";
extern int		K_period					= 20;
extern int		D_period					= 2;
extern int		Slowing					= 2;

extern string	AdditionalProperties	= "-------Дополнительные настройки-------";
extern string	Colors_settings		= "----Настройки цвета----";
extern color	CaptionBGColor			= Black;			//--цвет фоновых вставок крайнего левого столбца и верхней заголовочной строки
extern color	CaptionTextColor		= DimGray;		//--цвет надписей в заголовках таблицы
extern color	CurrencyTextColor		= DodgerBlue;	//--цвет валютной пары
extern color	ValuesTextColor		= Black;			//--цвет основных данных индикатора
extern color	GeneralFrameColor		= Orange;

extern string	Alert_setting			= "-------Сигналы оповещений-------";
extern bool		SignalAlert				= FALSE;
extern bool		SendAlertEmail			= FALSE;
extern int		Alert_Trigger			= 75;

extern string	SignalArrows			= "-------Сигналы в главном окне графика-------";
extern int		MultiScoreSignal		= 75;				//--величина multi score которая считается достаточной для сигнала
extern int		IndiceStrengthBuy		= 7;				//--минимальное значение индекса силы для сигнала Бай
extern int		IndiceStrengthSell	= 2;				//--максимальное значение индекса силы для сигнала Селл
extern int		CurrencyScoreDiff		= 5;				//--разница между сигналами Currency Pair Range, достаточная для сигнала
extern int		ArrowShift				= 50;				//--сдвиг относительно текущей свечи
extern color	BuyArrowGeneral		= Lime;			//--цвет стрелки сигнала бай по общей тенденции
extern color	BuyArrowCurrent		= Yellow;		//--цвет стрелки сигнала бай по текущему ТФ
extern color	SellArrowGeneral		= Red;			//--цвет стрелки сигнала селл по общей тенденции
extern color	SellArrowCurrent		= Orange;		//--цвет стрелки сигнала селл по текущему ТФ

//--настройки, используемые при анализе набора индикаторов на всех ТФ
string	Indicators					= "-------Дополнительные настройки индикаторов-------";
string	MA_Properties				= "----MA----";
int		ma_periods[3]				= { 20, 50, 100 };
int		ma_method					= MODE_EMA;
int		ma_applied_price			= PRICE_CLOSE;

string	CCI_Properties				= "----CCI----";
int		cci_period					= 14;
int		cci_applied_price			= PRICE_CLOSE;

string	MACD_Properties			= "----MACD----";
int		macd_fast_period			= 12;
int		macd_slow_period			= 26;
int		macd_signal_period		= 9;

string	ADX_Properties				= "----ADX----";
int		adx_period					= 14;
int		adx_applied_price			= PRICE_CLOSE;

string	Bulls_Properties			= "----Bulls----";
int		bulls_period				= 13;
int		bulls_applied_price		= PRICE_CLOSE;

string	Bears_Properties			= "----Bears----";
int		bears_period				= 13;
int		bears_applied_price		= PRICE_CLOSE;

string	Stochastic_Properties	= "----Stichastic----";
int		k_period						= 5;
int		d_period						= 3;
int		slowing						= 3;

string	RSI_Properties				= "----RSI----";
int		rsi_period					= 14;

string	Force_Properties			= "----Force Index----";
int		force_period				= 14;
int		force_ma_method			= MODE_SMA;
int		force_applied_price		= PRICE_CLOSE;

string	Momentum_Properties		= "----Momentum----";
int		mom_period					= 14;
int		mom_applied_price			= PRICE_CLOSE;

string	DeMarker_Properties		= "----DeMarker----";
int		dm_period					= 14;

string	symbol_list[19]			= {"EURUSD", "GBPUSD", "AUDUSD", "USDJPY", "USDCHF", "USDCAD", "EURJPY", "EURGBP", "EURCHF", "EURAUD", "GBPJPY", "GBPCHF", "AUDJPY", "NZDUSD", "NZDJPY", "AUDNZD", "CHFJPY", "EURCAD", "AUDCAD"};

color		g_color_436;

string	short_name					= "»»»  Сила тренда  «««";
string	_Symbol						= "";

//--основные периоды, на которых идет анализ
int tf[];

bool		GlobalError					= false;
int		current_tf_index			= -1;
datetime	last_alert_time			= 0;

int init()
{
	int i = 0;
	
	//--устанавливаем имя нашего индикатора
	IndicatorShortName( short_name );
	_Symbol	= Symbol();
	
	if ( !IsDllsAllowed() )
	{
		Alert( "Использование библиотек DLL запрещено. Проверьте настройки терминала и перезапустите индикатор." );
		GlobalError = true;
		return(0);
	}
	
	for ( i = 0; i < ArraySize( symbol_list ); i ++ )
	{
		if ( MarketInfo( symbol_list[i], MODE_BID ) < 0.00000001 )
		{
			Alert( "Символ ", symbol_list[i], " не доступен в Market Watch(Обзоре Рынка). Проверьте настройки терминала и перезапустите индикатор." );
			GlobalError = true;
			return(0);
		}
	}
	
	//--инициализируем рабочие ТФ
	int tf_size = 0;
	
	if ( UseTimeFrames != "" )
	{
		int		start_pos = 0;
		int		finit_pos = 0;
		string	timeframe[];
	
		while( start_pos >= 0 && !IsStopped() )
		{
			tf_size ++;
			ArrayResize( timeframe, tf_size );
			
			finit_pos				= StringFind	( UseTimeFrames, ",", start_pos );
			timeframe[tf_size-1] = StringSubstr	( UseTimeFrames, start_pos, finit_pos - start_pos );
		
			if ( finit_pos < 0 ) { break; }
		
			start_pos = finit_pos + 1;
		}
	}
	else
	{
		Print( "Не задан ни один ТФ. Используем все доступные." );
		ArrayResize( timeframe, 9 );
		
		timeframe[0] = "MN1";
		timeframe[1] = "W1";
		timeframe[2] = "D1";
		timeframe[3] = "H4";
		timeframe[4] = "H1";
		timeframe[5] = "M30";
		timeframe[6] = "M15";
		timeframe[7] = "M5";
		timeframe[8] = "M1";
	}
	
	current_tf_index = -1;
	
	for ( i = 0; i < ArraySize( timeframe ); i ++ )
	{
		ArrayResize( tf, i+1 );
		tf[i] = intPeriod( timeframe[i] );
		
		if ( tf[i] == Period() ) { current_tf_index = i; }
	}

	return (0);
}

int deinit()
{
   obj_delete( "!##_" );
   return (0);
}

int start()
{
   if ( GlobalError ) { return(0); }
   
   //--просто счетчики
   int i = 0, j = 0;
   
   int size		= ArraySize( tf );
   int sl_size = ArraySize( symbol_list );
   
   //--Объявление переменных
   //--переменные типа double
   //--сигнал состоит из 6 состовляющих:
   //--№1 - Prop_value - усредненное значение всех анализируемых сигналов
   double	tf_prop_value_b[], tf_prop_value_s[], tf_prop_percent[];
   color		tf_prop_value_color[];
   int		tf_prop_index_408[], tf_prop_index_420[], tf_prop_index_456[], tf_prop_index_460, tf_prop_index_464, tf_prop_index_sum[];
   string	tf_suggest_text[];
   
   //--№2 - Multi_value - усредненное значение анализируемых индикаторов для каждого периода
   color		tf_multi_color[];
   double	tf_multi_score[];
   
   //--№3 - Cur_score - соотношение цен Хай и Лоу последних 24 часовых баров
   double	cur_score, cur_score_1;
   color		cur_score_color_440, cur_score_color_444;
   double	cur_scores[8], highs[], lows[], bids[], digits[], bids_lows[], highs_lows[], bids_lows_upd[], nine_blu[];
   
   //--№4 - Cur_score2 - аналогично №3, но расчет ведется для символов типа "m"
   //--№5 - Sn_score - анализ индикатора МАКД для текущего символа и периода (каждый анализируемый период есть текущим сам для себя)
	string	tf_sn_score[];
	color		tf_sn_color[];
	
	//--№6 - Fis_score - анализ индикатора Стохастик для текущего символа и периода (каждый анализируемый период есть текущим сам для себя)
	string	tf_fis_score[];
	color		tf_fis_color[];
	
	//--обобщение по всем ТФ
   color		general_rainbow[8];
   double	gen_prop_value, gen_multi_score, gen_sn, gen_fis;
   string	gen_sn_score, gen_fis_score;
	
   //--общие переменные
   double l_1, l_2;
   
   //--счетчики сигналов
   int count_ld_000[];
   int count_ld_448[];
   
   //--приводим массивы в соответствие
   ArrayResize( highs,			sl_size ); ArrayResize( lows,				sl_size );
   ArrayResize( bids,			sl_size ); ArrayResize( digits,			sl_size );
   ArrayResize( bids_lows,		sl_size ); ArrayResize( bids_lows_upd,	sl_size );
   ArrayResize( highs_lows,	sl_size ); ArrayResize( nine_blu,		sl_size );
   
   ArrayInitialize( highs,			0 ); ArrayInitialize( lows,				0 );
   ArrayInitialize( bids,			0 ); ArrayInitialize( digits,				0 );
   ArrayInitialize( bids_lows,	0 ); ArrayInitialize( bids_lows_upd,	0 );
   ArrayInitialize( highs_lows,	0 ); ArrayInitialize( nine_blu,			0 );
   
   ArrayResize( tf_prop_value_b,		size ); ArrayResize( tf_prop_value_s,		size );
   ArrayResize( tf_prop_percent,		size ); ArrayResize( tf_prop_value_color, size );
   ArrayResize( tf_prop_index_408,	size ); ArrayResize( tf_prop_index_420,	size );
   ArrayResize( tf_prop_index_456,	size ); ArrayResize( tf_prop_index_sum,	size );
   ArrayResize( tf_suggest_text,		size ); ArrayResize( tf_multi_color,		size );
   ArrayResize( tf_multi_score,		size ); ArrayResize( tf_sn_score,			size );
   ArrayResize( tf_sn_color,			size ); ArrayResize( tf_fis_score,			size );
   ArrayResize( tf_fis_color,			size ); ArrayResize( count_ld_000,			size );
   ArrayResize( count_ld_448,			size );
   
   ArrayInitialize( tf_prop_value_b,		0 ); ArrayInitialize( tf_prop_value_s,			0 );
   ArrayInitialize( tf_prop_percent,		0 ); ArrayInitialize( tf_prop_value_color,	0 );
   ArrayInitialize( tf_prop_index_408,		0 ); ArrayInitialize( tf_prop_index_420,		0 );
   ArrayInitialize( tf_prop_index_456,		0 ); ArrayInitialize( tf_prop_index_sum,		0 );
   ArrayInitialize( tf_multi_color,			0 ); ArrayInitialize( count_ld_000,				0 );
   ArrayInitialize( tf_multi_score,			0 ); ArrayInitialize( count_ld_448,				0 );
   ArrayInitialize( tf_sn_color,				0 ); ArrayInitialize( tf_fis_color,				0 );
   
   //--собственно поиск сигналов
   for ( i = 0; i < size; i ++  )
   {
   	//--расчет всех индикаторов для каждого периода по очереди
   	//--MA
   	for ( j = 0; j < ArraySize( ma_periods ); j ++ )
   	{
   		l_1 = iMA ( NULL, tf[i], ma_periods[j], 0, ma_method, ma_applied_price, 0 );
   		l_2 = iMA ( NULL, tf[i], ma_periods[j], 0, ma_method, ma_applied_price, 1 );
   		
   		if ( l_1 > l_2 ) { count_ld_000[i] ++; }
   		if ( l_1 < l_2 ) { count_ld_448[i] ++; }
   	}
   	
   	//--CCI
   	l_1 = iCCI ( NULL, tf[i], cci_period, cci_applied_price, 0 );
   		
   	if ( l_1 > 0.0 ) { count_ld_000[i] ++; }
   	if ( l_1 < 0.0 ) { count_ld_448[i] ++; }
   	
   	//--MACD
   	l_1 = iMACD ( NULL, tf[i], macd_fast_period, macd_slow_period, macd_signal_period, PRICE_CLOSE, MODE_MAIN,		0 );
   	l_2 = iMACD ( NULL, tf[i], macd_fast_period, macd_slow_period, macd_signal_period, PRICE_CLOSE, MODE_SIGNAL,	0 );
   	
   	if ( l_1 > l_2 ) { count_ld_000[i] ++; }
   	if ( l_1 < l_2 ) { count_ld_448[i] ++; }
   	
   	//--ADX
   	l_1 = iADX ( NULL, tf[i], adx_period, adx_applied_price, MODE_PLUSDI,	0 );
   	l_2 = iADX ( NULL, tf[i], adx_period, adx_applied_price, MODE_MINUSDI,	0 );
   	
   	if ( l_1 > l_2 ) { count_ld_000[i] ++; }
   	if ( l_1 < l_2 ) { count_ld_448[i] ++; }
   	
   	//Bulls Power
   	l_1 = iBullsPower ( NULL, tf[i], bulls_period, bulls_applied_price, 0 );
   	
   	if ( l_1 > 0.0 ) { count_ld_000[i] ++; }
   	if ( l_1 < 0.0 ) { count_ld_448[i] ++; }
   	
   	//Bears Power
   	l_1 = iBearsPower ( NULL, tf[i], bears_period, bears_applied_price, 0 );
   	
   	if ( l_1 > 0.0 ) { count_ld_000[i] ++; }
   	if ( l_1 < 0.0 ) { count_ld_448[i] ++; }
   	
   	//Stochastic
   	l_1 = iStochastic ( NULL, tf[i], k_period, d_period, slowing, MODE_SMA, 1, MODE_MAIN,	0 );
   	l_2 = iStochastic ( NULL, tf[i], k_period, d_period, slowing, MODE_SMA, 1, MODE_SIGNAL,	0 );
   	
   	if ( l_1 >= l_2 ) { count_ld_000[i] ++; }
   	if ( l_1 <  l_2 ) { count_ld_448[i] ++; }
   	
   	//RSI
   	l_1 = iRSI ( NULL, tf[i], rsi_period, PRICE_CLOSE, 0 );
   	
   	if ( l_1 >= 50.0 ) { count_ld_000[i] ++; }
   	if ( l_1 <  50.0 ) { count_ld_448[i] ++; }
   	
   	//Force
   	l_1 = iForce ( NULL, tf[i], force_period, force_ma_method, force_applied_price, 0 );
   	
   	if ( l_1 >= 0.0 ) { count_ld_000[i] ++; }
   	if ( l_1 <  0.0 ) { count_ld_448[i] ++; }
   	
   	//Momentum
   	l_1 = iMomentum ( NULL, tf[i], mom_period, mom_applied_price, 0 );
   	
   	if ( l_1 >= 100.0 ) { count_ld_000[i] ++; }
   	if ( l_1 <  100.0 ) { count_ld_448[i] ++; }
   	
   	//DeMarker
   	l_1 = iDeMarker ( NULL, tf[i], dm_period, 0 );
   	l_2 = iDeMarker ( NULL, tf[i], dm_period, 1 );
   	
   	if ( l_1 >= l_2 ) { count_ld_000[i] ++; }
   	if ( l_1 <  l_2 ) { count_ld_448[i] ++; }
   	
   	//--после прохода по периоду, анализируем сигнал prop_value & multi_score для него
   	//--№1
   	tf_prop_value_b[i] = NormalizeDouble( 100.0 * ( count_ld_000[i] / 13.0 ), 0 );
   	tf_prop_value_s[i] = NormalizeDouble( 100.0 * ( count_ld_448[i] / 13.0 ), 0 );
   	
   	if ( tf_prop_value_b[i] < 70.0 || tf_prop_value_s[i] < 70.0 ) { tf_prop_index_456[i] = 0; }
   	
   	if ( tf_prop_value_b[i] >= 70.0 ) { tf_prop_index_456[i] =  1; }
   	if ( tf_prop_value_b[i] >= 75.0 ) { tf_prop_index_456[i] =  2; }
   	if ( tf_prop_value_b[i] >= 85.0 ) { tf_prop_index_456[i] =  3; }
   	
   	if ( tf_prop_value_s[i] >= 70.0 ) { tf_prop_index_456[i] = -1; }
   	if ( tf_prop_value_s[i] >= 75.0 ) { tf_prop_index_456[i] = -2; }
   	if ( tf_prop_value_s[i] >= 85.0 ) { tf_prop_index_456[i] = -3; }
   	
   	//--№2
   	if ( tf_prop_value_b[i] >= 50.0 )
   	{
   		tf_multi_score[i] = tf_prop_value_b[i];
   		tf_multi_color[i] = Lime;
   		gen_multi_score += tf_multi_score[i];
   	}
   	else
   	{
   		tf_multi_score[i] = tf_prop_value_s[i];
   		tf_multi_color[i] = Red;
   		gen_multi_score -= tf_multi_score[i];
   	}
   	
   	//--№5
   	//--расчет коэффициентов 408 и 420 для prop_value
   	//--MACD
		l_1 = iMACD( _Symbol, tf[i], Fast_EMA, Slow_EMA, MACD_SMA, PRICE_CLOSE, MODE_SIGNAL, 0 );
		l_2 = iMACD( _Symbol, tf[i], Fast_EMA, Slow_EMA, MACD_SMA, PRICE_CLOSE, MODE_SIGNAL, 1 );
		
		if ( l_1 >= 0.0 && l_1 > l_2 ) { tf_prop_index_408[i] = 1; tf_sn_score[i] = "м"; tf_sn_color[i] = Lime; }
		else
		{
			if ( l_1 < 0.0 && l_1 < l_2 ) { tf_prop_index_408[i] = -1; tf_sn_score[i] = "о"; tf_sn_color[i] = Red; }
			else { tf_prop_index_408[i] = 0; tf_sn_score[i] = "h"; tf_sn_color[i] = DarkOrange; }
		}
		
		//--№6
		//Stochastic
		l_1 = iStochastic( _Symbol, tf[i], K_period, D_period, Slowing, MODE_SMA, 0, MODE_SIGNAL, 0 );
   	l_2 = iStochastic( _Symbol, tf[i], K_period, D_period, Slowing, MODE_SMA, 0, MODE_SIGNAL, 1 );
   	
   	if ( l_1 < 75.0 && l_1 < l_2 ) { tf_prop_index_420[i] = -1; tf_fis_score[i] = "о"; tf_fis_color[i] = Red; }
   	else
   	{
      	if ( l_1 > 25.0 && l_1 > l_2 ) { tf_prop_index_420[i] = 1; tf_fis_score[i] = "м"; tf_fis_color[i] = Lime; }
      	else { tf_prop_index_420[i] = 0; tf_fis_score[i] = "h"; tf_fis_color[i] = DarkOrange; }
   	}
   	
   	gen_sn	+= tf_prop_index_408[i];
   	gen_fis	+= tf_prop_index_420[i];
   }

   double bid					= MarketInfo ( _Symbol, MODE_BID );
   
   double low					= iLow  ( _Symbol, PERIOD_H1, iLowest  ( _Symbol, PERIOD_H1, MODE_LOW,  24, 0 ) );
   double high_low			= iHigh ( _Symbol, PERIOD_H1, iHighest ( _Symbol, PERIOD_H1, MODE_HIGH, 24, 0 ) ) - low;
   
   high_low = NormalizeDouble( high_low/Point, 0 );
	high_low = 100.0 * ( ( bid - low ) / high_low ) / Point;
	
	high_low = NormalizeDouble( high_low, 2 );
   high_low = Lookup ( high_low ); //ld_2776
   
   if ( high_low <  6.0 && high_low > 3.0	) { tf_prop_index_460 = 0; }
   if ( high_low >= 6.0 ) { tf_prop_index_460 =  1; }
   if ( high_low >= 7.0 ) { tf_prop_index_460 =  2; g_color_436 = Lime; general_rainbow[3] = Lime; }
   if ( high_low >= 8.0 ) { tf_prop_index_460 =  3; }
   if ( high_low <= 3.0 ) { tf_prop_index_460 = -1; }
   if ( high_low <= 2.0 ) { tf_prop_index_460 = -2; g_color_436 = Red; general_rainbow[3] = Red; }
   if ( high_low <= 1.0 ) { tf_prop_index_460 = -3; }
   if ( high_low >  2.0 && high_low < 5.0	) { g_color_436 = DarkOrange; general_rainbow[3] = DarkOrange; }
   if ( high_low >= 5.0 && high_low < 7.0 ) { g_color_436 = Yellow; general_rainbow[3] = Yellow; }
	
	string symbol_substr = StringSubstr( _Symbol, 6, 1 );
	string new_symbol		= ""; //l_symbol_2876
	double point			= 0;	//ld_2864
	
   for ( i = 0; i < sl_size; i ++ )
   {
      RefreshRates();
      
      new_symbol = symbol_list[i];

      if ( StringFind ( AccountCompany(), "Interbank" ) == 0 && symbol_substr == "m" ) { new_symbol = new_symbol + "m"; }
      
      point = GetPoint ( new_symbol );
      
      highs				[i] = iHigh ( new_symbol, PERIOD_H1, iHighest ( new_symbol, PERIOD_H1, MODE_HIGH, 24, 0 ) );
      lows				[i] = iLow  ( new_symbol, PERIOD_H1, iLowest  ( new_symbol, PERIOD_H1, MODE_LOW,  24, 0 ) );
      
      bids				[i] = MarketInfo ( new_symbol, MODE_BID );
      digits			[i] = MarketInfo ( new_symbol, MODE_DIGITS );
      
      highs_lows		[i] = MathMax ( ( highs[i] - lows[i] ) / point, 1 );
      bids_lows		[i] = ( bids[i] - lows[i] ) / highs_lows[i] / point;
      
      bids_lows_upd	[i] = iLookup( 100.0 * bids_lows[i] ); //lda_2816 (blu)
      nine_blu			[i] = 9 - bids_lows_upd[i]; //lda_2820
   }
   
   cur_scores[0] = NormalizeDouble ( ( bids_lows_upd	[ 3] + bids_lows_upd	[ 4] + bids_lows_upd	[ 5] + nine_blu		[ 0] + nine_blu		[ 1] + nine_blu		[ 2] + nine_blu[13] ) / 7.0, 1 );
   cur_scores[1] = NormalizeDouble ( ( bids_lows_upd	[17] + bids_lows_upd	[ 0] + bids_lows_upd	[ 6] + bids_lows_upd	[ 7] + bids_lows_upd	[ 8] + bids_lows_upd	[ 9] ) / 6.0, 1 );
   cur_scores[2] = NormalizeDouble ( ( bids_lows_upd	[ 1] + bids_lows_upd	[10] + bids_lows_upd	[11] + nine_blu		[ 7] ) / 4.0, 1 );
   cur_scores[3] = NormalizeDouble ( ( bids_lows_upd	[16] + nine_blu		[ 4] + nine_blu		[ 8] + nine_blu		[11] ) / 4.0, 1 );
   cur_scores[4] = NormalizeDouble ( ( nine_blu			[18] + nine_blu		[ 5] + nine_blu		[17] ) / 3.0, 1 );
   cur_scores[5] = NormalizeDouble ( ( bids_lows_upd	[ 2] + bids_lows_upd	[15] + bids_lows_upd	[18] + bids_lows_upd	[12] + nine_blu		[ 9] ) * 0.2, 1 );
   cur_scores[6] = NormalizeDouble ( ( nine_blu			[ 3] + nine_blu		[ 6] + nine_blu		[10] + nine_blu		[12] + nine_blu		[14] + nine_blu		[16] ) / 6.0, 1);
   cur_scores[7] = NormalizeDouble ( ( bids_lows_upd	[13] + bids_lows_upd	[14] + nine_blu		[15] ) / 3.0, 1 );
   
   symbol_substr = StringSubstr( _Symbol, 0, 6 ); //ls_2908
   
   if ( symbol_substr == "EURUSD" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[0]; }
   if ( symbol_substr == "GBPUSD" ) { cur_score = cur_scores[2]; cur_score_1 = cur_scores[0]; }
   if ( symbol_substr == "AUDUSD" ) { cur_score = cur_scores[5]; cur_score_1 = cur_scores[0]; }
   if ( symbol_substr == "USDJPY" ) { cur_score = cur_scores[0]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "USDCHF" ) { cur_score = cur_scores[0]; cur_score_1 = cur_scores[3]; }
   if ( symbol_substr == "USDCAD" ) { cur_score = cur_scores[0]; cur_score_1 = cur_scores[4]; }
   if ( symbol_substr == "EURJPY" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "EURGBP" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[2]; }
   if ( symbol_substr == "EURCHF" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[3]; }
   if ( symbol_substr == "EURAUD" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[5]; }
   if ( symbol_substr == "GBPJPY" ) { cur_score = cur_scores[2]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "GBPCHF" ) { cur_score = cur_scores[2]; cur_score_1 = cur_scores[3]; }
   if ( symbol_substr == "AUDJPY" ) { cur_score = cur_scores[5]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "NZDUSD" ) { cur_score = cur_scores[7]; cur_score_1 = cur_scores[0]; }
   if ( symbol_substr == "NZDJPY" ) { cur_score = cur_scores[7]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "AUDNZD" ) { cur_score = cur_scores[5]; cur_score_1 = cur_scores[7]; }
   if ( symbol_substr == "CHFJPY" ) { cur_score = cur_scores[3]; cur_score_1 = cur_scores[6]; }
   if ( symbol_substr == "EURCAD" ) { cur_score = cur_scores[1]; cur_score_1 = cur_scores[4]; }
   if ( symbol_substr == "AUDCAD" ) { cur_score = cur_scores[5]; cur_score_1 = cur_scores[4]; }

   double score_diff = MathAbs ( cur_score - cur_score_1 ); //ld_2924
   
   if ( score_diff	<  3.0 ) { tf_prop_index_464 = 0; }
   
   if ( score_diff	>= 3.0 && cur_score		> cur_score_1 )	{ tf_prop_index_464 =  1; }
   if ( score_diff	>= 5.0 && cur_score		> cur_score_1 )	{ tf_prop_index_464 =  2; }
   if ( score_diff	>= 7.0 && cur_score		> cur_score_1 )	{ tf_prop_index_464 =  3; }
   if ( score_diff	>= 3.0 && cur_score		< cur_score_1 )	{ tf_prop_index_464 = -1; }
   if ( score_diff	>= 5.0 && cur_score		< cur_score_1 )	{ tf_prop_index_464 = -2; }
   if ( score_diff	>= 7.0 && cur_score		< cur_score_1 )	{ tf_prop_index_464 = -3; }
   
   if ( cur_score		<= 2.5 ) { cur_score_color_440 = Red; general_rainbow[4] = Red; }
   if ( cur_score		>  2.5 && cur_score		< 4.5 )				{ cur_score_color_440 = DarkOrange; general_rainbow[4] = DarkOrange; }
   if ( cur_score		>= 4.5 && cur_score		< 6.5 )				{ cur_score_color_440 = Yellow; general_rainbow[4] = Yellow; }
   if ( cur_score 	>= 6.5 ) { cur_score_color_440 = Lime; general_rainbow[4] = Lime; }
   
   if ( cur_score_1	<= 2.5 ) { cur_score_color_444 = Red; general_rainbow[5] = Red; }
   if ( cur_score_1	>  2.5 && cur_score_1	< 4.5 )				{ cur_score_color_444 = DarkOrange; general_rainbow[5] = DarkOrange; }
   if ( cur_score_1	>= 4.5 && cur_score_1	< 6.5 )				{ cur_score_color_444 = Yellow; general_rainbow[5] = Yellow; }
   if ( cur_score_1	>= 6.5 ) { cur_score_color_444 = Lime; general_rainbow[5] = Lime; }
   
   int gen_sum = 0;
   
   for ( i = 0; i < size; i ++ )
   {
   	tf_prop_index_sum	[i] = tf_prop_index_456[i] + tf_prop_index_408[i] + tf_prop_index_420[i] + tf_prop_index_460 + tf_prop_index_464;
   	tf_prop_percent	[i] = 100.0 * ( MathAbs( tf_prop_index_sum[i] ) / 11.0 );
   	
   	//BUY
   	if ( tf_prop_percent[i] >= 0.00 && tf_prop_percent		[i] <  50.0 && tf_prop_index_sum[i] >= 0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value += tf_prop_percent[i]; tf_suggest_text[i] = "L:"; tf_prop_value_color[i] = Green;				}
   	if ( tf_prop_percent[i] >= 50.0 && tf_prop_percent		[i] <  75.0 && tf_prop_index_sum[i] >= 0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value += tf_prop_percent[i]; tf_suggest_text[i] = "L:"; tf_prop_value_color[i] = Green;				}
   	if ( tf_prop_percent[i] >= 75.0 && tf_prop_percent		[i] <  90.0 && tf_prop_index_sum[i] >= 0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value += tf_prop_percent[i]; tf_suggest_text[i] = "L:"; tf_prop_value_color[i] = MediumSeaGreen;	}
   	if ( tf_prop_percent[i] >= 90.0 && tf_prop_index_sum	[i] >= 0 )												{ gen_sum += tf_prop_index_sum[i]; gen_prop_value += tf_prop_percent[i]; tf_suggest_text[i] = "L:"; tf_prop_value_color[i] = Lime;					}
   
   	//SELL
   	if ( tf_prop_percent[i] >= 0.00 && tf_prop_percent		[i] <  50.0 && tf_prop_index_sum[i] <  0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value -= tf_prop_percent[i]; tf_suggest_text[i] = "S:"; tf_prop_value_color[i] = Maroon;				}
   	if ( tf_prop_percent[i] >= 50.0 && tf_prop_percent		[i] <  75.0 && tf_prop_index_sum[i] <  0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value -= tf_prop_percent[i]; tf_suggest_text[i] = "S:"; tf_prop_value_color[i] = Maroon;				}
   	if ( tf_prop_percent[i] >= 75.0 && tf_prop_percent		[i] <  90.0 && tf_prop_index_sum[i] <  0 )	{ gen_sum += tf_prop_index_sum[i]; gen_prop_value -= tf_prop_percent[i]; tf_suggest_text[i] = "S:"; tf_prop_value_color[i] = Chocolate;			}
   	if ( tf_prop_percent[i] >= 90.0 && tf_prop_index_sum	[i] <  0 )												{ gen_sum += tf_prop_index_sum[i]; gen_prop_value -= tf_prop_percent[i]; tf_suggest_text[i] = "S:"; tf_prop_value_color[i] = Red;					}
   }
   
   general_rainbow[0] = CaptionBGColor;
   
   string gen_suggest_text = "";
   
   //--находим усредненный процент для всех 9 ТФ
   gen_prop_value = NormalizeDouble( MathAbs(gen_prop_value)/size, 0 );
   
   if ( gen_prop_value >= 0.00 && gen_prop_value < 75.0 )
   {
   	if ( gen_sum >= 0.0 ) { general_rainbow[1] = Green; gen_suggest_text = "L:"; }
   	else { general_rainbow[1] = Maroon; gen_suggest_text = "S:"; }
   }
   
   if ( gen_prop_value >= 75.0 && gen_prop_value < 90.0 )
   {
   	if ( gen_sum >= 0.0 ) { general_rainbow[1] = MediumSeaGreen; gen_suggest_text = "L:"; }
   	else { general_rainbow[1] = Chocolate; gen_suggest_text = "S:"; }
   }
   
   if ( gen_prop_value >= 90.0 )
   {
   	if ( gen_sum >= 0.0 ) { general_rainbow[1] = Lime; gen_suggest_text = "L:"; }
   	else { general_rainbow[1] = Red; gen_suggest_text = "S:"; }
   }
   
   if ( gen_multi_score >= 0.0 ) { general_rainbow[2] = Lime; }
   else { general_rainbow[2] = Red; }
   
   gen_multi_score = NormalizeDouble( MathAbs( gen_multi_score )/size, 0 );
   
   if ( gen_sn > 0 ) { general_rainbow[6] = Lime; gen_sn_score = "м"; }
   else
   {
   	if ( gen_sn < 0 ) { general_rainbow[6] = Red; gen_sn_score = "о"; }
   	else { general_rainbow[6] = DarkOrange; gen_sn_score = "h"; }
   }
   
   if ( gen_fis > 0 ) { general_rainbow[7] = Lime; gen_fis_score = "м"; }
   else
   {
   	if ( gen_fis < 0 ) { general_rainbow[7] = Red; gen_fis_score = "о"; }
   	else { general_rainbow[7] = DarkOrange; gen_fis_score = "h"; }
   }
   
   symbol_substr = StringSubstr ( _Symbol, 0, 6 ); //l_text_2996
   
   color		trade_rainbow	[];	//--цвета используемых ТФ 72
   string	final_values	[];	//--60
   
   ArrayResize( trade_rainbow,	 size*8 );
   ArrayResize( final_values,		(size+1)*6 );
   
   for ( i = 0; i < size; i ++ )
   {
   	//--вносим значения первой строки
   	trade_rainbow[i       ] = CaptionBGColor;				//--заголовок таблицы (имя ТФ)
   	trade_rainbow[i+size*1] = tf_prop_value_color[i];	//--цвет % рекомендации
   	trade_rainbow[i+size*2] = tf_multi_color		[i];	//--цвет multi_score
   	trade_rainbow[i+size*3] = g_color_436;					//--high_low
   	trade_rainbow[i+size*4] = cur_score_color_440;
   	trade_rainbow[i+size*5] = cur_score_color_444;
   	trade_rainbow[i+size*6] = tf_sn_color			[i];	//--цвет поля МАКД
   	trade_rainbow[i+size*7] = tf_fis_color			[i];	//--цвет поля Стохастик
   }
   
   for ( i = 0; i < size+1; i ++ )
   {
   	if ( i >= size ) { continue; }
   	
   	final_values [i         ] = DoubleToStr( tf_prop_percent[i], 0 ) + "%";
   	final_values [i+size  +1] = DoubleToStr( tf_multi_score[i], 0 );
   	final_values [i+size*2+2] = DoubleToStr( high_low, 0 );
   	final_values [i+size*3+3] = DoubleToStr( cur_score, 0 ) + " - " + DoubleToStr( cur_score_1, 0 );
   	final_values [i+size*4+4] = tf_sn_score[i];
   	final_values [i+size*5+5] = tf_fis_score[i];
   }
   
   final_values[size    ] = DoubleToStr( gen_prop_value, 0 ) + "%";
   final_values[size*2+1] = DoubleToStr( gen_multi_score, 0 );
   final_values[size*3+2] = DoubleToStr( high_low, 0 );
   final_values[size*4+3] = DoubleToStr( cur_score, 0 ) + " - " + DoubleToStr( cur_score_1, 0 );
   final_values[size*5+4] = gen_sn_score;
   final_values[size*6+5] = gen_fis_score;
   
   int		alert_signal	= 0;
   string	period_info		= "";
   
   if ( current_tf_index >= 0 )
   {
   	if ( tf_prop_percent[current_tf_index] >= Alert_Trigger )
   	{
   		if ( tf_prop_index_sum[current_tf_index] >= 0 ) { alert_signal = 1; }
   		else { alert_signal = -1; }
   	}
   	
   	period_info = strPeriod( Period() );
   }
   else { period_info = "[текущий период не анализируется, получен общий сигнал]"; }
   
   //--оповещение
   //--если на этом баре еще не оповещали
   if ( last_alert_time != iTime( _Symbol, Period(), 0 ) )
   {
   	//--prop_value общей тенденции >= указанного уровня
   	if ( gen_prop_value >= Alert_Trigger && gen_suggest_text == "L:" )
   	{
      	if ( current_tf_index < 0 || alert_signal > 0 )
      	{
      		if ( SignalAlert		) { Alert	( "Рекомендация Strong UP Trend - ", _Symbol, " ", period_info, " at ", TimeToStr( TimeCurrent(), TIME_SECONDS ) + " (server time)." ); }
      		if ( SendAlertEmail	) { SendMail( "Рекомендация signal", "Рекомендация Strong UP Trend - " + _Symbol + " " + period_info + " at " + TimeToStr( TimeCurrent(), TIME_SECONDS ) + " (server time)." ); }
      
      		last_alert_time = iTime( _Symbol, Period(), 0 );
      	}
   	}
   
   	if ( gen_prop_value >= Alert_Trigger && gen_suggest_text == "S:" )
   	{
      	if ( current_tf_index < 0 || alert_signal < 0 )
      	{
      		if ( SignalAlert		) { Alert	( "Рекомендация Strong DOWN Trend - ", _Symbol, " ", period_info, " at ", TimeToStr( TimeCurrent(), TIME_SECONDS ) + " (server time)." ); }
      		if ( SendAlertEmail	) { SendMail( "Рекомендация signal", "Рекомендация Strong DOWN Trend - " + _Symbol + " " + period_info + " at " + TimeToStr( TimeCurrent(), TIME_SECONDS ) + " (server time)." ); }
      	
      		last_alert_time = iTime( _Symbol, Period(), 0 );
      	}
   	}
   }
   
   //--создаем стрелку на графике при появлении сигнала
   //--сначала проверим общий сингал
   if ( gen_multi_score >= MultiScoreSignal )
   {
   	//buy
   	if ( general_rainbow[2] == Lime )
   	{
   		if ( high_low >= IndiceStrengthBuy )
   		{
   			if ( NormalizeDouble( cur_score, 0 ) - NormalizeDouble( cur_score_1, 0 ) >= CurrencyScoreDiff )
   			{
   				if ( gen_sn_score == "м" && gen_fis_score == "м" ) { create_signal_arrow( "gen", iTime( _Symbol, Period(), 0 ), iLow( _Symbol, Period(), 0 ) - ArrowShift*Point, BuyArrowGeneral, SYMBOL_ARROWUP ); }
   			}
   		}
   	}
   	
   	//sell
   	if ( general_rainbow[2] == Red )
   	{
   		if ( high_low <= IndiceStrengthSell )
   		{
   			if ( NormalizeDouble( cur_score_1, 0 ) - NormalizeDouble( cur_score, 0 ) >= CurrencyScoreDiff )
   			{
   				if ( gen_sn_score == "о" && gen_fis_score == "о" ) { create_signal_arrow( "gen", iTime( _Symbol, Period(), 0 ), iHigh( _Symbol, Period(), 0 ) + ArrowShift*Point, SellArrowGeneral, SYMBOL_ARROWDOWN ); }
   			}
   		}
   	}
   }
   
   if ( current_tf_index >= 0 )
   {
   	//--а затем сигнал текушего ТФ
   	if ( tf_multi_score[current_tf_index] >= MultiScoreSignal )
   	{
   		//buy
   		if ( tf_multi_color[current_tf_index] == Lime )
   		{
   			if ( high_low >= IndiceStrengthBuy )
   			{
   				if ( NormalizeDouble( cur_score, 0 ) - NormalizeDouble( cur_score_1, 0 ) >= CurrencyScoreDiff )
   				{
   					if ( tf_sn_score[current_tf_index] == "м" && tf_fis_score[current_tf_index] == "м" ) { create_signal_arrow( "cur", iTime( _Symbol, Period(), 0 ), iLow( _Symbol, Period(), 0 ) - (ArrowShift+10)*Point, BuyArrowCurrent, SYMBOL_ARROWUP ); }
   				}
   			}
   		}
   	
   		//sell
   		if ( tf_multi_color[current_tf_index] == Red )
   		{
   			if ( high_low <= IndiceStrengthSell )
   			{
   				if ( NormalizeDouble( cur_score_1, 0 ) - NormalizeDouble( cur_score, 0 ) >= CurrencyScoreDiff )
   				{
   					if ( tf_sn_score[current_tf_index] == "о" && tf_fis_score[current_tf_index] == "о" ) { create_signal_arrow( "cur", iTime( _Symbol, Period(), 0 ), iHigh( _Symbol, Period(), 0 ) + (ArrowShift+10)*Point, SellArrowCurrent, SYMBOL_ARROWDOWN ); }
   				}
   			}
   		}
   	}
   }
   
   int WIN = WindowFind( short_name );
   if ( WIN < 0 ) { WIN = 0; }
   
   DrawBackGround( "!##_", trade_rainbow, general_rainbow, final_values, WIN );
   
   return (0);
}

int Lookup(double ad_0) {
   int li_ret_8;
   int lia_12[10] = {0, 3, 10, 25, 40, 50, 60, 75, 90, 97};
   if (ad_0 <= lia_12[0]) li_ret_8 = 0;
   else {
      if (ad_0 < lia_12[1]) li_ret_8 = 0;
      else {
         if (ad_0 < lia_12[2]) li_ret_8 = 1;
         else {
            if (ad_0 < lia_12[3]) li_ret_8 = 2;
            else {
               if (ad_0 < lia_12[4]) li_ret_8 = 3;
               else {
                  if (ad_0 < lia_12[5]) li_ret_8 = 4;
                  else {
                     if (ad_0 < lia_12[6]) li_ret_8 = 5;
                     else {
                        if (ad_0 < lia_12[7]) li_ret_8 = 6;
                        else {
                           if (ad_0 < lia_12[8]) li_ret_8 = 7;
                           else {
                              if (ad_0 < lia_12[9]) li_ret_8 = 8;
                              else li_ret_8 = 9;
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return (li_ret_8);
}

double GetPoint(string symbol)
{
   symbol = StringSubstr( symbol, 0, 6 );
   return( MarketInfo( symbol, MODE_POINT ) );
}

int iLookup(double ad_0) {
   int li_ret_8;
   int lia_12[10] = {0, 3, 10, 25, 40, 50, 60, 75, 90, 97};
   if (ad_0 <= lia_12[0]) li_ret_8 = 0;
   else {
      if (ad_0 < lia_12[1]) li_ret_8 = 0;
      else {
         if (ad_0 < lia_12[2]) li_ret_8 = 1;
         else {
            if (ad_0 < lia_12[3]) li_ret_8 = 2;
            else {
               if (ad_0 < lia_12[4]) li_ret_8 = 3;
               else {
                  if (ad_0 < lia_12[5]) li_ret_8 = 4;
                  else {
                     if (ad_0 < lia_12[6]) li_ret_8 = 5;
                     else {
                        if (ad_0 < lia_12[7]) li_ret_8 = 6;
                        else {
                           if (ad_0 < lia_12[8]) li_ret_8 = 7;
                           else {
                              if (ad_0 < lia_12[9]) li_ret_8 = 8;
                              else li_ret_8 = 9;
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return (li_ret_8);
}

//+-------Новые функции-------
//--ТФ из числа в строку
string strPeriod( int intPeriod )
{
	switch ( intPeriod )
	{
		case PERIOD_MN1: return("MN1");
		case PERIOD_W1:  return("W1");
		case PERIOD_D1:  return("D1");
		case PERIOD_H4:  return("H4");
		case PERIOD_H1:  return("H1");
		case PERIOD_M30: return("M30");
		case PERIOD_M15: return("M15");
		case PERIOD_M5:  return("M5");
		case PERIOD_M1:  return("M1");
		
		default:		     return("M"+intPeriod);
	}
}

//--ТФ из строки в число
int intPeriod( string strPeriod )
{
	if ( strPeriod == "MN1"	)	{ return ( PERIOD_MN1 ); }
	if ( strPeriod == "W1"	)	{ return ( PERIOD_W1	 ); }
	if ( strPeriod == "D1"	)	{ return ( PERIOD_D1	 ); }
	if ( strPeriod == "H4"	)	{ return ( PERIOD_H4	 ); }
	if ( strPeriod == "H1"	)	{ return ( PERIOD_H1	 ); }
	if ( strPeriod == "M30" )	{ return ( PERIOD_M30 ); }
	if ( strPeriod == "M15" )	{ return ( PERIOD_M15 ); }
	if ( strPeriod == "M5"	)	{ return ( PERIOD_M5	 ); }
	if ( strPeriod == "M1"	)	{ return ( PERIOD_M1	 ); }
	
	return(-1);
}

//--удаление объектов по маске
void obj_delete( string prefix )
{
	int obj_total = ObjectsTotal();
	string name;
	
	for ( int i = obj_total - 1; i >= 0; i -- )
	{
		name = ObjectName(i);
		if ( StringFind( name, prefix ) >= 0 ) { ObjectDelete( name ); }
	}
}

//--рисует задний фон индикатора в окне win_num
void DrawBackGround( string prefix, color iColor[], color gColor[], string values[], int win_num )
{
	int size = ArraySize( tf );
	
	int		handle_win, font_size;
	int		rect[4];
	double	right_to_left, size_in_pixels;
	
	if ( FontSize < 1 ) //--динамическое распределение объектов
	{
		//--сначала получаем всю ширину, которую нам можно использовать:
		handle_win = WindowHandle( _Symbol, Period() ); //--окно в котором работает индикатор	
		GetWindowRect( handle_win, rect );
	
		//--затем вычисляем размер объектов в пикселях и кегль шрифта
		right_to_left	= NormalizeDouble( rect[2] - rect[0], 0 );							//--расстояние между левой и правой границами экрана
		size_in_pixels	= NormalizeDouble( MathFloor((right_to_left - 20)/36.0), 0 );	//--размер шрифта в пикселях
		font_size		= NormalizeDouble( MathFloor( size_in_pixels*4.0/3.0 ), 0 );	//--кегль шрифта
	}
	else //--жестко заданное размещение
	{
		font_size = FontSize*4;
		size_in_pixels = NormalizeDouble( FontSize*3.0, 0 );
	}
	
	//--инициализируем имя объектов
	string body = "back_ground_item_";
	string name = "";
	
	int		X					= 5; //--ось X
	int		Y					= 0; //--ось Y
	
	int		shift_X			= 0;	//--сдвиг по оси Х для каждого нового объекта в строке (вправо)
	int		shift_Y			= 0;	//--сдвиг по оси Y для каждого нового объекта в столбце (вниз)
	
	int		i, j, k;
	
	int		color_index		= 0;
	int		sub_index		= 0;
	int		val_index		= 0;
	int		sub_val_index	= 0;
	
	string	str[7] = { "", "Рекомендация:", "Кр-й:Sell, Зел-й:Buy", "Sell 0-1-2, Buy 7-8-9", "Sell=0-5,2-8, Buy=7-2,9-3", "Индикатор MACD", "Индикатор Stochastic" };
	
	string	font	 = "";
	
	str[0] = _Symbol;
	
	for ( k = 0; k < 7; k ++ )
	{
		if ( k < 5 ) { font = "Tahoma"; }
		else { font = "Wingdings"; }
		
		//--рисуем задний фон для заголовков и общей текстовой информации
		for ( i = 0; i < 4; i ++ )
		{
			name = prefix + body + DoubleToStr( k, 0 ) + DoubleToStr( i, 0 );
			
			if ( ObjectFind( name ) < 0 ) { ObjectCreate( name, OBJ_LABEL, win_num, 0, 0 ); } //--если объекта нет - создаем
			//--модифицируем свойства
			ObjectSet( name, OBJPROP_BACK, true ); //--отрисовка на заднем плане (фон)
			ObjectSet( name, OBJPROP_CORNER, 0 );
			ObjectSet( name, OBJPROP_XDISTANCE, X + shift_X - 1*i );
			ObjectSet( name, OBJPROP_YDISTANCE, Y + shift_Y );
			ObjectSetText( name, "n", font_size, "Wingdings", CaptionBGColor );
			
			if ( i < 1 )
			{
				if ( ObjectFind( name + "_text" ) < 0 ) { ObjectCreate( name + "_text", OBJ_LABEL, win_num, 0, 0 ); }
				ObjectSet( name + "_text", OBJPROP_BACK, false ); //--отрисовка на заднем плане (фон)
				ObjectSet( name + "_text", OBJPROP_CORNER, 0 );
				ObjectSet( name + "_text", OBJPROP_XDISTANCE, X + shift_X - 1*i + size_in_pixels*0.1 );
				ObjectSet( name + "_text", OBJPROP_YDISTANCE, Y + shift_Y + size_in_pixels*0.65 );
				if ( k > 0 ) { ObjectSetText( name + "_text", str[k], font_size/4, "Arial", CaptionTextColor ); }
				else { ObjectSetText( name + "_text", str[k], font_size/4, "Arial Black", CurrencyTextColor ); }
			}
			
			shift_X += NormalizeDouble( size_in_pixels, 0 );
		}
	
		//--рисуем задний фон для колонок с ТФ
		for ( i = 0; i < size; i ++ )
		{
			shift_X += NormalizeDouble( size_in_pixels, 0 );
			name = prefix + body + "_tf_" + DoubleToStr( k, 0 ) + DoubleToStr( i, 0 );
		
			if ( k < 1 )
			{
				if ( ObjectFind( name + "_timeframe" ) < 0 ) { ObjectCreate( name + "_timeframe", OBJ_LABEL, win_num, 0, 0 ); }
				//--модифицируем свойства
				ObjectSet( name + "_timeframe", OBJPROP_BACK, false ); //--отрисовка на заднем плане (фон)
				ObjectSet( name + "_timeframe", OBJPROP_CORNER, 0 );
				ObjectSet( name + "_timeframe", OBJPROP_XDISTANCE, X + shift_X + size_in_pixels*0.65  );
				ObjectSet( name + "_timeframe", OBJPROP_YDISTANCE, Y + shift_Y + size_in_pixels*0.65 );
				ObjectSetText( name + "_timeframe", strPeriod(tf[i]), font_size/3, "Arial", CaptionTextColor );
			}
			else
			{
				if ( ObjectFind( name + "_values" ) < 0 ) { ObjectCreate( name + "_values", OBJ_LABEL, win_num, 0, 0 ); }
				//--модифицируем свойства
				ObjectSet( name + "_values", OBJPROP_BACK, false ); //--отрисовка на заднем плане (фон)
				ObjectSet( name + "_values", OBJPROP_CORNER, 0 );
				ObjectSet( name + "_values", OBJPROP_XDISTANCE, X + shift_X + size_in_pixels*0.65  );
				ObjectSet( name + "_values", OBJPROP_YDISTANCE, Y + shift_Y + size_in_pixels*0.65 );
				ObjectSetText( name + "_values", values[val_index], font_size/3, font, ValuesTextColor );
			}
		
			for ( j = 0; j < 2; j ++ )
			{
				name = name + DoubleToStr( j, 0 );
			
				if ( ObjectFind( name ) < 0 ) { ObjectCreate( name, OBJ_LABEL, win_num, 0, 0 ); } //--если объекта нет - создаем
				//--модифицируем свойства
				ObjectSet( name, OBJPROP_BACK, true ); //--отрисовка на заднем плане (фон)
				ObjectSet( name, OBJPROP_CORNER, 0 );
				ObjectSet( name, OBJPROP_XDISTANCE, X + shift_X - 1*j );
				ObjectSet( name, OBJPROP_YDISTANCE, Y + shift_Y );
				if ( k == 4 && j > 0 ) { ObjectSetText( name, "n", font_size, "Wingdings", iColor[color_index+size] ); }
				else { ObjectSetText( name, "n", font_size, "Wingdings", iColor[color_index] ); }
				
				shift_X += NormalizeDouble( size_in_pixels, 0 );
			}
			
			color_index ++;
			
			if ( k > 0 )
			{
				val_index ++;
				if (	val_index == size || val_index == size*2+1 ||
						val_index == size*3+2 || val_index == size*4+3 ||
						val_index == size*5+4 || val_index == size*6+5 ) { val_index ++; }
			}
		}
	
		if ( k == 4 ) { color_index += size;  } //--если мы уже отрисовали ячейки двойного цвета, перескакиваем их
	
		if ( k < 1 )
		{
			if ( ObjectFind( name + "_general" ) < 0 ) { ObjectCreate( name + "_general", OBJ_LABEL, win_num, 0, 0 ); }
			ObjectSet( name + "_general", OBJPROP_BACK, false ); //--отрисовка на заднем плане (фон)
			ObjectSet( name + "_general", OBJPROP_CORNER, 0 );
			ObjectSet( name + "_general", OBJPROP_XDISTANCE, X + shift_X + size_in_pixels*0.45  );
			ObjectSet( name + "_general", OBJPROP_YDISTANCE, Y + shift_Y + size_in_pixels*0.65 );
			ObjectSetText( name + "_general", "Общая тенденция", font_size/4, "Arial", CaptionTextColor );
		}
		else
		{
			if ( ObjectFind( name + "_gen_val" + k ) < 0 ) { ObjectCreate( name + "_gen_val" + k, OBJ_LABEL, win_num, 0, 0 ); }
			//--модифицируем свойства
			ObjectSet( name + "_gen_val" + k, OBJPROP_BACK, false ); //--отрисовка на заднем плане (фон)
			ObjectSet( name + "_gen_val" + k, OBJPROP_CORNER, 0 );
			ObjectSet( name + "_gen_val" + k, OBJPROP_XDISTANCE, X + shift_X + size_in_pixels*1.65 );
			ObjectSet( name + "_gen_val" + k, OBJPROP_YDISTANCE, Y + shift_Y + size_in_pixels*0.65 );
			ObjectSetText( name + "_gen_val" + k, values[sub_val_index+size], font_size/3, font, ValuesTextColor );
		}
	
		if ( k > 0 ) { sub_val_index += (size+1); }
		
		for ( i = 0; i < 2; i ++ )
		{
			name = prefix + body + "_general_" + DoubleToStr( k, 0 ) + DoubleToStr( i, 0 );
			shift_X += NormalizeDouble( size_in_pixels, 0 );
			
			if ( ObjectFind( name ) < 0 ) { ObjectCreate( name, OBJ_LABEL, win_num, 0, 0 ); } //--если объекта нет - создаем
			//--модифицируем свойства
			ObjectSet( name, OBJPROP_BACK, true ); //--отрисовка на заднем плане (фон)
			ObjectSet( name, OBJPROP_CORNER, 0 );
			ObjectSet( name, OBJPROP_XDISTANCE, X + shift_X - 1*i );
			ObjectSet( name, OBJPROP_YDISTANCE, Y + shift_Y );
			if ( k == 4 && i > 0 ) { ObjectSetText( name, "n", font_size, "Wingdings", gColor[sub_index+1] ); }
			else { ObjectSetText( name, "n", font_size, "Wingdings", gColor[sub_index] ); }
		}
		
		sub_index ++;
		if ( k == 4 ) { sub_index ++; }
		
		shift_Y += size_in_pixels*1.1;
		shift_X = 0;
	}
	
	WindowRedraw();
}

void create_signal_arrow( string prefix, datetime time, double price, color clr, int arrow_code )
{
	string	name			= "!##_" + prefix + "_signal_arrow_" + TimeToStr( time );
	
	string	str			= "";
	datetime last_arrow	= 0;
	color		last_color	= CLR_NONE;
	
	for ( int i = ObjectsTotal() - 1; i >= 0; i -- )
	{
		str = ObjectName(i);
		if ( StringFind( str, prefix + "_signal_arrow_", 0 ) < 0 ) { continue; }
		if ( ObjectGet	( str, OBJPROP_TIME1 ) > last_arrow  )
		{
			last_arrow	= ObjectGet( str, OBJPROP_TIME1 );
			last_color	= ObjectGet( str, OBJPROP_COLOR );
		}
		
	}
	
	//--если последняя нарисованая стрелка имеет такое же направление как и та, что мы собираемся нарисовать, выходим
	if ( last_color == clr ) { return; }
	
	if ( ObjectFind( name ) < 0 ) { ObjectCreate( name, OBJ_ARROW, 0, time, price ); }
	ObjectSet( name, OBJPROP_ARROWCODE, arrow_code );
	ObjectSet( name, OBJPROP_COLOR, clr );
	ObjectSet( name, OBJPROP_TIME1, time );
	ObjectSet( name, OBJPROP_PRICE1, price );
	
	WindowRedraw();
}