Hi experienced coders...

I hope someone can help me with the next Problem....

I want to Create a Text Object above the current bar when my state is true.
But when the condition becomes true it will create 3 object back to my current bar. I have attached a screenshot of my chart. The state becomes true when the quicker stochastics crosses the signal line. But you will realize that the text objects will be 3 bars sooner.

Am I doing something incorrect? Please be patient. . I am new to coding.

Thank you for your help. .

Here comes the code...



#property copyright Copyright © 2006, MetaQuotes Software Corp..
#property link http://www.metaquotes.net

#property indior_chart_window
#property indior_buffers 9
#property indior_color1 Red
#property indior_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 indior initialization function |
// ------------------------------------------------------------------
int init()


//-- indiors
IndiorShortName(0);
//--
return(0);

// ------------------------------------------------------------------
//| Custom indior deinitialization function |
// ------------------------------------------------------------------
int deinit()

//--
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectsDeleteAll(0,OBJ_TEXT);
//--
return(0);

// ------------------------------------------------------------------
//| Custom indior iteration function |
// ------------------------------------------------------------------
int start()



//bars count
int limit, I, counter;
int counted_bars=IndiorCounted();
//-- check for possible errors
if(counted_barslt;0) return(-1);
//-- last counted bar is going to be recounted
if(counted_barsgt;0) counted_bars--;
//--
limit=Bars-counted_bars;
//--
for(I = 0; I lt;= limit; I )

counter=I;
Range=0;
AvgRange=0;
for (counter=I ;counterlt;=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 gt; 70) (stoch_main_m1 gt; stoch_sig_m1) ((stoch_main_m1_3 - stoch_main_m1) gt; 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 lt; 30) (stoch_main_m1 lt; stoch_sig_m1) ((stoch_main_m1 - stoch_main_m1_3) gt; 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));