Questions from Beginners MQL5 MT5 MetaTrader 5 - page 952

 
vladzeit:

***

1. Request the current price for the current instrument.

***

2.1 If the current price is Point >= 100 pips, we open a position.

***

Do you want to catch a gap?

 
Vladimir Karputov:

Do you want to catch a gap?

Vladimir, to my shame, I'm not sure I understand what a Gapis)

I want to implement a simple algorithm, in which a price change by a number of points will be a condition to enter the market, to buy or to sell... does not matter.

As a result, I want to learn how to get the current price for the symbol, save it in a local or global variable and retrieve it from there on an event, and reset it to zero.

I want to use it mainly for finding entry points into the market.

I just started to learn mql5, mostly due to your examples of Expert Advisors, which you write a lot, thank you).

I am able to put together my own algorithms from your examples, but I'm confused by getting the current price and saving it in a variable.

 
vladzeit:

***

I want to implement a simple algorithm in which a price change by a number of pips would be a condition for entering the market, to buy or sell... doesn't matter.

***

You must understand that if you set a price on the current tick, on the next tick this price can either not change at all or change by a very small number of points.

Therefore, you need to be more specific about what you want to do:

  • for example, get the current price once in N-seconds.
  • get the current price only at new bar forming.
  • ...
  • and only then compare this price with the previous stored value.

 
Vladimir Karputov:

It should be understood that if you memorise a price on the current tick, then on the next tick this price may either not change at all or change by a very small number of points.

Therefore, you need to be more specific about what you want to do:

  • for example, get the current price once in N-seconds.
  • get the current price only at new bar forming.
  • ...
  • and only then compare that price with the previous memorised value.

Hmmm... I didn't think about these features)

  • To get the current price only at the moment when a new bar is born.
This example would be more useful to me.
 
vladzeit:

Mmm... These are features I hadn't thought of)

  • Get the current price only when a new bar is born.
This example will be more useful to me.

I'll try to show an example tonight (late).

 

Good afternoon!
I am trying to speed up the indicator. I am trying to speed up the indicator because I have a time array that should be compared to bar indexes and I see some slowness here. I've already checked, if I have prepared an array with indexes and compared it to bar indexes I get 40K elements in 7 seconds, but if I have a time array it takes 140 seconds. Are there any tricks to speed up the indicator?

   bool FindArr(int Bar)
     {
      int Size=CheckSizeTime;
      for(int i=restBars; i<Size; i++)
        {
         datetime BarTime=iTime(NULL,PERIOD_CURRENT,Bar);
         if(BarTime==ArrCol.BarTimeArray[i])
           {
            restBars++;
            return(true);
           }
        }
      return(false);
     }
if(prev_calculated==0)         
        for(int i=0;i<rates_total;i++)
           {
            if(Arr.FindArr(i))
              {
               ColorSectionBuffer[i]=low[i];
               ColorSectionColors[i]=0;
              }
            else
              {
               ColorSectionBuffer[i]=0;
               ColorSectionColors[i]=EMPTY_VALUE;
              }
           }
 
vladzeit:

Mmm... These are features I hadn't thought of)

  • Get the current price only when a new bar is born.
This example will be more useful to me.
Vladimir Karputov:

I'll try to show an example tonight (late).

Here was making an example for someone to get prices on each tick:

//+------------------------------------------------------------------+
//|                                               Display prices.mq5 |
//|                              Copyright © 2018, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
//---
#include <Trade\SymbolInfo.mqh>  
CSymbolInfo    m_symbol;                     // symbol info object
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return(INIT_FAILED);
   RefreshRates();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(!RefreshRates())
      return;
   Comment("Ask: ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()),"\n",
           "Bid: ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()));
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates(void)
  {
//--- refresh rates
   if(!m_symbol.RefreshRates())
     {
      Print("RefreshRates error");
      return(false);
     }
//--- protection against the return value of "zero"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
      return(false);
//---
   return(true);
  }
//+------------------------------------------------------------------+

The explanations will be tomorrow, I am already sleeping tonight.

Tomorrow there will also be an example of a new bar.

Files:
 
Vladimir Karputov:

Here's an example of getting prices on each tick for someone else:

I'll explain it tomorrow, I'm already in bed tonight.

Tomorrow there will also be an example of a new bar.

Vladimir, thank you.I got acquainted a little bit with functionRefreshRates ofCSymbolInfo class.I've seen it in your reports and read in a primer as well.

The call of this function inOnTick and output of price values inComment are also clear to me from the example. The procedure inOnInit to check the current symbol is also clear to me.

While waiting for the example with the new bar, I will try to put some practice with your example, I haven't used it in practice. I will try it.


 
fxsaber:

Thank you, I've fixed it.

Thanks - now it seems to give out directories only correctly.

However, I realized that subdirectories are separated by one "\", while the MQL standard provides two "\\\" slashes. I.e. the code is needed to generate file paths and because of one slash it is impossible to do it without additional post processing, is there an option to get two slashes at once?

 
Aleksey Vyazmikin:

Thanks - now only the directories seem to be correct.

However, I realized that subdirectories are separated by one "\", while the MQL standard provides two "\\\" slashes. I.e. the code is needed for generation of file paths, but because of one slash it is impossible to do it without additional post processing, is there a possibility to get two slashes at once?

Print("\\");
Reason: