Support Resistance Fixed lines, stay on chart

 

Hello Guys, I'm new to coding, and I have this question; I'm trying to create support resistance expert; it draws 2 lines on 5minTF if the conditions are met; however, the lines keep moving ( I want the lines fixed, and if there is another signal, I want to draw extra line , and so on). How can I keep the lines fixed on chart, so that I can have multiple lines for every time the conditions are met! much appreciated for any help <3


int OnInit()

  {

   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

   
  }

void OnTick()
  {
  
  //candle 5
  double high5 = iHigh(_Symbol,PERIOD_M5,5);
  double low5 = iLow(_Symbol,PERIOD_M5,5);
  datetime time5 = iTime(_Symbol,PERIOD_M5,5);
  
  //candle 4
  double high4 = iHigh(_Symbol,PERIOD_M5,4);
  double low4 = iLow(_Symbol,PERIOD_M5,4);
  datetime time4 = iTime(_Symbol,PERIOD_M5,4);
  
  //candle 3
  double high3 = iHigh(_Symbol,PERIOD_M5,3);
  double low3 = iLow(_Symbol,PERIOD_M5,3);
  datetime time3 = iTime(_Symbol,PERIOD_M5,3);
  
  //candle 2
  double high2 = iHigh(_Symbol,PERIOD_M5,2);
  double low2 = iLow(_Symbol,PERIOD_M5,2);
  datetime time2 = iTime(_Symbol,PERIOD_M5,2);
  
  //candle 1
  double high1 = iHigh(_Symbol,PERIOD_M5,1);
  double low1 = iLow(_Symbol,PERIOD_M5,1);
  datetime time1 = iTime(_Symbol,PERIOD_M5,1);
  datetime time11 = time1 + PeriodSeconds(PERIOD_M5) * 10;
  
  string x1 ="resistance";
  string x2 ="support";


  
  //sell
  if(high3>high4 && high3>high5 && high3>high2 && high3>high1) {
  ObjectCreate(0,x1,OBJ_TREND,0,time3,high3,time11,high3);
  
  }
  
  //buy
  if(low3<low4 && low3<low5 && low3<low2 && low3<low1){
  ObjectCreate(0,x2,OBJ_TREND,0,time3,low3,time11,low3);
  }
  
  ObjectSetInteger(0,x1,OBJPROP_COLOR,clrBlue);
  ObjectSetInteger(0,x1,OBJPROP_WIDTH,2);
  ObjectSetInteger(0,x2,OBJPROP_COLOR,clrRed);
  ObjectSetInteger(0,x2,OBJPROP_WIDTH,2);
    
   
  }

 

Please paste code properly. You should know this by now ...

EDIT: And please copy it from the original source code and not from the posted text.

Forum on trading, automated trading systems and testing trading strategies

I want this indicator to draw the first 4h range (H&L) of the day, for the rest of the day. everyday adjust to the new first 4h candle

salitos, 2022.11.03 18:07

Please attach the code properly if you have it, you may have noticed a </> icon on the ribbon toolbar at the top of the comment/post box.
 
Rami Khattab: Hello Guys, I'm new to coding, and I have this question; I'm trying to create support resistance expert; it draws 2 lines on 5minTF if the conditions are met; however, the lines keep moving ( I want the lines fixed, and if there is another signal, I want to draw extra line , and so on). How can I keep the lines fixed on chart, so that I can have multiple lines for every time the conditions are met! much appreciated for any help <3

It keeps shifting because you are continuously updating the existing objects.

If you want extra new lines for new signals, then you have to create new objects and not just update the same ones.

Use unique names for each of those line objects. Don't reuse the names.

Reason: