Как убрать показания на каждом баре (объекты)

time_of_money

Местный
Как убрать показания на каждом баре (объекты)?

Я хочу присвоить индикатору(объект) при пересечении 2 линий или 0 линии на общем графике, к примеру -- код:

Код:
//+------------------------------------------------------------------+
//#property indicator_separate_window
#property indicator_chart_window
//#property indicator_minimum -1
//#property indicator_maximum 1
#property indicator_buffers 4
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_width2 4
#property indicator_width3 4
//----
int   LeftNum1=56;
int   LeftNum2=56;
//----
extern int     RangePeriods=10;
extern double  PriceSmoothing=0.3;    // =0.67 bei Fisher_m10 
extern double  IndexSmoothing=0.3;    // =0.50 bei Fisher_m10
string         ThisName="Fisher_m11";
int            DrawStart;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   SetIndexLabel(0,"Fish");
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexBuffer(3,ExtMapBuffer4);
//----
   string Text=ThisName;
   Text=Text+"  (rPeriods "+RangePeriods;
   Text=Text+", pSmooth "+DoubleToStr(PriceSmoothing,2);
   Text=Text+", iSmooth "+DoubleToStr(IndexSmoothing,2);
   Text=Text+")  ";
   IndicatorShortName(Text);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   DrawStart=2*RangePeriods+4;             // DrawStart= BarNumber calculated from left to right
   SetIndexDrawBegin(1,DrawStart);
   SetIndexDrawBegin(2,DrawStart);
//----
   if (PriceSmoothing>=1.0)
     {
      PriceSmoothing=0.9999;
      Alert("Fish61: PriceSmothing factor has to be smaller 1!");
     }
   if (PriceSmoothing<0)
     {
      PriceSmoothing=0;
      Alert("Fish61: PriceSmothing factor mustn''t be negative!");
     }
   if (IndexSmoothing>=1.0)
     {
      IndexSmoothing=0.9999;
      Alert("Fish61: PriceSmothing factor has to be smaller 1!");
     }
   if (IndexSmoothing<0)
     {
      IndexSmoothing=0;
      Alert("Fish61: PriceSmothing factor mustn''t be negative!");
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
ObjectsDeleteAll();    
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if (Bars<DrawStart)
     {
      Alert("Fish84: Not enough Bars loaded to calculate FisherIndicator with RangePeriods=",RangePeriods);
      return(-1);
     }
//----   
   int    counted_bars=IndicatorCounted();
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
//----
   int Position=Bars-counted_bars;        // Position = BarPosition calculated from right to left
   int LeftNum1=Bars-Position;            // when more bars are loaded the Position of a bar changes but not its LeftNum
   if (LeftNum1<RangePeriods+1)Position=Bars-RangePeriods-1;
//----
   while(Position>=0)
     {
      CalculateCurrentBar(Position);
      Position--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Single Bar Calculation function                                  |
//+------------------------------------------------------------------+
int CalculateCurrentBar(int pos)
  {
   double  LowestLow, HighestHigh, GreatestRange, MidPrice;
   double  PriceLocation, SmoothedLocation, FishIndex, SmoothedFish;
//----
   LowestLow=Low[Lowest(NULL,0,MODE_LOW,RangePeriods,pos)];
   HighestHigh=High[Highest(NULL,0,MODE_HIGH,RangePeriods,pos)];
   if (HighestHigh-LowestLow<0.1*Point)HighestHigh=LowestLow+0.1*Point;
   GreatestRange=HighestHigh-LowestLow;
   MidPrice=(High[pos]+Low[pos])/2;
   // PriceLocation in current Range 
   if (GreatestRange!=0)
     {
      PriceLocation=(MidPrice-LowestLow)/GreatestRange;
      PriceLocation= 2.0*PriceLocation - 1.0;           // ->  -1 < PriceLocation < +1
     }
   // Smoothing of PriceLocation
   ExtMapBuffer4[pos]=PriceSmoothing*ExtMapBuffer4[pos+1]+(1.0-PriceSmoothing)*PriceLocation;
   SmoothedLocation=ExtMapBuffer4[pos];
   if (SmoothedLocation> 0.99) SmoothedLocation= 0.99; // verhindert, dass MathLog unendlich wird
   if (SmoothedLocation<-0.99) SmoothedLocation=-0.99; // verhindert, dass MathLog minuns unendlich wird
   // FisherIndex
   if(1-SmoothedLocation!=0) FishIndex=MathLog((1+SmoothedLocation)/(1-SmoothedLocation));
   else Alert("Fisher129: Unerlaubter Zustand bei Bar Nummer ",Bars-pos);
   // Smoothing of FisherIndex
   ExtMapBuffer1[pos]=IndexSmoothing*ExtMapBuffer1[pos+1]+(1.0-IndexSmoothing)*FishIndex;
   if (Bars-pos<DrawStart)ExtMapBuffer1[pos]=0;
   SmoothedFish=ExtMapBuffer1[pos];
//----
   if (SmoothedFish>0)     // up trend
     {
      ExtMapBuffer2[pos]=SmoothedFish;
      ExtMapBuffer3[pos]=0;
     }
   else                          // else down trend
     {
      ExtMapBuffer2[pos]=0;
      ExtMapBuffer3[pos]=SmoothedFish;
     }
     
     
     
     
     
 //-----------------------======================================================================
   {  
   if(ExtMapBuffer2[pos]>0)
  { 
   bool l1=ObjectCreate("Buy"+pos, OBJ_ARROW,0,iTime(NULL,0,pos),iLow(NULL,0,pos)-10*Point);
   datetime t1=ObjectGet("Buy"+pos, OBJPROP_TIME1);
   ObjectSet("Buy"+pos,OBJPROP_ARROWCODE,SYMBOL_ARROWUP);
   ObjectSet("Buy"+pos,OBJPROP_COLOR,Aqua);
     }
   if(ExtMapBuffer3[pos]<0)
  { 
   bool l2=ObjectCreate("Sell"+pos, OBJ_ARROW,0,iTime(NULL,0,pos),iHigh(NULL,0,pos)+10*Point);
   datetime t2=ObjectGet("Sell"+pos, OBJPROP_TIME1);
   ObjectSet("Sell"+pos,OBJPROP_ARROWCODE,SYMBOL_ARROWDOWN);
   ObjectSet("Sell"+pos,OBJPROP_COLOR,Red);
   
     }
   
   }
   //---------------------======================================================================       
     

     
//----
   return(0);
  }
//+------------------------------------------------------------------+
Показатель выводится на каждом баре, что еще следует сделать чтобы
сигнал на общем графике выводился только при смене тренда, а не на каждом?

К примеру получилось:



Хочется так:

 

ale002

Пользователь
Дак у вас картинка от какого-то др кода ?? В этом коде единственный объект - стрелка, если вопрос про неё, то попробуйте условие

if(ExtMapBuffer2[pos]>0)

заменить на

if(ExtMapBuffer2[pos]>0 && ExtMapBuffer2[pos+1] == EMPTY_VALUE)

и для ExtMapBuffer3 - аналогично

Исчо - в этом коде имена объектов формируются из ИНДЕКСОВ баров "Buy"+pos, т.е. напр при запуске индикатор нарисовал такой объект на нулевом баре, имя ему будет "Buy0", через час появился новый сигнал на покупку на нулевом баре и имя ему по вашему коду снова будет "Buy0". В резалте старый объект скакнёт на нулевой бар, а места прошлого сигнала вы не найдёте, а после перезапуска он снова появиццо.. Поменяйте "Buy"+pos на "Buy"+Time[pos] (Sell - аналогично)
 

time_of_money

Местный
Дак у вас картинка от какого-то др кода ?? В этом коде единственный объект - стрелка, если вопрос про неё, то попробуйте условие

if(ExtMapBuffer2[pos]>0)

заменить на

if(ExtMapBuffer2[pos]>0 && ExtMapBuffer2[pos+1] == EMPTY_VALUE)

и для ExtMapBuffer3 - аналогично

Исчо - в этом коде имена объектов формируются из ИНДЕКСОВ баров "Buy"+pos, т.е. напр при запуске индикатор нарисовал такой объект на нулевом баре, имя ему будет "Buy0", через час появился новый сигнал на покупку на нулевом баре и имя ему по вашему коду снова будет "Buy0". В резалте старый объект скакнёт на нулевой бар, а места прошлого сигнала вы не найдёте, а после перезапуска он снова появиццо.. Поменяйте "Buy"+pos на "Buy"+Time[pos] (Sell - аналогично)
Все сделал как Вы сказали но безуспешно, что касается стрелок исправил как и на скриншоте....

Код:
//-----------------------======================================================================
   {  
   if(ExtMapBuffer3[pos]>0 && ExtMapBuffer3[pos+1] == EMPTY_VALUE)
  { 
   bool l1=ObjectCreate("Buy"+Time[pos], OBJ_VLINE,0,iTime(NULL,0,pos),iLow(NULL,0,pos)-10*Point);
   datetime t1=ObjectGet("Buy"+Time[pos], OBJPROP_TIME1);
   ObjectSet("Buy"+Time[pos],OBJPROP_COLOR,Aqua);
     }
   if(ExtMapBuffer2[pos]<0 && ExtMapBuffer2[pos+1] == EMPTY_VALUE)
  { 
   bool l2=ObjectCreate("Sell"+Time[pos], OBJ_VLINE,0,iTime(NULL,0,pos),iHigh(NULL,0,pos)+10*Point);
   datetime t2=ObjectGet("Sell"+Time[pos], OBJPROP_TIME1);
   ObjectSet("Sell"+Time[pos],OBJPROP_COLOR,Red);
   
     }
   
   }
   //---------------------======================================================================
Все пока безуспешно!.
 

time_of_money

Местный
Безуспешно пробовал по разному, примеров много но не один не подходит.

К примеру обычный MA, все работает при изменении выше 0 отметки...

Код:
[B]#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  Green
#property  indicator_color3  Red

//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];

extern int ShortMA=32;
extern int LongMA=208;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,2);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,32);
   SetIndexDrawBegin(1,32);
   SetIndexDrawBegin(2,32);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("CAO("+ShortMA+","+LongMA+")");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
//---- initialization done
   return(0);
  }
  
 
  int deinit()
  {
ObjectsDeleteAll();    
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd
   for(int i=0; i<limit; i++)
      ExtBuffer0[i]=iMA(NULL,0,ShortMA,0,MODE_SMA,PRICE_CLOSE,i)-iMA(NULL,0,LongMA,0,MODE_SMA,PRICE_CLOSE,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
     }
     
  //-----------------------======================================================================
  for(i=limit-1; i>=0; i--)
  
  
   {  
   if(ExtBuffer2[i]!=0 && ExtBuffer1[i-1]!=0)
  { 
   bool l1=ObjectCreate("Buy"+i, OBJ_ARROW,0,iTime(NULL,0,i),iLow(NULL,0,i)-10*Point);
   datetime t1=ObjectGet("Buy"+i, OBJPROP_TIME1);
   ObjectSet("Buy"+i,OBJPROP_ARROWCODE,SYMBOL_ARROWUP);
   ObjectSet("Buy"+i,OBJPROP_COLOR,Aqua);
     }
   if(ExtBuffer2[i-1]!=0 && ExtBuffer1[i]!=0)
  { 
   bool l2=ObjectCreate("Sell"+i, OBJ_ARROW,0,iTime(NULL,0,i),iHigh(NULL,0,i)+10*Point);
   datetime t2=ObjectGet("Sell"+i, OBJPROP_TIME1);
   ObjectSet("Sell"+i,OBJPROP_ARROWCODE,SYMBOL_ARROWDOWN);
   ObjectSet("Sell"+i,OBJPROP_COLOR,Red);
     }
   
   }
   //---------------------======================================================================           
     
//---- done
   return(0);
  }[/B]
 
Последнее редактирование:

ale002

Пользователь
Это ваш предыдущий пример
PHP:
//+------------------------------------------------------------------+
#property indicator_separate_window
//#property indicator_chart_window
//#property indicator_minimum -1
//#property indicator_maximum 1
#property indicator_buffers 4
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_width2 4
#property indicator_width3 4
//----
int	LeftNum1=56;
int	LeftNum2=56;
//----
extern int	  RangePeriods=10;
extern double  PriceSmoothing=0.3;	 // =0.67 bei Fisher_m10 
extern double  IndexSmoothing=0.3;	 // =0.50 bei Fisher_m10
string			ThisName="Fisher_m11";
int				DrawStart;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function								 |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
	IndicatorBuffers(4);
	SetIndexLabel(0,"Fish");
	SetIndexStyle(0,DRAW_NONE);
	SetIndexBuffer(0,ExtMapBuffer1);
	SetIndexStyle(1,DRAW_HISTOGRAM);
	SetIndexBuffer(1,ExtMapBuffer2);
	SetIndexStyle(2,DRAW_HISTOGRAM);
	SetIndexBuffer(2,ExtMapBuffer3);
	SetIndexStyle(3,DRAW_NONE);
	SetIndexBuffer(3,ExtMapBuffer4);
//----
	string Text=ThisName;
	Text=Text+"  (rPeriods "+RangePeriods;
	Text=Text+", pSmooth "+DoubleToStr(PriceSmoothing,2);
	Text=Text+", iSmooth "+DoubleToStr(IndexSmoothing,2);
	Text=Text+")  ";
	IndicatorShortName(Text);
	SetIndexLabel(1,NULL);
	SetIndexLabel(2,NULL);
	DrawStart=2*RangePeriods+4;				 // DrawStart= BarNumber calculated from left to right
	SetIndexDrawBegin(1,DrawStart);
	SetIndexDrawBegin(2,DrawStart);
//----
	if (PriceSmoothing>=1.0)
	  {
		PriceSmoothing=0.9999;
		Alert("Fish61: PriceSmothing factor has to be smaller 1!");
	  }
	if (PriceSmoothing<0)
	  {
		PriceSmoothing=0;
		Alert("Fish61: PriceSmothing factor mustn''t be negative!");
	  }
	if (IndexSmoothing>=1.0)
	  {
		IndexSmoothing=0.9999;
		Alert("Fish61: PriceSmothing factor has to be smaller 1!");
	  }
	if (IndexSmoothing<0)
	  {
		IndexSmoothing=0;
		Alert("Fish61: PriceSmothing factor mustn''t be negative!");
	  }
//----
	return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function							  |
//+------------------------------------------------------------------+
int deinit()
  {
ObjectsDeleteAll();	 
	return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function										|
//+------------------------------------------------------------------+
int start()
  {
	if (Bars<DrawStart)
	  {
		Alert("Fish84: Not enough Bars loaded to calculate FisherIndicator with RangePeriods=",RangePeriods);
		return(-1);
	  }
//----	
	int	 counted_bars=IndicatorCounted();
	if (counted_bars<0) return(-1);
	if (counted_bars>0) counted_bars--;
//----
	int Position=Bars-counted_bars;		  // Position = BarPosition calculated from right to left
	int LeftNum1=Bars-Position;				// when more bars are loaded the Position of a bar changes but not its LeftNum
	if (LeftNum1<RangePeriods+1)Position=Bars-RangePeriods-1;
//----
	while(Position>=0)
	  {
		CalculateCurrentBar(Position);
		Position--;
	  }
//----
	return(0);
  }
//+------------------------------------------------------------------+
//| Single Bar Calculation function											 |
//+------------------------------------------------------------------+
int CalculateCurrentBar(int pos)
  {
	double  LowestLow, HighestHigh, GreatestRange, MidPrice;
	double  PriceLocation, SmoothedLocation, FishIndex, SmoothedFish;
//----
	LowestLow=Low[Lowest(NULL,0,MODE_LOW,RangePeriods,pos)];
	HighestHigh=High[Highest(NULL,0,MODE_HIGH,RangePeriods,pos)];
	if (HighestHigh-LowestLow<0.1*Point)HighestHigh=LowestLow+0.1*Point;
	GreatestRange=HighestHigh-LowestLow;
	MidPrice=(High[pos]+Low[pos])/2;
	// PriceLocation in current Range 
	if (GreatestRange!=0)
	  {
		PriceLocation=(MidPrice-LowestLow)/GreatestRange;
		PriceLocation= 2.0*PriceLocation - 1.0;			  // ->  -1 < PriceLocation < +1
	  }
	// Smoothing of PriceLocation
	ExtMapBuffer4[pos]=PriceSmoothing*ExtMapBuffer4[pos+1]+(1.0-PriceSmoothing)*PriceLocation;
	SmoothedLocation=ExtMapBuffer4[pos];
	if (SmoothedLocation> 0.99) SmoothedLocation= 0.99; // verhindert, dass MathLog unendlich wird
	if (SmoothedLocation<-0.99) SmoothedLocation=-0.99; // verhindert, dass MathLog minuns unendlich wird
	// FisherIndex
	if(1-SmoothedLocation!=0) FishIndex=MathLog((1+SmoothedLocation)/(1-SmoothedLocation));
	else Alert("Fisher129: Unerlaubter Zustand bei Bar Nummer ",Bars-pos);
	// Smoothing of FisherIndex
	ExtMapBuffer1[pos]=IndexSmoothing*ExtMapBuffer1[pos+1]+(1.0-IndexSmoothing)*FishIndex;
	if (Bars-pos<DrawStart)ExtMapBuffer1[pos]=0;
	SmoothedFish=ExtMapBuffer1[pos];
//----
	if (SmoothedFish>0)	  // up trend
	  {
		ExtMapBuffer2[pos]=SmoothedFish;
		ExtMapBuffer3[pos]=0;
	  }
	else								  // else down trend
	  {
		ExtMapBuffer2[pos]=0;
		ExtMapBuffer3[pos]=SmoothedFish;
	  }



//-----------------------======================================================================
string sObjectName = "";
if(ExtMapBuffer3[pos] != 0 && ExtMapBuffer3[pos+1] == 0) {
	sObjectName = "Sell" + Time[pos];
	ObjectCreate(sObjectName, OBJ_VLINE, 0, Time[pos], 1);
	ObjectSet(sObjectName, OBJPROP_COLOR, Red);
}
if(ExtMapBuffer2[pos] != 0 && ExtMapBuffer2[pos+1] == 0) { 
	sObjectName = "Buy" + Time[pos];
	ObjectCreate(sObjectName, OBJ_VLINE, 0, Time[pos], 1);
	ObjectSet(sObjectName, OBJPROP_COLOR, Aqua);
}
	
	//---------------------======================================================================

	  

	  
//----
	return(0);
  }
//+------------------------------------------------------------------+
 

time_of_money

Местный
Спасибо забыл об обычном сравнении, благодарю за разяснение.


 

Онлайн статистика

Пользователи онлайн
1
Гости онлайн
62
Всего посетителей
63

Статистика форума

Темы
1 646
Сообщения
53 511
Пользователи
9 184
Новый пользователь
BoldikuFFs

Мы в социальных сетях

Вверх Снизу