Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1560

 
Vitaly Muzichenko #:

What do you want to get?

Do you have a code for mt4 to understand what you need?

double rsii1[100], rsii2[100],profit_m[100]; int b,s,b1,s1;
extern int rsi_shift=1;
extern intrsi_period1=4;
extern int rsi_period2=14;
extern int N=5;
extern int Level1=20;

extern int Level2=80;
extern int Level3=30;
extern int Level4=70;
int signal() // 3. Signal Function

{

int b = 0, s = 0, b1 = 0, s1 = 0; // Reset conditions

for (int i = 1; i <= N; i++) // Conditions over the last bars

{

rsii1[i] = iRSI(_Symbol, PERIOD_CURRENT, Inp_RSI_ma_period, PRICE_CLOSE, i);

rsii2[i] = iRSI(_Symbol, PERIOD_CURRENT, Inp_RSI_ma_period, PRICE_CLOSE, i);


if (rsii1[i] < Level1) b = 1;

if (rsii1[i] > Level2) s = 1;

if (rsii2[i] < Level3) b1 = 1;

if (rsii2[i] > Level4) s1 = 1;

}

double rsi1 = iRSI(_Symbol, PERIOD_CURRENT, rsi_period1, PRICE_CLOSE, rsi_shift);

double rsi2 = iRSI(_Symbol, PERIOD_CURRENT, rsi_period1, PRICE_CLOSE, rsi_shift + 1);

double rsi3 = iRSI(_Symbol, PERIOD_CURRENT, rsi_period2, PRICE_CLOSE, rsi_shift);

double rsi4 = iRSI(_Symbol, PERIOD_CURRENT, rsi_period2, PRICE_CLOSE, rsi_shift + 1);


if (rsi1 > rsi3 && rsi2 <= rsi4 && b == 1 && b1 == 1) return (ORDER_TYPE_BUY); //open buy

if (rsi1 < rsi3 && rsi2 >= rsi4 && s == 1 && s1 == 1) return (ORDER_TYPE_SELL); // open Sell


return(0);

}


I am trying to convert it to 5 by inserting a muving handle into the two rsi values.

The cross of RSI and MA above or below the specified levels

i.e. RSI above 70 and MA above 60 at cross from top to bottom opens short, and vice versa RS below and MA below at cross from bottom to top opens long.
I have a couple of dozens of such functions and I am trying to adapt them to 5. Some of them work, some of them don't.


H.Y. how do you hide the code area so that you don't get such sheets? I don't see the spoiler button so that I don't have to throw a thousand and a half lines on 5.0.

 
Mickey Moose #:

double rsii1[100], rsii2[100],profit_m[100]; int b,s,b1,s1;

H.Y. how do you hide the code area so that you don't get such sheets? I can't see the spoiler button so that I don't have to throw a thousand and a half lines on 5k.

double handle_iRSI;
double handle_iMA;
double buff[1];
int OnInit()
{
  handle_iRSI=iRSI(Symbol(),Period(),14,PRICE_CLOSE);
  if(handle_iRSI==INVALID_HANDLE) {
    Print("Не удалось создать хэндл индикатора iRSI для пары %s/%s, код ошибки %d",GetLastError());
    return(INIT_FAILED);
  }
  handle_iMA=iMA(Symbol(),Period(),50,0,MODE_SMA,PRICE_CLOSE);
  if(handle_iMA==INVALID_HANDLE) {
    Print("Не удалось создать хэндл индикатора iMA для пары %s/%s, код ошибки %d",GetLastError());
    return(INIT_FAILED);
  }
  return(INIT_SUCCEEDED);
}
void OnTick()
{

  for(int i = 1; i <= N; i++) {
    CopyBuffer(handle_iRSI,0,i,1,buf);
    double RSI[i] = buf[0];//iRSI(NULL,0,14,PRICE_CLOSE,i);
    CopyBuffer(handle_iMA,0,i,1,buf);
    double MA[i] = buf[0];//iMA(Symbol(),Period(),50,0,MODE_SMA,PRICE_CLOSE,i);
 

Here I have finished something else, in idea it should close when receiving a profit in xxx amount
I want to change the condition to "if we have orders and they are of such type and they are in profit for the amount of OverProfit, then when receiving the opposite signal they close. Otherwise, our grid of orders averages the position by the amount of OverLoss/
. As I understand it is necessary to insert a memorable variable into the function of searching for signals and reset it after closing positions.

What is stressing me here - I have no idea how to work with these structures and take pieces from the database, so I edit by poke.

bool SearchTradingSignals(void)
  {
   double ma[],rsi[];
   ArraySetAsSeries(ma,true);
   ArraySetAsSeries(rsi,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iMA,0,start_pos,count,ma) ||
      !iGetArray(handle_iRSI,0,start_pos,count,rsi))
     {
      return(false);
     }

   int size_need_position=ArraySize(SNeedPosition);
   if(rsi[2]<ma[2] && rsi[1]>ma[1])
     {
      ArrayResize(SNeedPosition,size_need_position+1);
      if(!InpReverse)
         SNeedPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
      else
         SNeedPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
      //---
      return(true);
     }
   if(rsi[2]>ma[2] && rsi[1]<ma[1])
     {
      ArrayResize(SNeedPosition,size_need_position+1);
      if(!InpReverse)
         SNeedPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
      else
         SNeedPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
      //---
      return(true);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| Close over xxx                                          |
//+------------------------------------------------------------------+


void ClosebyProfit()   // Если профит превышает значение вызываем функцию
{ 
  double profit1 = PositionGetDouble(POSITION_PROFIT); 
  for(int i = PositionsTotal() - 1; i >= 0; i--)
  {    
      if(m_position.Symbol()==m_symbol.Name() == Symbol() && PositionGetInteger(POSITION_MAGIC) == InpMagic)
      {
        if((PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && profit1 >= OverProfit))
        {
         pos_TIC=PositionGetInteger(POSITION_TICKET);
            m_Trade.PositionClose(pos_TIC);
          continue;
        }
        else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && profit1 >= OverProfit)
        {
          pos_TIC=PositionGetInteger(POSITION_TICKET);
            m_Trade.PositionClose(pos_TIC);
        }
      }
    }
  }
 
Its asking me "signal subscription failed,enable real time subscription in Signals setting."
how to solve it?please.
 

Hi there, I am new to mql5 but i have learned and created an advisor which gives "BREAK OF STRUCTURE" . It prints "BOS" when there is BOS found, it works fine and shows as object in strategy tester but i am not able to apply in real time chart. Please help.

EX5 removed by moderator.

Files:
Learn.mq5  7 kb
 
Hello, can you tell me where I am missing something? The m15 chart is open, I want to find the opening time of the last candle on m1.

iTime(0, PERIOD_M1, 0) ;

I get 1970.01.01, why is that? The history is loaded, even if I change the shift, put any number or ratestotal there, the result is the same.
 
Vlad Tatarkin #:
iTime(0, PERIOD_M1, 0) ;

Maybe it's better to try this way

iTime(NULL, PERIOD_M1, 0);
 
hlkrt strategy tester but I can't apply it to a real time chart. Please help.

Checked. It is drawing something on the real time chart.


 
Aleksandr Slavskii #:

Maybe it's better to try it this way

PERIOD_CURRENT works fine, as soon as you put another TF, it says 1970.

PS: figured it out.
 
Vlad Tatarkin #:
PERIOD_CURRENT works fine, as soon as you put another TF, it says 1970.
PS: figured it out.

On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
          Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018)
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019)