[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 133

 
r772ra:

Sorry for the intrusion.

topBuffer[i] behind the loop and drawing, try it this way:

Your option doesn't work, but a BIG THANK YOU for your attention, hard work and understanding of other people's problems.
 
Roll:

THANK YOU SO MUCH!

Your version of the indicator works!

I tried to solve them with the MQL4 tutorial and the examples of indicators, but nothing worked.

If you have the desire, time and inclination to help me figure out why:

1. When you install the indicator line receives a value of 0 (zero) and only with the arrival of the first tick takes the value of the variable top, or should open the parameter window and immediately close it;

2. The parameter top is calculated to the 4th sign, although there is the following line in init()

IndicatorDigits(Digits+1);

and the line

top=WindowPriceMax(win_idx);

I replaced it by

top=NormalizeDouble((WindowPriceMax(win_idx)),Digits+1);

It doesn't help! And the numerical values of the indicator window scale are 5 digits.

3. With the removal of the indicator Comment is not removed from the chart.



Code

--------

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
double ExtMapBuffer1[],
ExtMapBuffer2[];
//--------------------------------
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
IndicatorShortName("MACD_max-min_v2");

IndicatorDigits(Digits+1);

return(0);
}
//--------------------------------
int deinit()
{

return(0);
}
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted(),limit,win_idx;
double top;

if(counted_bars>0)counted_bars--;
limit=Bars-counted_bars;
win_idx=WindowFind("MACD_max-min_v2");

for(int i=0;i<limit;i++)
{
ExtMapBuffer1[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
ExtMapBuffer2[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);
}

// top=WindowPriceMax(win_idx);
top=NormalizeDouble((WindowPriceMax(win_idx)),Digits+1);
Comment( "\n"," top = ",top);
ObjectDelete("max");

if(ObjectFind("max")!=win_idx)
{
ObjectCreate("max",OBJ_HLINE,win_idx,Time[0],top);
ObjectSet("max",OBJPROP_COLOR,Yellow);
ObjectSet("max",OBJPROP_WIDTH,0);
}

return(0);
}
//+------------------------------------------------------------------+


Files:
 
MK07:

Technical correction - use the SRC button on the top panel to insert code, as your advisers do. It will be much easier to read.

P.S.
to clear the Comment line, insert Comment(") in deinit();
 
granit77:
Technical correction - use the SRC button on the top panel to insert code, as your advisers do. It will be much easier to read.

P.S.
To clear the Comment line, insert Comment(") in deinit();
Thanks for the information.This is my first time on the forums.A special THANK YOU for the code snippet.
 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
double ExtMapBuffer1[],ExtMapBuffer2[];
int init(){SetIndexStyle(0,DRAW_LINE);SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);SetIndexBuffer(1,ExtMapBuffer2);
IndicatorShortName("MACD_max-min");return(0);}
int deinit(){Comment("");return(0);}
//+------------------------------------------------------------------+
int start(){int counted_bars=IndicatorCounted(),limit,win_idx;double top;
if(counted_bars>0)counted_bars--;limit=Bars-counted_bars;win_idx=WindowFind("MACD_max-min");
for(int i=0;i<limit;i++){ExtMapBuffer1[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
  ExtMapBuffer2[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);}
  top=WindowPriceMax(win_idx);ObjectDelete("max");
  if(ObjectFind("max")!=win_idx){ObjectCreate("max",OBJ_HLINE,win_idx,Time[0],top);
  ObjectSet("max",OBJPROP_COLOR,Yellow);ObjectSet("max",OBJPROP_WIDTH,0);}
  Comment( "\n"," top = ",DoubleToStr(top,5));return(0);}
//+------------------------------------------------------------------+
 
https://docs.mql4.com/ru/common/Comment
void Comment(. ...)
The function prints a user defined comment to the upper left corner of the chart. The parameters can be of any type. The number of parameters cannot exceed 64.
Arrays cannot be passed to Comment(). Arrays must be printed element by element.
Data of type double is printed with 4 decimal digits after the point. To output numbers with higher accuracy, use DoubleToStr().
The bool, datetime and color types will be printed as numbers.
To output datetime data as a string, use the TimeToStr() function.

To split the output into multiple lines, you may use line feed character "\n" or "\r\n".
See also Alert() and Print().
 
Can you tell me how to write:
Price has crossed the horizontal line up....
And how should this line be described?
 
Roll:
Thank you for the science.
 

Hello,

Here's the problem I'm having.

Working on PERIOD_H1.

To close at the end of the hour I do this:

   for(j = OrdersTotal()-1; j >= 0; j--){ 
       if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
          if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){
            OpenTime= OrderOpenTime();          
          if(OrderType() == OP_BUY){
            if(TimeCurrent()>Time[0]+3580){ 
             OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),0,Red);}
             }
           else 
          if(OrderType() == OP_SELL){
            if(TimeCurrent()>Time[0]+3580){
             OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),0,Blue);}
             }
           }
         }
To open a position at the beginning of the hour I do the following
   if(TimeCurrent()<Time[0]+3500 && HaveBuy==false && HaveSell==false)
     if(Ask <= EnBuy && IsFreeLevel==true){
          ticket = OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),0,0,forecast-5*MyPoint,"",MagicNumber,0,Blue);
         }
     if(Bid >= EnSel && IsFreeLevel==true){
          ticket = OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),0,0,forecast+5*MyPoint,"",MagicNumber,0,Red);
         }

But for the test it goes like this

I can't figure out where I'm going wrong.

Not all times it works this way, but it has such moments.

Thanks who will answer :).

 
alsu:
I'm not saying that, I'm saying what difference does it make where the EA is attached? If it is written correctly, it makes no difference where it is placed - just place it on a chart of Mongolian exchange, but if it is set to operate on EURUSD 1 minute, it will do so. And it is not hard to program it, just change a couple of lines.

Thank you very much for the clarification!

Only I'm concerned about the tester simulating one-minute bars for modifications at the opening of each one-minute bar.

I'll try changing Open[0] to iOpen(NULL,1,0) and adding a function to check the opening of the one-minute bar.

A few minutes passed, during which I tweaked the code and tried it with the tester at M5 and made sure that in this case the tester does not open 1-minute bars, although prescribed, and modifies it only every 5 minutes, which I was afraid of. In all ticks mode it is a bit better, because it modifies more often. But on M1 only on bar opening it works the same, both with Open[0] and with iOpen(NULL,1,0), for which I'm still grateful!

Now I will always use green iOpen, as I see that I can do without red Open. Green profit is nicer than red loss. (:))