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

 
Artyom Trishkin:

In the tester on a different symbol? Or in demo/real on a different symbol? Or in the tester on this symbol? Or on demo/real on this symbol?

Why do you have to pull everything out of you?

What's your point? What difference does it make where you tried it? The question is whether Point = 0. And if it can, how do I write the code correctly so that I don't encounter an error: division by zero?
 
LuckySith:

Sorry, I'm very nerdy - I don't really understand it.
Maybe you have the simplest indicator with a code of some, I have an analogy to understand? Because I couldn't find one.

I have a very simple code that puts dots in the middle of the bar. How do I make the text appear when I hover over them, or a box, whatever.



#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black
//---- input parameters
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars;
//----  
   for(int i=limit; i>=0; i--)
     {
      double       fabody0 = fabs(Close[i]-Open[i]);
      double       fabody1 = fabs(Close[i+1]-Open[i+1]);
      double       fabody2 = fabs(Close[i+2]-Open[i+2]);
      double       fabody3 = fabs(Close[i+3]-Open[i+3]);
      double       fabody4 = fabs(Close[i+4]-Open[i+4]);
      double       fabody5 = fabs(Close[i+5]-Open[i+5]);
      double       fabody6 = fabs(Close[i+6]-Open[i+6]);
      double       fabody7 = fabs(Close[i+7]-Open[i+7]);
      if((fabody0>fabody1) && (fabody0>fabody2) && (fabody0>fabody3) && (fabody0>fabody4) && (fabody0>fabody5) && (fabody0>fabody6) &&(Volume[i]>Volume[i+1]))
      {  
         if (((Close[i]>Open[i])&&(Low[i]+(High[i]-Low[i])/2>Low[i+1]+(High[i+1]-Low[i+1])*0.9))||((Close[i]<Open[i])&&(Low[i]+(High[i]-Low[i])/2<Low[i+1]+(High[i+1]-Low[i+1])*0.1)))
         ExtMapBuffer1[i]=(iHigh(Symbol(),0,i)+iLow(Symbol(),0,i))/2;
      }
     }
//----
   return(0);
  }
Try
Files:
gmxdk8j.mq4  6 kb
 
Gevorg Hakobyan:
What's your point? What difference does it make where you tried it? The question is whether Point = 0. And if it can, how should I write correct code so that I don't encounter an error: division by zero?
Suit yourself.
So check the divider to zero before dividing.
Thought you were interested in the cause, not the effect, and the appropriate crutch.
 
Artyom Trishkin:
Suit yourself.
So check the divider to zero before dividing.
Thought you were interested in the cause, not the effect, and the appropriate crutch.
I haven't read the whole dialogue, but I suspect a problem with printing the fifth decimal point.
 
Alexey Viktorov:
I haven't read the whole dialogue, but I suspect a problem with printing the fifth decimal place.
No, it divides by Point() and gets a division by zero.
That's why I'm trying to get a coherent answer on how and where it gets the symbol data.

 
Artyom Trishkin:
No, it divides by Point() and gets division by zero.
I'm trying to get a clear answer how and where it takes the data for the symbol.

if(v=="NZD")
{
h=(iClose("NZDUSD",p,b)-iOpen("NZDUSD",p,b))/MarketInfo("NZDUSD",MODE_POINT)+
(iOpen("EURNZD",p,b)-iClose("EURNZD",p,b))/MarketInfo("EURNZD",MODE_POINT)+
(iOpen("GBPNZD",p,b)-iClose("GBPNZD",p,b))/MarketInfo("GBPNZD",MODE_POINT)+
(iOpen("AUDNZD",p,b)-iClose("AUDNZD",p,b))/MarketInfo("AUDNZD",MODE_POINT)+
(iClose("NZDJPY",p,b)-iOpen("NZDJPY",p,b))/MarketInfo("NZDJPY",MODE_POINT)+
(iClose("NZDCAD",p,b)-iOpen("NZDCAD",p,b))/MarketInfo("NZDCAD",MODE_POINT)+
(iClose("NZDCHF",p,b)-iOpen("NZDCHF",p,b))/MarketInfo("NZDCHF",MODE_POINT);
}
 
Alexey Viktorov:
I haven't read the whole dialogue, but I suspect a problem with printing the fifth decimal point.
Could that be the problem?
 
Gevorg Hakobyan:
Could that be the problem?
No. It is only the invisibility of the fifth digit when printing and in the alerts.
 
Alekseu Fedotov:
Try
In general, that's what you need, but the problem is that the description will be quite large, and this method can literally write a couple of words - the rest just does not show up
 

Hello.

Please help.

Now the lot of each following order is increasing in 1, 2, 3, 4, 5...

I want to increase lot not each order, but in steps of 3, so 1, 1, 1, 1, 2, 2, 2, 3, 3, 3...


extern double   LotStop        = 0.01;
extern double   Plus_LotStop   = 0.01;
extern double   Plus_N_ORD  = 3;        //каждые N ордеров
void OnTick()
  {
//---
      for (int i=1; i<=OrdersStop; i++)
   {
         if((Close[1]<Open[1]&&Close[2]>Open[2]&&NumberOfPositions(Symbol(), -1,_Magic)<1))
         {
            OPENORDER (OP_BUYSTOP,PriceBS,LOTs,_Magic,i);
            numB++;
            PriceBS = NormalizeDouble(PriceBS+Step_Stop*Point,Digits);
          
            OPENORDER (OP_SELLSTOP,PriceSS,LOTs,_Magic,i);
            numS++;
            PriceSS = NormalizeDouble(PriceSS-Step_Stop*Point,Digits);
         }
      
      LOTs=LOTs+Plus_LotStop;
      }
  }
Reason: