why this piece of code doesn't draw?

 

Hi

I am writing an indicator that draws lines on a separate window, also should draw arrows to indicator buy/sell on the main price chart.

So I write the following code, but it doesn't draw, any idea why please?


double CrossUp[];
         
GoUp[i] = Low[i] - Range*0.75;

DrawBuyArrow(Time[i],GoUp[i],Red, STYLE_SOLID);



void DrawBuyArrow(datetime x1, double y1, color lineColor, double style)

  {

   string label = "CustomIndicator# " + DoubleToStr(x1, 0);

   ObjectDelete(label);

   ObjectCreate(label, OBJ_ARROW_BUY, 0, x1, y1);

   ObjectSet(label, OBJPROP_COLOR, lineColor);

   ObjectSet(label, OBJPROP_STYLE, style);

   ObjectSet(label, OBJPROP_WIDTH, 1);

  }
 
luckyvictor:

Hi

I am writing an indicator that draws lines on a separate window, also should draw arrows to indicator buy/sell on the main price chart.

So I write the following code, but it doesn't draw, any idea why please?


         GoUp[i] = Low[i] - Range*0.75;

         DrawBuyArrow(Time[i],GoUp[i],Red, STYLE_SOLID);


void DrawBuyArrow(datetime x1, double y1, color lineColor, double style)

  {

   string label = "CustomIndicator# " + DoubleToStr(x1, 0);

   ObjectDelete(label);

   ObjectCreate(label, OBJ_ARROW_BUY, 0, x1, y1);

   ObjectSet(label, OBJPROP_COLOR, lineColor);

   ObjectSet(label, OBJPROP_STYLE, style);

   ObjectSet(label, OBJPROP_WIDTH, 1);

  }

Have you added enough indicator buffers?


#property indicator_separate_window

#property indicator_buffers X?

are they having correct values in log print?

 
Farzin Sadeghi:

Have you added enough indicator buffers?


#property indicator_separate_window

#property indicator_buffers X?

are they having correct values in log print?

Do I need buffer for this?

I actually learn the code from this page.

https://docs.mql4.com/constants/objectconstants/enum_object/obj_arrow_buy

OBJ_ARROW_BUY - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
OBJ_ARROW_BUY - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
The following script creates and moves Buy sign on the chart. Special functions have been developed to create and change graphical object's properties. You can use these functions "as is" in your own applications. //| Create Buy sign                                                  |               time=0,            ...
 
luckyvictor: Do I need buffer for this?
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Your code sets GoUp[], but we don't know what that is (post all relevant code.) If it isn't a buffer, then you have array exceed and the indicator dies.
  3. You can create individual arrows (since you said your learning.) But for real code, you should make your buffer an arrow buffer and the terminal will draw them for you
              SetIndexArrow - Custom Indicators - MQL4 Reference
 
whroeder1:
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Your code sets GoUp[], but we don't know what that is (post all relevant code.) If it isn't a buffer, then you have array exceed and the indicator dies.
  3. You can create individual arrows (since you said your learning.) But for real code, you should make your buffer an arrow buffer and the terminal will draw them for you
              SetIndexArrow - Custom Indicators - MQL4 Reference

Hi Whroeder1

Thanks for giving me feedback.

1. I have changed the format.

2. GoUp is a buffer of type double, it is used in a for loop, the counter 'i' represents the index of the time bar, but I am not using it to draw, just for calculating the price and hence the drawing point.

3. I have done this exercise of using individual arrow. The reason I am using the create object is because I think it is a way to draw on the indicator_chart_window, while I can use SetIndexArrow to draw on indicator_separate_window.

So may I ask whether I can draw on two windows in the same indicator? e.g. on chart windows I draw arrows to show the buy/sell, and at the same time I can draw the indicator on the the separate window.

Many thanks