identify range and trend market

 

is there any code to identify range and trend market?


i used to identify support resistance for some bar...but not perfect all time


input int x1 =50; // bar count

PHighest1 = Close[iHighest(Symbol(),0,MODE_HIGH,x1,0)];
PLowest1  =  Close[iLowest(Symbol(),0,MODE_LOW,x1,0)];

  
   ObjectCreate("R1",OBJ_HLINE,0,Time[1],PHighest1,Time[x1],PHighest1);
   ObjectSet("R1", OBJPROP_STYLE, 4);
   ObjectSet("R1", OBJPROP_COLOR, Pink);
   ObjectSetInteger(0,"R1",OBJPROP_RAY,false); 
   

  ObjectCreate("S1",OBJ_HLINE,0,Time[1],PLowest1,Time[x1],PLowest1);
   ObjectSet("S1", OBJPROP_STYLE, 4);
   ObjectSet("S1", OBJPROP_COLOR, Green);
   ObjectSetInteger(0,"S1",OBJPROP_RAY,false);