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

 
How to do a proper martingale?
I understand correctly:
Before opening each trade, you need to check all trades on this symbol with this magician and if the last trade on the date with a loss, respectively increase the lot?
 
Roman Sharanov:
What is the correct way to do a martingale?
I understand correctly:
Before opening each trade, you need to check all trades on this symbol with this magician and if the last trade by date is at a loss, respectively increase the lot?

It's like this

 
Sergey Gritsay:

It's like this

just don't understand how to calculate the most recent transaction out of all of them

 
Folks, has anyone come across, need to get indicator data based on another indicator, e.g. RSI superimposed on RSI.
 
Roman Sharanov:

I just don't understand how to calculate the most recent transaction out of all of them

It goes something like this.

double  ProfitLastDeals()
  {
   double m_profit=0;
   int total=OrdersTotal();

   for(int i=0; i<total; i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS))continue;
      if(OrderMagicNumber()!=m_magic)continue;
      if(OrderSymbol()!=m_symbol)continue;
      if(OrderType()==m_type)
        {
         m_profit=OrderProfit();
        }
     }
   return(m_profit);
  }
 
Sergey Gritsay:
Folks, has anyone come across, I need to get indicator data based on another indicator, e.g. RSI superimposed on RSI.

All sorted out, the question is no longer relevant

 
Roman Sharanov:

I just don't understand how to calculate the most recent one out of all the trades

Sorry, the last example selects among open, among closed it should be like this

double  ProfitLastDealsHistory()
  {
   double m_profit=0;
   int total=OrdersHistoryTotal();

   for(int i=0; i<total; i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
      if(OrderMagicNumber()!=m_magic)continue;
      if(OrderSymbol()!=m_symbol)continue;
      if(OrderType()==m_type)
        {
         m_profit=OrderProfit();
        }
     }
   return(m_profit);
  }
 

Strange behaviourof iBarShift(). Returns index (-1) withexact =false flag explicitly checked.

Error occurs randomly at any time, there is no way to catch it manually.

On getting a negative index the code writes in the console the parameters of the executed request and the result

2019.01.04 10:40:24.047 CCC (GBPUSD,M1) Neg index: NZDUSD TimeCurrent: 2019.01.04 09:40:23 Request: 2019.01.04 09:40:23 TimeLastTick: 2019.01.04 09:40:23.44
2019.01.04 10:40:24.047 CCC (GBPUSD,M1) LastError: 0

Request - the time when the bar index is requested

TimeLastTick is the time of the last tick for the requested symbol;MqlTick[] is taken right after the error.

What could be the reasons for such behavior, maybe someone has encountered it?

 
SemenTalonov:

Strange behaviourof iBarShift(). Returns index (-1) withexact =false flag explicitly checked.

Error occurs randomly at any time, there is no way to catch it manually.

On getting a negative index the code writes in the console the parameters of the executed request and the result

Request - the time when the bar index is requested

TimeLastTick is the time of the last tick for the requested symbol;MqlTick[] is taken right after the error.

What may be the reasons for such behavior, maybe someone has encountered?

What does the documentation say about exact == false ?
 
Artyom Trishkin:
What does it say in the documentation about exact == false ?

Returned value if no bar was found at the specified time. Ifexact=false iBarShift returns index of the nearest bar with open time less than specified (time_open<time). If such a bar is not found (no history before the specified time), the function will return -1.

But we have history, it is a fact. Everything happens at the newest (0-th by time series) bar.