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 ?
Marcell Petras #:
Hey! On the rectangle part.I don't know how to position the rectangle exactly to the swing prices.
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(); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!