Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 739

 
Ilya Prozumentov:

It's up to the author to figure that out. Better bring the code from OnTick()

I contacted the author. I did not help. He himself hardly knows what to do:"Check your conditions here I won't help you".

I may(!) be responsible for my part of the code, but I can't be responsible for yours".

Here is the code OnTick():

void OnTick()
  {RefreshRates();
//---
   string TextDisplay="";

/*  Check News   */
   bool trade=true; string nstxt=""; int NewsPWR=0; datetime nextSigTime=0;
   if(MidleNews || HighNews) 
     {RefreshRates();
      if(SourceNews==0)
        {// Investing
        RefreshRates();
         if(CheckInvestingNews(NewsPWR,nextSigTime)){ trade=false; } // news time
        }
     }
   if(trade)
     {// No News, Trade enabled
      nstxt="No News, Waiting";
      if(ObjectFind(0,"NS_Label")!=-1){ ObjectDelete(0,"NS_Label"); }

        }else{// waiting news , check news power
      color clrT=LowColor;
      if(NewsPWR>3)
        {
         nstxt= "Waiting Non-farm Payrolls News";
         clrT = HighColor;
           }else{
         if(NewsPWR>2)
           {
            nstxt= "Waiting High News";
            clrT = HighColor;
              }else{
            if(NewsPWR>1)
              {
               nstxt= "Waiting Midle News";
               clrT = MidleColor;
                 }else{
               nstxt= "Waiting Low News";
               clrT = LowColor;
              }
           }
        }
      // Make Text Label
      if(nextSigTime>0){ nstxt=nstxt+" "+TimeToString(nextSigTime,TIME_MINUTES); }
      if(ObjectFind(0,"NS_Label")==-1)
        {
         LabelCreate(StringConcatenate(nstxt),clrT);
        }
      if(ObjectGetInteger(0,"NS_Label",OBJPROP_COLOR)!=clrT)
        {
         ObjectDelete(0,"NS_Label");
         LabelCreate(StringConcatenate(nstxt),clrT);
        }
     }
   nstxt="\n"+nstxt;
/*  End Check News  */ 


   if(trade && oppoz)  
     {// No news and Trade Allowed
     Fun_New_Bar();
            
      if(New_Bar)      
     { 
      Alert("Открыть позицию"); ManageTrade(); // Your trade functions
     }
     oppoz=false;
     }

   TextDisplay=TextDisplay+nstxt;
   Comment(TextDisplay);

   return;
  }
 
Alekseu Fedotov:

Try replacing

with this line.

I think it's working! There's been no message for 20 minutes now. Let's see how it reacts to the news at 1pm.

 
Artyom Trishkin:
The number is NaN - Not a Number - Not a Number. Try to normalise the numbers in the Z-count calculation

Thank you, that helped.

Strange thatMathCeil() is not working. NormalizeDouble() number helped - == Z-score equals = -92233720368547.77 . The figure is awesome, but the balance is almost unchanged




 
Alekseu Fedotov:

Try replacing

with this line.

Oh, that's great! Everything worked according to the settings, no failures. Thank you!

I love simple solutions and simple codes.

Thanks also to everyone who paid attention and tried to help a complete amateur.

 

I attach the price marker to the Bid, observe that it works fine, switch to another chart and see that the vertical coordinate immediately shifts by about 15 pixels.

I go back, the marker "escaped" and is not in place until the next tick, then it returns "to the motherland". What can this be caused by?




//+------------------------------------------------------------------+
//|                                              !_clr_indicator.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window


string objname="Bid";
input color Bid_color = clrCrimson;

int OnInit()
  {

int x,y;
double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
int width = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);  //ширина графика

   ObjectCreate(0, objname, OBJ_LABEL,0, 0, 0);
   
   ObjectSetString(0, objname, OBJPROP_TEXT, DoubleToString(Bid, _Digits-1));
   ObjectSetInteger(0, objname, OBJPROP_FONTSIZE, 12);
   ObjectSetInteger(0, objname, OBJPROP_COLOR, Bid_color);
   ObjectSetString(0, objname, OBJPROP_FONT, "Verdana");

   ChartTimePriceToXY(0, 0, TimeCurrent(), Bid, x, y); 
   ObjectSetInteger(0, objname, OBJPROP_XDISTANCE, width-60);

   Print("y=", y, "  ", ObjectGetInteger(0,objname,OBJPROP_TIME,0));

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {


int x2,y2;
double Bid2 = SymbolInfoDouble(Symbol(), SYMBOL_BID);


           ChartTimePriceToXY(0, 0, TimeCurrent(), Bid2, x2, y2); 
      
        ObjectSetInteger(0, objname, OBJPROP_YDISTANCE, y2);

   Print("x2=", x2, "  y2=", y2, "  ", "  Bid=",Bid2);

   return(rates_total);
  }


void OnDeinit(const int reason) 
   { 

      ObjectDelete(0,objname);
   } 
 
 
 
psyman:

I attach the price marker to the Bid, observe that it works fine, switch to another chart and see that the vertical coordinate immediately shifts by about 15 pixels.

I go back, the marker "escaped" and is not in place until the next tick, then it returns "to the motherland". What can this be caused by?

Because the chart is only redrawn on the next tick. But it is dangerous to set forced redrawing of the chart now. The previous two builds of MT5 were not childish brakes. I don't know how it is in MT4, I should check it.

 
Alexey Viktorov:

The situation can be solveddue to the fact that the chart is re-drawn only on the next tick. But the forced re-drawing of the chart is dangerous. The previous two builds of MT5 were rather complicated. I do not know how it is in MT4, I should check it.

So this is a consequence, it is not clear what causes the shift.

The same thing happens horizontally and the most unpleasant thing is that the marker is overlapping the price, I cut out most of the code to understand the situation.

How to get out of this situation?

 
psyman:

This is the consequence, it is not clear what is causing the shift.

The same thing happens horizontally and the most unpleasant thing is that the marker is overlapping the price, I cut out most of the code to understand the situation.

How to get out of this situation?

try updating marker coordinates in the same way and in the CHARTEVENT_CHART_CHANGE event

if(id==CHARTEVENT_MOUSE_MOVE || id==CHARTEVENT_CHART_CHANGE)
 
Ilya Prozumentov:

Try updating the marker coordinates in the same way as the CHARTEVENT_CHART_CHANGE event


Tried it, you have to move the mouse to get the mark back. It's the same crutch, but in a different hand :-)

And switching between charts forCHARTEVENT_CHART_CHANGE is not an event.

Can anyone think of a way to overcome this anomaly?

 
psyman:


Tried it, you have to move the mouse to get the mark back. It's the same crutch, but in a different hand :-)

And switching between charts forCHARTEVENT_CHART_CHANGE is not an event.

Can anyone think of a way to overcome this anomaly?

Do initialization of variables in OnInit (including redrawing of objects)