Questions from Beginners MQL4 MT4 MetaTrader 4 - page 226

 

Alexey, thank you for your answers and your help.

New question, is it possible to duplicate chart tabs in MT4? That is, not a template to set the chart parameters each time, but a full copy of the tab with the selected currency, timeframe and chart parameters. Is there such a thing or not?

 
Rustam Bikbulatov:

Trying)

Fighting, searching, finding and re-hiding!


ElenkaVladi:

New question.

Yeah, you're welcome.

The easiest one is the pattern. Why don't you like it? You have set the timeframe, scale, background colour, colour of candlesticks, you have set the required indicators and saved it as default.tpl. Now when you open a new chart, everything is ready for you.

 
Aleksei Stepanenko:


The simplest thing is the template. Why don't you like it? Set the timeframe, scale, background colour, candlestick colour, sketched the necessary indicators and saved it as default.tpl. Now, when you open a new chart, everything is ready for you.

No, the question seems to be different. When a user opens a chart and installs an indicator, he knows neither TF nor symbol. The script should select the symbol and the TF. (And the indicator may be loaded at the same time, or a template may be selected).

 
Aleksei Stepanenko:

Fight, search, find and re-hide!


Yeah, you're welcome.

The simplest thing is the pattern. Why don't you like it? You set the timeframe, scale, background colour, colour of candlesticks, you set the required indicators and save it as default.tpl. Now when you open a new chart, everything is ready for you.

Ah, that's how it works, no thought of default.tpl. :))
 

@makssub in PM asking for MQL4 code, then this code

#property strict
//+------------------------------------------------------------------+
void OnStart()
{
   while(!IsStopped())
   {
      int ticket = -1;
      string ord_sym = "";
      int max_pips = INT_MIN;
      for(int i = OrdersTotal() - 1; i >= 0; i--)
      {
         if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES) || OrderType() > OP_SELL) continue;
         string _sym      = OrderSymbol();
         double sym_point = SymbolInfoDouble(_sym, SYMBOL_POINT);
         double sym_price = OrderType() == OP_BUY ? SymbolInfoDouble(_sym, SYMBOL_BID) : SymbolInfoDouble(_sym, SYMBOL_ASK);
         int ord_pips     = fabs(PriceToInteger(OrderOpenPrice(), sym_point) - PriceToInteger(sym_price, sym_point));
         if(max_pips < ord_pips)
         {
            max_pips = ord_pips;
            ticket = OrderTicket();
            ord_sym = _sym;
         }
      }
      if(ticket < 0) Comment("");
      else Comment("Max pips in order = ", max_pips, " , Symbol = ", ord_sym, " , ticket = ", ticket);
      Sleep(123);
      RefreshRates();
   }
   Comment("");
}
//+------------------------------------------------------------------+
int PriceToInteger( const double Price, const double point )
{
   return((int)(Price / point + 0.1));
}
//+------------------------------------------------------------------+


how to close a ticket order here look for:https://www.mql5.com/ru/forum/131859

Только "Полезные функции от KimIV".
Только "Полезные функции от KimIV".
  • 2011.02.18
  • www.mql5.com
Все функции взяты из этой ветки - http://forum.mql4...
 
Alexey Viktorov:

Well, in simple words, it goes like this:

We create a variable of datetime type and record the time of the current D1 candle in it when we close the order with a profit. And before opening another order, we check the value of this variable with the time of the current D1 candle. Accordingly, if the current time is higher, we can open. Otherwise, we smoke smoke smoke.

Can you show me an example, I just don't have enough experience to implement what you said?
 
Hi all! Please advise a MQL4 tutorial, up to date.
 
Nikolay Grigoryev:
Hi all! Please advise me a MQL4 tutorial relevant to today.

there is only one textbook, the old Kovalev textbook. It was up to 2016 or so. Then a lot of things from 5 were transferred to 4. Thank God the order system was retained. There are no more textbooks (I didn't find any, and others didn't either). Only articles here and internet searches.

 
Valeriy Yastremskiy:

there is only one textbook, the old Kovalev textbook. It was up to 2016 or so. Then a lot of things from 5 were transferred to 4. Thank God the order system was retained. There are no more textbooks (I didn't find any, and others didn't either). Only articles here and a search on the internet.

Thank you!

 

I have written a simple indicator. When crossing zero, it doesn't draw the line, even though the buffers have values. Can you please tell me where I went wrong.

#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed

//---- input parameters
extern int    FastEMA=12;  
extern int    SlowEMA=26;  
extern int    Signal=9;  

//---- buffers
double DiffBuffer_up[];
double DiffBuffer_dn[];
//
double MainBuffer[];
double SignalBuffer[];

ENUM_TIMEFRAMES TimeFrame;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   int    draw_begin=MathMax(FastEMA,SlowEMA);
   string short_name="MACD Stephen";
   //---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,DiffBuffer_up);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,DiffBuffer_dn);
   short_name=StringConcatenate(short_name," ("+(string)FastEMA+","+(string)SlowEMA+","+(string)Signal+")");
   IndicatorShortName(short_name);
   SetIndexDrawBegin(0,draw_begin);
   SetIndexDrawBegin(1,draw_begin);
   SetIndexLabel(0,"Up");
   SetIndexLabel(1,"Down");
   IndicatorDigits(6);
   SetLevelValue(0,0);
   
   TimeFrame=GetTF();
   
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int limit, iChart, iTF, delta=0;
  datetime TimeArray[];
  //if(TimeFrame>Period()) delta=(int)MathCeil(TimeFrame/Period());
  int counted_bars=IndicatorCounted();
  //---- check for possible errors
  if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars+delta;

  ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
  ArraySetAsSeries(MainBuffer,true);
  ArraySetAsSeries(SignalBuffer,true);
  ArrayResize(MainBuffer,  100000);
  ArrayResize(SignalBuffer,100000);
  
  iTF=0;
  for(iChart=0; iChart<limit; iChart++)
  {
      while(Time[iChart]<TimeArray[iTF]) iTF++;
      MainBuffer[iChart]=EMPTY_VALUE;
      SignalBuffer[iChart]=EMPTY_VALUE;
      MainBuffer[iChart]  =iMACD(Symbol(),TimeFrame,FastEMA,SlowEMA,Signal,PRICE_CLOSE,MODE_MAIN,iTF);
      SignalBuffer[iChart]=iMACD(Symbol(),TimeFrame,FastEMA,SlowEMA,Signal,PRICE_CLOSE,MODE_SIGNAL,iTF);
      double diff=MainBuffer[iChart]-SignalBuffer[iChart];
      
      if (diff>0) {
         DiffBuffer_up[iChart]=diff;
         DiffBuffer_dn[iChart]=EMPTY_VALUE;
      }
      else {
         DiffBuffer_dn[iChart]=diff;
         DiffBuffer_up[iChart]=EMPTY_VALUE;
      }
  }
  return(0);
}

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES GetTF() {

   switch (Period()) {
      case PERIOD_M1:  return PERIOD_M5;
      case PERIOD_M5:  return PERIOD_M15;
      case PERIOD_M15: return PERIOD_M30;
      case PERIOD_M30: return PERIOD_H1;
      case PERIOD_H1:  return PERIOD_H4;
      case PERIOD_H4:  return PERIOD_D1;
      case PERIOD_D1:  return PERIOD_W1;
      case PERIOD_W1:  return PERIOD_MN1;
   }
   
   return (ENUM_TIMEFRAMES)Period();

}
//+------------------------------------------------------------------+

Reason: