property strict troubles

 

I have added background zones to my trading system and works fine but, not with property strict


I get 2 errors in code below - k is undeclared identifier and complicit conversion from number to string on second line


Any advice?


for (int k = i; k<Bars-1; k++) if (state[k]!=state[k+1]) break;

            string   name     = UniqueID+":"+Time[k]; 

            datetime lastTime = Time[i];

                  ObjectDelete(name); 

                  ObjectCreate(name,OBJ_RECTANGLE,0,Time[k+1],0,lastTime,WindowPriceMax()*3.0);

                     ObjectSet(name,OBJPROP_BACK,true);

                     if (state[i]==-1)

                           ObjectSet(name,OBJPROP_COLOR,ColorDown);

                    else   ObjectSet(name,OBJPROP_COLOR,ColorUp);

 
Pieter Gerhardus Van Zyl:

I have added background zones to my trading system and works fine but, not with property strict

I get 2 errors in code below - k is undeclared identifier and complicit conversion from number to string on second line

Any advice?

please use code button </> or alt-s to insert code.

you say it works fine without strict, but it doesn't, it certainly isn't doing what you think, you have left out {  } to group your code lines appropriately.

so you get the error because from your 2nd line onwards as k has not been declared, as it was only declared locally for the  for-loop

for (int k = i; k<Bars-1; k++) if (state[k]!=state[k+1]) break;  <<==  This is your entire for loop it does no processing at all

            string   name     = UniqueID+":"+Time[k];                 <<== all the code from here is independant of the for-loop

            datetime lastTime = Time[i];

                  ObjectDelete(name); 

                  ObjectCreate(name,OBJ_RECTANGLE,0,Time[k+1],0,lastTime,WindowPriceMax()*3.0);

                     ObjectSet(name,OBJPROP_BACK,true);

                     if (state[i]==-1)

                           ObjectSet(name,OBJPROP_COLOR,ColorDown);

                    else   ObjectSet(name,OBJPROP_COLOR,ColorUp);
 
Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
 

Hi

Try something like this: here you need to define and declare properly “i", UniqueID and colors before this code.

   for (int k = i; k<Bars-1; k++) {
         if (state[k]!=state[k+1]) break;

            string   name     = (string)UniqueID+":"+TimeToStr(Time[k]); 

            datetime lastTime = Time[i];

                  ObjectDelete(name); 

                  ObjectCreate(name,OBJ_RECTANGLE,0,Time[k+1],0,lastTime,WindowPriceMax()*3.0);

                     ObjectSet(name,OBJPROP_BACK,true);

                     if (state[i]==-1)

                           ObjectSet(name,OBJPROP_COLOR,ColorDown);

                    else   ObjectSet(name,OBJPROP_COLOR,ColorUp);
   }

Have a nice day