Why cant I see upper and lower keltner lines on chart?

Back to topics list To post a new topic, please log in or register
avatar
52
renzbub 2015.12.05 19:04
 

In the following code im trying to simply create keltner channels but i cant see why it doesnt display the upper and lower lines on the chart. 

input int Keltner_Period=20;
input double Keltner_ATR=1.5;
input int Keltner_MaMode=MODE_SMA;

// OnTick() event handler                
void OnTick()
{
   double close = Close[1];  
   datetime time = iTime(_Symbol,0,1);
 
   string ob_Longs = "Longs "+TimeToStr(time);    
   string ob_Shorts = "Shorts "+TimeToStr(time);

   //--- Indicator Calculations
   double Kelt_Mid_Band = iMA(_Symbol,_Period,Keltner_Period,0,Keltner_MaMode,PRICE_CLOSE,i);
   double Kelt_Upper_Band = Kelt_Mid_Band + (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);
   double Kelt_Lower_Band = Kelt_Mid_Band - (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);'

   if(close > Kelt_Upper_Band) ObjectCreate(ob_Longs,OBJ_ARROW_UP,0,time,close);      

   if(close < Kelt_Lower_Band) ObjectCreate(ob_Shorts,OBJ_ARROW_DOWN,0,time,close);            
}









avatar
Moderator
3418
GumRai 2015.12.05 19:32 #
 

You don't have any code to draw the lines

   double Kelt_Mid_Band = iMA(_Symbol,_Period,Keltner_Period,0,Keltner_MaMode,PRICE_CLOSE,i);
   double Kelt_Upper_Band = Kelt_Mid_Band + (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);
   double Kelt_Lower_Band = Kelt_Mid_Band - (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);'

 I don't see where i is declared or given a value

avatar
52
renzbub 2015.12.06 13:07 #
 
GumRai:

You don't have any code to draw the lines

 I don't see where i is declared or given a value

I forgot to add int  i = 0; in my forum thread. I have tried to use int  i = 0; but i can only see the moving average? The ATR line appears as an ATR indicator in the seperate window. But I need to see it as an upper and lower keltner line? 

The code does work as intended but its for some reason the keltner bands are invisible? 

 

input int Keltner_Period=20;
input double Keltner_ATR=1.5;
input int Keltner_MaMode=MODE_SMA;

// OnTick() event handler                
void OnTick()
{
   double close = Close[1];  
   datetime time = iTime(_Symbol,0,1);
 
   string ob_Longs = "Longs "+TimeToStr(time);    
   string ob_Shorts = "Shorts "+TimeToStr(time);

   int i = 1;

   //--- Indicator Calculations
   double Kelt_Mid_Band = iMA(_Symbol,_Period,Keltner_Period,0,Keltner_MaMode,PRICE_CLOSE,i);
   double Kelt_Upper_Band = Kelt_Mid_Band + (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);
   double Kelt_Lower_Band = Kelt_Mid_Band - (iATR(_Symbol,_Period,Keltner_Period,i)*Keltner_ATR);'

   if(close > Kelt_Upper_Band) ObjectCreate(ob_Longs,OBJ_ARROW_UP,0,time,close);      

   if(close < Kelt_Lower_Band) ObjectCreate(ob_Shorts,OBJ_ARROW_DOWN,0,time,close);            
}

 

avatar
Moderator
3418
GumRai 2015.12.06 13:18 #
 
If you want to see the lines, I suggest that you write an indicator to show the lines.
avatar
52
renzbub 2015.12.06 14:00 #
 
GumRai:
If you want to see the lines, I suggest that you write an indicator to show the lines.
Is it not possible to see keltner lines on an expert advisor as it is say bollinger bands using iBand() function? 
avatar
Moderator
3418
GumRai 2015.12.06 14:15 #
 
Unless something has changed, calling iBand() from an EA will not cause the BB lines to be printed on the chart. The exception being in the strategy tester at the end of a test.
avatar
52
renzbub 2015.12.06 14:34 #
 
GumRai:
Unless something has changed, calling iBand() from an EA will not cause the BB lines to be printed on the chart. The exception being in the strategy tester at the end of a test.
Is it possible to use an indicator like an include file so i could write it then apply it to an EA?
avatar
Moderator
3418
GumRai 2015.12.06 20:32 #
 
Eas cannot draw lines in the same way as an indicator using buffers
avatar
13001
WHRoeder 2015.12.06 22:06 #
 
EA's have no eyes; they don't need it to be on the chart. If you need it to be, attach the indicator.
Back to topics list  

To add comments, please log in or register