Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 644

 
Got:

Explain where I'm wrong, it doesn't find the tool in Market Watch.

Try also putting "=" in the condition i>=0

for(int i=SymbolsTotal(true)-1; i>=0; i--){
 
borilunad:

Click Charts, at the bottom of Properties and on the top left uncheck the Chart at the top! And in general, use more of it, it will come in handy!

Thank you! it worked.
 

The Debugger doesn't work - what's wrong?

Metatrader bild 646, editor bild 934. Here is the simplest indicator:


I run it on EURUSD, M1, and this is what I get:

1

I.e. everything is as it should be.

And now I make a breakpoint before Alert and run the Debugger:

USDCHF,H1 chart appears. Where is it coming from? OnlyEURUSD, M1 is open.

I am running it and this is what I see:

I.e., the indicator takes data exactly from this USDCHF,H1. What is the problem here?

The second question. The Editor does not place the written script in folder Scripts but in folder MQL4 and places the compiled file there as well. I have to manually drag and drop the source code to Scripts folder, then compile it and the script will appear in Navigator only then. I don't have that bug with indicators, they go to their folders instantly. Is it something I'm doing wrong or is the Editor making a mistake?

Third question. I still have 646 Bild, even though someone on the Forum said about 650th back in May. Has there really been no update since then, or again I have something wrong?

Good luck to whoever answers me.

 
Thanks for the luck! But only answering the third question! I too have a 646 bild until the server upgrades us to a newer one. This happens when I turn it on after a rest. I do it once a week before the session starts. Good luck to you as well!
 

How do I put SendMail and Alert in the indicator so that it doesn't react to old signals when recalculating indicator values, but shows Alert and sends mail only on new ones?

If it goes like this:

//+------------------------------------------------------------------+
//|                                                       simple.mq4 |
//|                                                         evillive |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "evillive"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Aqua

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double Up[];
double Down[];
extern int period = 2;
extern int method = 1;
extern int price = 0;
extern int shift = 4;
extern string _alerts_="alerts section";
input bool alert=false;//show alert
input bool mail=false;//send mail
input bool not=false;//send push notification
//////////////////

      string dir="";
      datetime tim=0;

int OnInit()
  {

   SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(0, 176);
   SetIndexBuffer(0, Up);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(1, 176);
   SetIndexBuffer(1, Down);
   SetIndexLabel(0,"BUY!");
   SetIndexLabel(1,"SELL!");

   return(INIT_SUCCEEDED);
  }

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 i,limit;
   double ma0,ma1,atr;
//---
      if(rates_total<=(period+shift))
      return(0);
//--- counting from 0 to rates_total
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<=rates_total-(period+shift); i++)
        {
         Up[i]=0.0;
         Down[i]=0.0;
        }
     }
//--- starting calculation
   if(prev_calculated>0)
      limit=rates_total-prev_calculated; //period+shift;
   else
      limit=rates_total-(period+shift);

   for(i = 1; i < limit; i++)
  {
      ma0 = iMA(NULL,0,period,0,method,price,i);
      ma1 = iMA(NULL,0,period,0,method,price,i+shift);
      atr = iATR(NULL,0,period,i);
      if(ma0>ma1 && Close[i]<Close[i+shift] && Close[i]>Close[i+period+shift])
        {
            Up[i] = (Close[i]+Open[i])/2;
            dir="up";
            tim=Time[i];
            alerts(dir,tim);
        }
      if(ma0<ma1 && Close[i]>Close[i+shift] && Close[i]<Close[i+period+shift])
        {   
            Down[i] = (Close[i]+Open[i])/2;
            dir="down";
            tim=Time[i];
            alerts(dir,tim);
        }
  }
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void alerts(string d, datetime t)
{
if(!IsTesting() && (TimeLocal()-t)>60)
{
if(alert==true) Alert("New ",d," arrow");
if(mail==true) SendMail("New signal",StringConcatenate("A new ",d, "signal detected by indicator"));
if(not==true) SendNotification(StringConcatenate("A new ",d, "signal detected by indicator"));
}
return;
}

then at any effect on the indicator (setting on the chart, setting, change of TF, jump in place or sharp sound), it re-shows alerts and tries to send the same mail to ALL arrows, from the beginning of the chart to the current one.

Question in addition - the mail in the log is marked as"Mail: 'Test message' has been sent", but not a single letter has fallen into the box (((

 
evillive:

How do I write SendMail and Alert in the indicator, so it would not react to old signals when recalculating the indicator values, but show Alert and send mail only on new ones?

If it goes like this:

then at any influence on the indicator (installation on the chart, setting, change of TF, jump in place or sharp sound), it shows the alerts again and tries to send them by mail to ALL the arrows, from the beginning of the chart to the current one.

Question in addition - the mail in the log is marked as"Mail: 'Test message' has been sent", but not a single letter has fallen into the box (((.


I would have done so

//+------------------------------------------------------------------+
//|                                                       simple.mq4 |
//|                                                         evillive |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "evillive"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Aqua

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double Up[];
double Down[];
extern int period = 2;
extern int method = 1;
extern int price = 0;
extern int shift = 4;
extern string _alerts_="alerts section";
input bool alert=false;//show alert
input bool mail=false;//send mail
input bool not=false;//send push notification
                     //////////////////

char dir=0;
datetime tim=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   SetIndexStyle(0,DRAW_ARROW,EMPTY,3);
   SetIndexArrow(0,176);
   SetIndexBuffer(0,Up);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,3);
   SetIndexArrow(1,176);
   SetIndexBuffer(1,Down);
   SetIndexLabel(0,"BUY!");
   SetIndexLabel(1,"SELL!");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 i,limit;
   double ma0,ma1,atr;
//---
   if(rates_total<=(period+shift))
      return(0);
//--- counting from 0 to rates_total
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<=rates_total-(period+shift); i++)
        {
         Up[i]=0.0;
         Down[i]=0.0;
        }
     }
//--- starting calculation
   if(prev_calculated>0)
      limit=rates_total-prev_calculated-1; //period+shift;
   else
      limit=rates_total-(period+shift)-1;

   for(i=limit; i>=0; i--)
     {
      ma0 = iMA(NULL,0,period,0,method,price,i);
      ma1 = iMA(NULL,0,period,0,method,price,i+shift);
      atr = iATR(NULL,0,period,i);
      if(ma0>ma1 && Close[i]<Close[i+shift] && Close[i]>Close[i+period+shift])
        {
         Up[i]=(Close[i]+Open[i])/2;
        }
      if(ma0<ma1 && Close[i]>Close[i+shift] && Close[i]<Close[i+period+shift])
        {
         Down[i]=(Close[i]+Open[i])/2;
        }
     }
      if(ma0>ma1 && Close[0]<Close[shift] && Close[0]>Close[period+shift])
        {
         if (dir!=1) {
            dir=1;
            alerts("UP",Time[0]);
         }
        }
      if(ma0<ma1 && Close[i]>Close[i+shift] && Close[i]<Close[i+period+shift])
        {
         if (dir!=-1){
            dir=-1;
            alerts("DOWN",Time[0]);
         }
        }

   

   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void alerts(string d,datetime t)
  {
   if(!IsTesting() && (TimeLocal()-t)>60)
     {
      if(alert==true) Alert("New ",d," arrow");
      if(mail==true) SendMail("New signal",StringConcatenate("A new ",d,"signal detected by indicator"));
      if(not==true) SendNotification(StringConcatenate("A new ",d,"signal detected by indicator"));
     }
   return;
  }
//+------------------------------------------------------------------+
 
Vinin:


I would do so

Arethe added lines supposed to be outside the loop or is that a typo?
Okay, I got it, that's how it should be.
 

Hello, does anyone have a template for averaging a position.

That is, if an order is open and it is losing, then opening a second order in the same direction, we put a stop in the middle between these orders and so on, three orders, four...?

 
Top2n:

Hello, does anyone have a template for averaging a position.

That is, if an order is open and it is losing, then opening a second order in the same direction, we put a stop in the middle between these orders and so on, three orders, four...?


Take all open prices and calculate the arithmetic average
 
Top2n:

Hello, does anyone have a template for averaging a position.

That is, if an order is open and it is losing, then opening a second order in the same direction, we put a stop in the middle between these orders and so on, three orders, four...?


Evillive:

take all opening prices and calculate the arithmetic average

Also take into account different lot sizes, swaps and commissions!