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

 
Alexey G. Smolyakov:
The full path of the folder MQL4\Indicators\Used. It seems that there is no way out of the folder. But this is an anomaly - other Expert Advisors work with their indicators in similar folders without any problems. But what is the problem with this indicator - I do not understand it. I looked through its code but I did not have enough knowledge and experience to understand it. I have a suspicion that it only counts the last bar or something like that.

then everything is OK

press Ctrl+D in the terminal - data window opens, throw the indicator on the chart and you will see indicator buffers and their values on each bar in the data window, you get the same figures via iCustom()

there are indicators that have EMPTY_VALUE on some bars - you will see an empty cell in the data window (it is not guaranteed that the indicator author has not set 0.0 instead of EMPTY_VALUE - you need to check it)

Then when iCustom() is called, the obtained value must be compared with EMPTY_VALUE . Search in the kodobase or in the ZigZag EA or in the ZigZag upload to a file - there you will find a ready example of how to work with empty EMPTY_VALUE indicator values

 
Igor Makanu:

then everything is OK

press Ctrl+D in the terminal - data window opens, throw the indicator on the chart and you will see in the data window indicator buffers and their values on each bar, you get the same figures via iCustom()

there are indicators that have EMPTY_VALUE on some bars - you will see an empty cell in the data window (it is not guaranteed that the indicator author has not set 0.0 instead of EMPTY_VALUE - you need to check it)

Then when iCustom() is called, the obtained value must be compared with EMPTY_VALUE . Search in kodobase or in the Expert Advisor on ZigZag or in the ZigZag upload to a file - there you will see a ready example of how to work with empty values of the EMPTY_VALUE indicator

Thank you, checking the values for EMPTY_VALUE has helped.
 
Good afternoon. How to make a function that shows what is set in the settings (Only Long / Only Short / Long & Short). Tried this, but it doesn't work
string LSset()
{
string LS;
if (SymbolInfoInteger(Symbol(),SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_LONGONLY) LS="ONLY LONG";
if (SymbolInfoInteger(Symbol(),SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_SHORTONLY) LS="ONLY SHORT";
if (SymbolInfoInteger(Symbol(),SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_SHORTONLY && 
   SymbolInfoInteger(Symbol(),SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_LONGONLY) LS="LONG & SHORT";
return(LS);
}
Files:
 
Lomonosov1991:
Good afternoon. How to make a function that shows what is set in settings (Only Long / Only Short / Long & Short). Tried this, but it doesn't work

It shouldn't work that way. It is possible to write such a function, but difficult for a beginner.

 
fxsaber:

It shouldn't work that way. It is possible to write such a function, but difficult for a beginner.

search rules, a few years ago the developers promised to make access from an expert to these settings, but they never did

solutionhttps://www.mql5.com/ru/forum/121619#comment_3208150

dll solution, don't know why you need ithttps://www.mql5.com/ru/forum/231434/page2#comment_6773340

ZS: haven't checked, but search the threads, it seems the problem of not saving these settings when applying the chart template remains

LongOnly, ShortOnly or Long&Short?
LongOnly, ShortOnly or Long&Short?
  • 2009.11.03
  • www.mql5.com
Не подсажет ли кто нибудь как внутри советника оределить в каком режиме он запущен LongOnly, ShortOnly or Long&Short? Заранее спасибо...
 
extern int punkt=100;
extern int Ordersss=3;
extern double xxx=1.2;

int PunktsX()
{
   int P=punkt;                             
   int i;
   for(i=Ordersss; i<NumberOfPositions(); i++)
   P*=xxx;
   return(P);
}

I made a function on the averaging advisor. if more than 3 orders are open, each subsequent order will be opened further.

I cannot correct the warning(possible loss of data due to type conversion)

Please advise what to do)

 
Lomonosov1991:

I made a function on the averaging advisor. if more than 3 orders are open, each subsequent order will be opened further.

I cannot correct the warning(possible loss of data due to type conversion)

Please advise what to do)

P=(int)(P*xxx);

For a more accurate calculation it would probably be better to

extern int punkt=100;
extern int Ordersss=3;
extern double xxx=1.2;

int PunktsX()
{
   double P=punkt;                             
   int i;
   for(i=Ordersss; i<NumberOfPositions(); i++)
   P*=xxx;
   return (int) P;
}
 
Konstantin Nikitin:

For a more accurate calculation it's probably better to do this

Thank you) I didn't know you could do that with return)

 
Igor Makanu:

search rules, a few years ago the developers promised to make these settings accessible from an expert, but they never did

solutionhttps://www.mql5.com/ru/forum/121619#comment_3208150

dll solution, don't know why it's neededhttps://www.mql5.com/ru/forum/231434/page2#comment_6773340

ZS: haven't checked, but by searching the threads, it seems the problem of not saving these settings when applying the chart template remains

Thanks, I'll give it a try)

 
Lomonosov1991:

I will try it)

Forum on trading, automated trading systems & strategy testing

Libraries: Expert

fxsaber, 2019.06.04 16:40

// MT4-советник показывает, в каком режиме Long/Short был запущен.

#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

int GetLongShortFlag( const int Chart_ID = 0 )
{
  MqlParam Params[];
  string Names[];
  
  const int Res = EXPERT::Parameters(Chart_ID, Params, Names);
  
  return(((Res & 3) << 1) + (Res & 1));
}

string LongShortToString( const int Chart_ID = 0 )
{
  const int Flag = GetLongShortFlag(Chart_ID);
  string Str = NULL;
  
  if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY) && (bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Long & Short";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY))
    Str = "Only Long";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Only Short";
    
  return(Str);
}

int OnInit()
{
  Alert(LongShortToString());
  
  return(INIT_FAILED);
}