Small problem with re-coloring the pricegraph with TrendLines...

 

Hi,

can anyone of you gurus pls help me out with this problem that has kept me occupied for days ?

//********************* Global Declarations **************************
int Tick;
int id;
int PrevTime;
int DrawIndex = 0;
color Sell = Red;
color Buy = Blue;
color Wait = White;
string Mode = "Sell";
color Gcolor;
color PrevGcolor;
bool Redraw = false;
//********************************************************************

//********************* Executed every Tick **************************
int start()
  {
Tick++;// Increment Tick counter
// THIS THING IS SUPPOSED TO SHOW EA TRADEHISTORY AS COLORS ON THE PRICE GRAPH
// for testing we draw a Vline at bar0, and change mode.
// these two must coincide on the graph, in orher words
// the Red and Blue must meet at the Vline.
// The Vline is in the correct location (time) but for 
// some reason the Mode color is leading by 2 bars...
// Start "Visual Mode" backtest at 2008.12.01
// To make any sense the chary must be "line" and not candles etc.

Mode="Buy";//We start with buy
if (  (TimeToStr(Time[0]) >= "2008.12.01 01:14")  )//this is the transitionpoint
   {
      Mode="Sell";//At this date and time we change to sell
	  	ObjectCreate( "UpLine"+Tick, OBJ_VLINE, 0, Time[0], 0); 
   }   


//--------- Apply Mode color to pricegraph ------------- 
DrawColor (Mode, DrawIndex, Redraw);
//------------------------------------------------------



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






//************ Draw priceline overlay color **************************************************************
int DrawColor(string Mode, int DrawIndex, bool Redraw)
{
id++;//objectindex
   int   i=0;

   if (Mode == "Sell") Gcolor = Sell;
   if (Mode == "Buy")  Gcolor = Buy;
   if (Mode == "Wait") Gcolor = Wait;


   while (i<=500)
   {


      ObjectCreate("ClosedPeriod"+id, OBJ_TREND, 0, Time[i+2], Close[i+2], Time[i+1], Close[i+1]);
      ObjectSet("ClosedPeriod"+id, OBJPROP_RAY, 0);
      ObjectSet("ClosedPeriod"+id, OBJPROP_WIDTH, 2);
      ObjectSet("ClosedPeriod"+id, OBJPROP_COLOR, Gcolor);//current graphcolor 
   
  i++;  
   }
   if (Time[0]!=PrevTime)   //if chart has scrolled...  
   {
   
   }            
     
PrevTime=Time[0];//store current time
return(0);
}
//*********************************************************************************************************













 
DayTrader:

Hi,

can anyone of you gurus pls help me out with this problem that has kept me occupied for days ?













SOLVED !