Hi experienced coders...
I hope someone can help me with the following Problem....
I want to Create a Text Object above the current bar when my condition is true.
But when the condition becomes true it will create 3 object back to my current bar. I've attached a screenshot of my chart. the condition becomes true when the faster stochastics crosses the signal line. But you will see that the text objects will be 3 bars earlier.
Am I doing something wrong? Please be patient with me.. I'm new to coding.
Thanks for your help..
Here comes the code...
#property copyright "Copyright 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_color1 Red
#property indicator_color2 Green
int flagval1 = 0;
int flagval2 = 0;
double Range, AvgRange;
extern int bars_back = 0;
extern bool display_points = true;
extern bool display_SS = true;
extern int K_period = 8;
extern int D_period = 3;
extern int S_period = 3;
extern int K_period3 = 34;
extern int D_period3 = 3;
extern int S_period3 = 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorShortName("0");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectsDeleteAll(0,OBJ_TEXT);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//bars count
int limit, i, counter;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//----
limit=Bars-counted_bars;
//----
for(i = 0; i <= limit; i++)
{
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+49;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/50;
//m1 data
double stoch_main_m1 = iStochastic(NULL,PERIOD_M1,K_period,D_period,S_per iod,MODE_SMA,1,MODE_MAIN,bars_back);
double stoch_sig_m1 = iStochastic(NULL,PERIOD_M1,K_period,D_period,S_per iod,MODE_SMA,1,MODE_SIGNAL,bars_back);
//m1 data 3 bruno
double stoch_main_m1_3 = iStochastic(NULL,PERIOD_M1,K_period3,D_period3,S_p eriod3,MODE_SMA,1,MODE_MAIN,bars_back);
double stoch_sig_m1_3 = iStochastic(NULL,PERIOD_M1,K_period3,D_period3,S_p eriod3,MODE_SMA,1,MODE_SIGNAL,bars_back);
}
//SS m1 up
if ((display_SS == true) && (stoch_main_m1_3 > 70) && (stoch_main_m1 > stoch_sig_m1) && ((stoch_main_m1_3 - stoch_main_m1) > 30))
{ if (i == 1 && flagval2==0)
{
flagval2=1;
flagval1=0;
}
ObjectCreate(GetName("S1",i), OBJ_TEXT, 0, Time[i], (Low[i] - Range*1.25));
ObjectSetText(GetName("S1",i),"S1", 8, "Arial Bold", Silver);
}
//SS m1 down
if ((display_SS == true) && (stoch_main_m1_3 < 30) && (stoch_main_m1 < stoch_sig_m1) && ((stoch_main_m1 - stoch_main_m1_3) > 30))
{ if (i == 1 && flagval1==0)
{
flagval1=1;
flagval2=0;
}
ObjectCreate(GetName("S1",i), OBJ_TEXT, 0, Time[i], (High[i] + Range*1.25));
ObjectSetText(GetName("S1",i),"S1", 8, "Arial Bold", Silver);
}
}
return(0);
//GetName Definiert für die Points auf den Bars
string GetName(string aName,int i)
{
return(aName+DoubleToStr(Time[i],0));
}
I hope someone can help me with the following Problem....
I want to Create a Text Object above the current bar when my condition is true.
But when the condition becomes true it will create 3 object back to my current bar. I've attached a screenshot of my chart. the condition becomes true when the faster stochastics crosses the signal line. But you will see that the text objects will be 3 bars earlier.
Am I doing something wrong? Please be patient with me.. I'm new to coding.
Thanks for your help..
Here comes the code...
#property copyright "Copyright 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_color1 Red
#property indicator_color2 Green
int flagval1 = 0;
int flagval2 = 0;
double Range, AvgRange;
extern int bars_back = 0;
extern bool display_points = true;
extern bool display_SS = true;
extern int K_period = 8;
extern int D_period = 3;
extern int S_period = 3;
extern int K_period3 = 34;
extern int D_period3 = 3;
extern int S_period3 = 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorShortName("0");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectsDeleteAll(0,OBJ_TEXT);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//bars count
int limit, i, counter;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//----
limit=Bars-counted_bars;
//----
for(i = 0; i <= limit; i++)
{
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+49;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/50;
//m1 data
double stoch_main_m1 = iStochastic(NULL,PERIOD_M1,K_period,D_period,S_per iod,MODE_SMA,1,MODE_MAIN,bars_back);
double stoch_sig_m1 = iStochastic(NULL,PERIOD_M1,K_period,D_period,S_per iod,MODE_SMA,1,MODE_SIGNAL,bars_back);
//m1 data 3 bruno
double stoch_main_m1_3 = iStochastic(NULL,PERIOD_M1,K_period3,D_period3,S_p eriod3,MODE_SMA,1,MODE_MAIN,bars_back);
double stoch_sig_m1_3 = iStochastic(NULL,PERIOD_M1,K_period3,D_period3,S_p eriod3,MODE_SMA,1,MODE_SIGNAL,bars_back);
}
//SS m1 up
if ((display_SS == true) && (stoch_main_m1_3 > 70) && (stoch_main_m1 > stoch_sig_m1) && ((stoch_main_m1_3 - stoch_main_m1) > 30))
{ if (i == 1 && flagval2==0)
{
flagval2=1;
flagval1=0;
}
ObjectCreate(GetName("S1",i), OBJ_TEXT, 0, Time[i], (Low[i] - Range*1.25));
ObjectSetText(GetName("S1",i),"S1", 8, "Arial Bold", Silver);
}
//SS m1 down
if ((display_SS == true) && (stoch_main_m1_3 < 30) && (stoch_main_m1 < stoch_sig_m1) && ((stoch_main_m1 - stoch_main_m1_3) > 30))
{ if (i == 1 && flagval1==0)
{
flagval1=1;
flagval2=0;
}
ObjectCreate(GetName("S1",i), OBJ_TEXT, 0, Time[i], (High[i] + Range*1.25));
ObjectSetText(GetName("S1",i),"S1", 8, "Arial Bold", Silver);
}
}
return(0);
//GetName Definiert für die Points auf den Bars
string GetName(string aName,int i)
{
return(aName+DoubleToStr(Time[i],0));
}
Attached Image