Domande dai principianti MQL5 MT5 MetaTrader 5 - pagina 1344

 
Igor Makanu #:

nessun modo

Se lo chiamate programmaticamente, potete generare un parametro in modo casuale

e dovete eseguirlo manualmente, dovrete comunque cambiare il parametro di input


prova a vedere cosa c'è ora nelle macro predefinite, era __COUNT___ e ora c'è qualcosa con random, non ho controllato come funziona __COUNT___- risulta statico, ha poco effetto, forse puoi usare random per il tuo compito

Ho trovato __RANDOM__, ma ho bisogno di compilare il codice per cambiare il valore. O forse mi manca qualcosa?

#define  MACRO __RANDOM__ 
input ulong MASlow = MACRO; // Период медленной МА

Può essere cambiato a runtime in qualche modo?

__RANDOM__
 
Компилятор для каждого объявления __RANDOM__ подставляет в код случайное ulong-число.
 
 
non è un nuovo numero per ogni chiamata?
 
Fast235 #:
non c'è un nuovo numero per ogni chiamata?

No

 
Fast235 #:
non è un nuovo numero per ogni chiamata?
Compilatore, quindi al momento della compilazione.
 
Vitaly Muzichenko #:

No

Allora non è un problema risolvibile.

Qual è il problema? - Dovete cercare di formularlo in modo diverso.

 
Vitaly Muzichenko #:

No

Vitaly, a cosa serve tutto questo? È necessario avere > 1 finestra indicatore per ottenere un numero di finestra e metterci qualcosa dentro?
 
Alexey Viktorov #:
Vitaliy, perché? È necessario avere > 1 finestra indicatore per ottenere un numero di finestra e metterci qualcosa dentro?

Sì, proprio così.

Dovete ottenere il numero della finestra in cui si trova l'indicatore. Per fare questo, cliccate sul pulsante e ottenete i dati

  if(id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,(string)wndNum+"_butt")!=-1) {
    Alert("Window number:"+(string)wndNum," => Program name:"+prog_name," => Short name:"+short_name);
    ObjectSetInteger(0,sparam,OBJPROP_STATE,false);
  }

mt4 funziona


mt5 funziona solo in uno - il primo installato, le copie sono ignorate


 

Siamo arrivati a questo, non c'è modo di risolvere il problema della settimana :(

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
//#property indicator_width1  1

input ulong MASlow = __COUNTER__; // Период медленной МА

//+------------------------------------------------------------------+
int wndNum;
string prog_name,short_name;
double Label1Buffer[];
bool flag=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
  prog_name=MQLInfoString(MQL_PROGRAM_NAME);

  int q=0;
  for(int k=1; k<ChartGetInteger(0,CHART_WINDOWS_TOTAL); k++) {
    for(int e=0; e<ChartGetInteger(0,CHART_WINDOWS_TOTAL); e++) {
      if(ChartIndicatorName(0,k,e)==prog_name) {
        q++;
      }
    }
  }

  short_name="Set ("+(string)MASlow+")";
  IndicatorSetString(INDICATOR_SHORTNAME,short_name);
  wndNum=ChartWindowFind();
  
  wndNum=q;
  
  ButtonCreate(0,(string)wndNum+"_butt",44,18,40,14,CORNER_RIGHT_LOWER,"= "+(string)wndNum+" =","Alert","Arial",9,clrBlack,C'236,233,216',clrGray,false,false,false);
  
  SetIndexBuffer(0,Label1Buffer);
  PlotIndexSetInteger(0,PLOT_LINE_WIDTH,q+1);

  flag=true;

  Print("INIT SUCCEEDED: "+(string)wndNum," => Count: ",q);
//---
  return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  ObjectsDeleteAll(0,(string)wndNum+"_butt");
  ChartRedraw();
}

//+------------------------------------------------------------------+
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[])
{
  for(int i = prev_calculated == 0 ? 0 : prev_calculated - 1; i < rates_total; i++) {
    Label1Buffer[i] = close[i];
  }
  if(flag==false) OnInit();
  return(rates_total);
}

//+------------------------------------------------------------------+
//| OnChartEvent function                                            |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
  if(id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam,(string)wndNum+"_butt")!=-1) {
    Alert("Window number:"+(string)wndNum," => Program name:"+prog_name," => Short name:"+short_name);
    ObjectSetInteger(0,sparam,OBJPROP_STATE,false);
  }
  if(id==CHARTEVENT_CHART_CHANGE) {
    ButtonCreate(0,(string)wndNum+"_butt",44,18,40,14,CORNER_RIGHT_LOWER,"= "+(string)wndNum+" =","Alert","Arial",9,clrBlack,C'236,233,216',clrGray,false,false,false);
    OnInit();
  }
}

//===============================================================================================
//--------------------------------------- Создает кнопку ---------------------------------------+
//===============================================================================================
void ButtonCreate(long chart_ID=0,string nm="Button",int xd=0,int yd=0,int width=50,int height=18,int cr=0,
                  string text="Button",string tooltip="Button",string font="Arial",int font_size=9,color clr=clrBlack,
                  color back_clr=C'236,233,216',color border_clr=clrNONE,bool state=false,bool selection=true,bool selectable=true,bool bc=false)
{
  if(ObjectFind(chart_ID,nm)<0) {
    ObjectCreate(chart_ID,nm,OBJ_BUTTON,wndNum,0,0);
    ObjectSetInteger(chart_ID,nm,OBJPROP_XSIZE,width);
    ObjectSetInteger(chart_ID,nm,OBJPROP_YSIZE,height);
    ObjectSetInteger(chart_ID,nm,OBJPROP_CORNER,cr);
    ObjectSetString(chart_ID,nm,OBJPROP_TEXT,text);
    ObjectSetString(chart_ID,nm,OBJPROP_TOOLTIP,tooltip);
    ObjectSetString(chart_ID,nm,OBJPROP_FONT,font);
    ObjectSetInteger(chart_ID,nm,OBJPROP_FONTSIZE,font_size);
    ObjectSetInteger(chart_ID,nm,OBJPROP_COLOR,clr);
    ObjectSetInteger(chart_ID,nm,OBJPROP_BGCOLOR,back_clr);
    ObjectSetInteger(chart_ID,nm,OBJPROP_BORDER_COLOR,border_clr);
    ObjectSetInteger(chart_ID,nm,OBJPROP_BACK,bc);
    ObjectSetInteger(chart_ID,nm,OBJPROP_STATE,state);
    ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,selectable);
    ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,selection);
    ObjectSetInteger(chart_ID,nm,OBJPROP_HIDDEN,false);
    ObjectSetInteger(chart_ID,nm,OBJPROP_YDISTANCE,yd);
    ObjectSetInteger(chart_ID,nm,OBJPROP_ZORDER,10);
    ObjectSetInteger(chart_ID,nm,OBJPROP_XDISTANCE,xd);
    ChartRedraw();
  }
}
//+------------------------------------------------------------------+
 
Vitaly Muzichenko #:

Sì, proprio così.

Dovete ottenere il numero della finestra in cui si trova l'indicatore. Per fare questo, cliccate sul pulsante e ottenete i dati

mt4 funziona


mt5 funziona solo in uno - il primo installato, ignora le copie


Beh, apparentemente questa è una conseguenza dell'aumento della produttività ... Perché ricalcolare l'indicatore 100500 volte per il capriccio di un utente non molto intelligente? Ma si dà il caso che alcune caratteristiche soffrano di protezione.

Probabilmente è necessario inserire un parametro esterno nel nome breve dell'indicatore.

input int MAFast = 8;  // Период быстрой МА
input string shortName = "1";  // Префикс…
string short_name = "";
/********************************************************************\
|           Custom indicator initialization function                 |
\********************************************************************/
int OnInit()
 {
//--- indicator buffers mapping
  short_name = shortName+MQLInfoString(MQL_PROGRAM_NAME) + "=Set (" + (string)MASlow + "/" + (string)MAFast + ")";
  IndicatorSetString(INDICATOR_SHORTNAME, short_name);
  SetIndexBuffer(0, Label1Buffer, INDICATOR_DATA);
  Print("INIT_SUCCEEDED");
  return(INIT_SUCCEEDED);
 }/******************************************************************/

Funziona così. Testato.

 
Alexey Viktorov #:

Beh, apparentemente questa è una conseguenza dell'aumento delle prestazioni... Perché ricalcolare l'indicatore 100500 volte per il capriccio di un utente poco intelligente? Ma si dà il caso che alcune caratteristiche soffrano di protezione.

Probabilmente è necessario inserire un parametro esterno nel nome breve dell'indicatore.

Funziona così. Testato.

Di nuovo, è necessario cambiare il prefisso quando si carica la prossima copia?

Motivazione: