Would you please help me in mql to print indicators - page 2

 
If you have any questions - ask them tomorrow. I sleep.
 
Sorry, but I can not understand the logic of your indicator. (It should be short sentences and pictures).
 
Karputov Vladimir:
Sorry, but I can not understand the logic of your indicator. (It should be short sentences and pictures).

As you can see, there are two parts:

1.  named //new bar - draw indicator on new bar if xyz - in real time, normal work

2. named //History - draw indicator on the bar [i] when bar [i+1] like xx && bar [i+2] like xyz... where bar[i] is any  bar related to its bars [i+1], [i+2]....


Forget point 1. I just wont to print signal on every candle where second previous candle was down. Not in real time but for all in history of a chart.


if (Close[i]<Open[i]) draw_labe(code_120_down,color_120_down,i); //works OK, prints signals

if (Close[i+1]<Open[i+1]) draw_labe(code_120_down,color_120_down,i);  //doesn't work
 
mareks1 :

As you can see, there are two parts:

1.  named //new bar - draw indicator on new bar if xyz - in real time, normal work

2. named //History - draw indicator on the bar [i] when bar [i+1] like xx && bar [i+2] like xyz... where bar[i] is any  bar related to its bars [i+1], [i+2]....


Forget point 1. I just wont to print signal on every candle where second previous candle was down. Not in real time but for all in history of a chart.


Let us simplify the code:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//new bar
   if(Time[0]==prevtime)
      return(rates_total);
   prevtime=Time[0];

//test
   if(Close[2]<Open[2])
     {
      draw_labe(code_120_down,color_120_down,2);
      Comment("test. Time[2]=",Time[2]);
     }
   return(rates_total);
  }

and

void draw_labe(int code,color col,int f)
  {
   string name=identif+string(Time[f]);

   if(ObjectFind(0,name)==-1)
     {
      ObjectCreate(name,OBJ_ARROW,0,Time[f],Open[f]);
      ObjectSet(name,OBJPROP_ARROWCODE,code);
      ObjectSet(name,OBJPROP_COLOR,col);
      ObjectSet(name,OBJPROP_WIDTH,label_width);
     }
  }

It works. We verify the second bar. And draw on the second bar.

 

It works but not as it should.

1. it draws on bar [i+2] not on the bar [i]. In other words we wont: "Show on bar [i] if bar [i+2] was down".

2. it draws in present time not on the history.

The goal is to click compile on the clear chart and in that moment have a chart full of indicators like this

(the picture does not show our test conditions, it ilustrate the effect of calculations on history made in the moment of compilation)

 
mareks1 :

It works but not as it should.

1. it draws on bar [i+2] not on the bar [i]. In other words we wont: "Show on bar [i] if bar [i+2] was down".

....

You could:

//test
   if(Close[2]<Open[2])
     {
      draw_labe(code_120_down,color_120_down,0);
      Comment("test. Time[2]=",Time[2]);
     }
 

OK, but what about real formulas when we calculate together [i+1] [i+2] [i+3] ?

My oryginal code draw labels on real time (although I am not sure that calculate correct - another problem)

Now the problem is that my code draw on historical but only when condition is if (Close[i]<Open[i])

Does not draw when if (Close[i+2]<Open[i+2])

Does not draw when if (Close[2]<Open[2])

That is the point.

 

Your indicators creates a lot of objects. It is better to go to DRAW_ARROW.

Reason: