# Moving rectangle objects to swing points

Hello everyone,

Fairly beginner coder here! I'm working on an EA which involves identifying swing prices and placing stop and profit targets using these points. As a fun visual addition, I am trying to figure out how to create a rectangle around each swing point. Although this may sound simple, I have been struggling to find a way to accomplish this task and have been pondering it for the past few days. If anyone has a code for achieving this or has any comments or ideas, I would be grateful for your help. Thank you!

Marcell Petras:

Hello everyone,

Fairly beginner coder here! I'm working on an EA which involves identifying swing prices and placing stop and profit targets using these points. As a fun visual addition, I am trying to figure out how to create a rectangle around each swing point. Although this may sound simple, I have been struggling to find a way to accomplish this task and have been pondering it for the past few days. If anyone has a code for achieving this or has any comments or ideas, I would be grateful for your help. Thank you!

Hello , are you stuck on the pivots or the rectangle part ?

Lorentzos Roussos #:

Hello , are you stuck on the pivots or the rectangle part ?

Hey! On the rectangle part.I don't know how to position the rectangle exactly to the swing prices.

Marcell Petras #:
Hey! On the rectangle part.I don't know how to position the rectangle exactly to the swing prices.

Try this function , if you mean a rectangle on the chart

```int OnInit()
{
//---
reset_counter();
place_rectangle("TEST_",iHigh(_Symbol,_Period,1),iTime(_Symbol,_Period,1),2,30,clrOrange);
//---
return(INIT_SUCCEEDED);
}

uint rectangles=0;
void reset_counter(){rectangles=0;}
void place_rectangle(string system_tag,
double price,
datetime time,
double x_size_in_bars,
int y_size_in_points,
color rectangle_color,
bool precise_time_is_on=false){
rectangles++;
string name=system_tag+"_R_"+IntegerToString(rectangles);
double top_=price+((double)y_size_in_points)*_Point;
double bottom_=price-((double)y_size_in_points)*_Point;
if(!precise_time_is_on){if(x_size_in_bars<2){x_size_in_bars=2.0;}}
int size_in_secs=(int)(((double)PeriodSeconds())*x_size_in_bars);
datetime previous=(datetime)(time-size_in_secs/2);
datetime next=(datetime)(time+size_in_secs/2);
ObjectCreate(ChartID(),name,OBJ_RECTANGLE,0,previous,top_,next,bottom_);
ObjectSetInteger(ChartID(),name,OBJPROP_BGCOLOR,rectangle_color);
ObjectSetInteger(ChartID(),name,OBJPROP_COLOR,rectangle_color);
ObjectSetInteger(ChartID(),name,OBJPROP_FILL,rectangle_color);
ObjectSetInteger(ChartID(),name,OBJPROP_BACK,true);
ChartRedraw();
}```

Lorentzos Roussos #:

Try this function , if you mean a rectangle on the chart

Hey! Thanks a lot. This is exactly what I was looking for!
Reason: