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

 
Roman Efimov:
In general, the problem is the following! I want to trawl profit with another EA but this EA does not let me pull stop loss for profit ! Can anybody fix it! The author is not answering!

So put "0" in the input parameters and there will be no trailing stops.

extern int TrailingStop = 0; // Trailing Stop, if 0, no Trailing Stop

 
Vitaly Muzichenko:
How is it possible to remove a specific indicator from all charts with one move? Applying a new template does not work. Maybe a script?

You still need to close the chart to delete the indicator

Why doesn't the template fit? - is Expert Advisor hanging on it? - I checked it. You can save Expert Advisor in a chart template and apply the template in the same Expert Advisor - Expert Advisor will be deleted and then restarted on this template

 
Igor Makanu:

You still need to close the chart to delete the indicator

Why doesn't the template fit? - is Expert Advisor hanging on it? - I checked, you can save Expert Advisor in a chart template and apply the template from the same Expert Advisor - Expert Advisor will be deleted and then it will run again on this template

You can't change the template on different chart layouts, etc.)

 
Vitaly Muzichenko:

On different markup charts and stuff, you can't replace the pattern)

Googled, there is ChartIndicatorDelete()

https://docs.mql4.com/ru/chart_operations/chartindicatordelete

never used it, can't say anything

ChartIndicatorDelete - Операции с графиками - Справочник MQL4
ChartIndicatorDelete - Операции с графиками - Справочник MQL4
  • docs.mql4.com
Удаляет с указанного окна графика индикатор с указанным именем. Отданная команда поступает в очередь сообщений графика и выполняется только после обработки всех предыдущих команд. Возвращает true в случае удачного помещения команды в очередь графика, иначе false. Чтобы получить информацию об ошибке, необходимо вызвать функцию GetLastError...
 
Igor Makanu:

Googled, there's ChartIndicatorDelete()

https://docs.mql4.com/ru/chart_operations/chartindicatordelete

I've never used it, so I can't say anything.

Yes, thanks, Alexey already gave a heads up about it.

Made it this way, everything works except: How can I magically write it so that I have a choice in input parameters which one to delete?

#property version   "1.00"
#property strict
#property show_inputs

enum ind {
 ind_1, // Indicator 1
 ind_2, // Indicator 2
 ind_3, // Indicator 3
 ind_4  // Indicator 4
};

input string ProgName = "Candles Signal";

long list_id[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
 int size=ChartGetIDList(list_id);
  //
  for(int i=size-1;i>=0;i--) {
   long id=list_id[i];
   for(int k=ChartIndicatorsTotal(id,0);k>=0;k--) {
    if(ChartIndicatorName(id,0,k)==ProgName) {
     Print(ChartSymbol(id),"=",ChartIndicatorName(id,0,k));
     ChartIndicatorDelete(id,0,ProgName);
    }
   }
  }
 }
//+------------------------------------------------------------------+
int ChartGetIDList(long &List[]) {
 int i=0;
 long chartID=ChartFirst();
 while(chartID!=-1) {
    i++;
     ArrayResize(List,i);
     List[i-1]=chartID;
   chartID=ChartNext(chartID);
  }
  return(ArraySize(List));
 }
 

There is an indicator which can get values from a senior period, for(i=0;y=0;i<li_0;i++)

How to make a loop for (int i = li_0; i >= 0; i--)

   datetime TimeArray[];
   int    i,shift,y=0;
      int counted = IndicatorCounted();
   if (counted < 0) return (-1);
   if (counted > 0) counted--;
   int li_0 = Bars - counted;
    
   // Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   for(i=0,y=0;i<li_0;i++)
 //  for (int i = li_0; i >= 0; i--) //ДЛЯ ТАКОГО ЦИКЛА КАК СДЕЛАТЬ
     {
     if (Time[i]<TimeArray[y]) y++;
     stro_1=NormalizeDouble(iCustom(NULL, TimeFrame, "slow", 0, y+1), Digits);
     }
 
Vitaly Muzichenko:

Yes, thanks, Alexei has already let me know about it.

Made it this way, everything works except: How do I magically prescribe it so that there is a choice in the input parameters which one to delete?

here's a script to check

#property strict
#property show_inputs
enum Eind {
 ind_1, // Indicator 1
 ind_2, // Indicator 2
 ind_3, // Indicator 3
 ind_4  // Indicator 4
};

input Eind param = ind_1;
//+------------------------------------------------------------------+
void OnStart()
  {
   Alert("Выбран :",param);
  }
//+------------------------------------------------------------------+
 
Igor Makanu:

here's a script to test

I understand that you need to select via switch, and there enter the names

Your code prints an int value, you need to select string


 
Vitaly Muzichenko:

I understand that you need to select via switch, and enter the names there

Your code prints an int value, you need to select string


Wouldn't EnumToString() help you? The only problem may occur if there is a space or some other invalid character in the short indicator name. As a last resort, you can create an array of string variables and take the index of enumeration from there. Or it is not for individual use and it will take more time to explain than to write the code?

 
Alexey Viktorov:

Wouldn't EnumToString() help you? The problem may occur if there is a space or some other invalid character in short indicator name. As a last resort, you can create an array of string variables and take from there the index of enumeration. Or it is not for individual use and it will take more time to explain than to write the code?

I'll try to do it with a switch, but later. There are spaces in the names.

Reason: