Please help with my ATR indicator - it's not loading up on new charts correctly.

 

Hi,

I've written this little indicator.

It takes the price Open of this day, and draws a line on the chart at 0%.

It then draws other lines based on the percentage of the ATR100 (daily) value.

When this indicator is 'dragged' onto a chart it works fine.... BUT.... when I then flick through other charts, it doesn't load up correctly unless I remove the indicator and re-load it up.

Please could you help me correct this code so that I can flick through charts and it loads up correctly without having to remove the indicator and add it again. I'm a bit puzzled at how to do this. I've attached my code and it's included below.

__________________


#property copyright "James Frog"
#property indicator_chart_window

double control=2147483647;


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll();

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {

double ATR100 = iATR(0,PERIOD_D1,100, 0);
double daysOpen = iOpen(0,PERIOD_D1,0);


// Line of the opening price of the day 0%
if(ObjectFind("0percentLine")==-1)
{
ObjectCreate("0percentLine", OBJ_TREND, 0, Time[5], daysOpen, Time[0], daysOpen);
ObjectCreate("0percentLineText", OBJ_TEXT,0,Time[0], daysOpen);
ObjectSet("0percentLine", OBJPROP_COLOR, White );
ObjectSet("0percentLine", OBJPROP_RAY, 0 );
ObjectSet("0percentLine",OBJPROP_WIDTH,2);
ObjectSetText("0percentLineText", "0",8, "Arial", White);
}
else if(ObjectFind("0percentLine")==0)
{
ObjectSet("0percentLine",OBJPROP_PRICE1,daysOpen);
}


// Line of the opening price of the day 35%
if(ObjectFind("35percentLine")==-1)
{

ObjectCreate("35percentLine", OBJ_TREND, 0, Time[5], daysOpen-(0.35*(daysOpen-(daysOpen-ATR100))), Time[0], daysOpen-(0.35*(daysOpen-(daysOpen-ATR100))));
ObjectCreate("35percentLineText", OBJ_TEXT,0,Time[0], daysOpen-(0.35*(daysOpen-(daysOpen-ATR100))) );
ObjectSet("35percentLine", OBJPROP_COLOR, White );
ObjectSet("35percentLine", OBJPROP_RAY, 0 );
ObjectSet("35percentLine",OBJPROP_WIDTH,2);
ObjectSetText("35percentLineText", "35",8, "Arial", White);
}
else if(ObjectFind("35percentLine")==0)
{
ObjectSet("35percentLine",OBJPROP_PRICE1,daysOpen-(0.35*(daysOpen-(daysOpen-ATR100))));
}


// Line of the opening price of the day 50%
if(ObjectFind("50percentLine")==-1)
{

ObjectCreate("50percentLine", OBJ_TREND, 0, Time[5], daysOpen-(0.5*(daysOpen-(daysOpen-ATR100))), Time[0], daysOpen-(0.5*(daysOpen-(daysOpen-ATR100))));
ObjectCreate("50percentLineText", OBJ_TEXT,0,Time[0], daysOpen-(0.5*(daysOpen-(daysOpen-ATR100))) );
ObjectSet("50percentLine", OBJPROP_COLOR, White );
ObjectSet("50percentLine", OBJPROP_RAY, 0 );
ObjectSet("50percentLine",OBJPROP_WIDTH,2);
ObjectSetText("50percentLineText", "50",8, "Arial", White);
}
else if(ObjectFind("50percentLine")==0)
{
ObjectSet("50percentLine",OBJPROP_PRICE1,daysOpen-(0.5*(daysOpen-(daysOpen-ATR100))));
}

// Line of the opening price of the day 50%
if(ObjectFind("65percentLine")==-1)
{

ObjectCreate("65percentLine", OBJ_TREND, 0, Time[5], daysOpen-(0.65*(daysOpen-(daysOpen-ATR100))), Time[0], daysOpen-(0.65*(daysOpen-(daysOpen-ATR100))));
ObjectCreate("65percentLineText", OBJ_TEXT,0,Time[0], daysOpen-(0.65*(daysOpen-(daysOpen-ATR100))) );
ObjectSet("65percentLine", OBJPROP_COLOR, White );
ObjectSet("65percentLine", OBJPROP_RAY, 0 );
ObjectSet("65percentLine",OBJPROP_WIDTH,2);
ObjectSetText("65percentLineText", "65",8, "Arial", White);
}
else if(ObjectFind("65percentLine")==0)
{
ObjectSet("65percentLine",OBJPROP_PRICE1, daysOpen-(0.65*(daysOpen-(daysOpen-ATR100))) );
}




// 100% down
if(ObjectFind("100percentLine")==-1)
{
ObjectCreate("100percentLine", OBJ_TREND, 0, Time[5], daysOpen-ATR100, Time[0], daysOpen-ATR100);
ObjectCreate("100percentLineText", OBJ_TEXT,0,Time[0], daysOpen-ATR100);
ObjectSet("100percentLine", OBJPROP_COLOR, White );
ObjectSet("100percentLine", OBJPROP_RAY, 0 );
ObjectSet("100percentLine",OBJPROP_WIDTH,2);
ObjectSetText("100percentLineText", "100",8, "Arial", White);
}
else if(ObjectFind("100percentLine")==0)
{
ObjectSet("100percentLine",OBJPROP_PRICE1,daysOpen-ATR100);
}


return(0);
}

__________________

thanks

James

Files:
 

try this:

int start(){

ObjectsDeleteAll();

Reason: