how to put codes for oscillators

 
I have a specific question. When I set Stochastic in my EA, it works of course when the lines are crossed, but the problem is, I don't know how to make it buy only when it is oversold ( 20 ) and sell when it is overbought ( 80 ). Vladimir please help me - where and how I need to set the data for this function ... I would be grateful to you !!!
 
financion.comission:
My question is - look, when I set Stochastic in EA and set its parameters, it of course triggers when lines are crossed, but the problem is, I don't know how to make it buy only at oversold area ( 20 ) and sell at overbought area ( 80 ) . Vladimir please help me - where and how I need to set the data for this function ... I would be grateful to you!!!

Example code: RSI intrazone trading Simple.

RSI intrazone trading Simple
RSI intrazone trading Simple
  • www.mql5.com
Торговля только внутри зон индикатора iRSI (Relative Strength Index, RSI)
 
If the rsi of the current/previous bar is greater than 80, sell. Similarly buy
 
Vladimir Karputov:

Example code: RSI intrazone trading Simple.

Please tell me if these parameters can be set in the EA "" generate ""

thank you in advance ...!

 
financion.comission:

Tell me if these parameters can be set in the EA "" generate "" or should I write them as codes in the EA "" pattern ""

Thank you in advance ...!

This is a ready-made Expert Advisor. There is no "generate" or "template".

The block that is responsible for generating a trading signal is theSearchTradingSignals function.

Here we get indicator data from the last three bars and compare what zone the indicator is in.

//+------------------------------------------------------------------+
//| Search trading signals                                           |
//+------------------------------------------------------------------+
bool SearchTradingSignals(void)
  {
   if(m_prev_bars==m_last_deal_in) // on one bar - only one deal
      return(true);
   double rsi[];
   ArraySetAsSeries(rsi,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iRSI,0,start_pos,count,rsi))
      return(false);
   int size_need_position=ArraySize(SPosition);
//--- BUY Signal
   if(rsi[m_bar_current]>Inp_RSI_Level_Up)
     {
      if(!InpReverse)
        {
         ArrayResize(SPosition,size_need_position+1);
         SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
         if(InpPrintLog)
            Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
         return(true);
        }
      else
        {
         ArrayResize(SPosition,size_need_position+1);
         SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
         if(InpPrintLog)
            Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
         return(true);
        }
     }
//--- SELL Signal
   if(rsi[m_bar_current]<Inp_RSI_Level_Down)
     {
      if(!InpReverse)
        {
         ArrayResize(SPosition,size_need_position+1);
         SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
         if(InpPrintLog)
            Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
         return(true);
        }
      else
        {
         ArrayResize(SPosition,size_need_position+1);
         SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
         if(InpPrintLog)
            Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
         return(true);
        }
     }
//---
   return(true);
  }
 
financion.comission:
I have a specific question - look, when I set the Stochastic in my EA and set its parameters, it of course triggers when the lines are crossed, but the problem is, I don't know how to make it buy only in oversold area ( 20 ) and sell in overbought area ( 80) ... Vladimir please help me - where and how I need to set the data for this function ... I would be grateful to you!!!

Here is an Expert Advisor from the terminal - which you can experiment with.

you can change the indicator here

//+------------------------------------------------------------------+
//| Initialization of the indicators                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::InitIndicators(void)
  {
//--- create MACD indicator
   if(m_handle_macd==INVALID_HANDLE)
      if((m_handle_macd=iStochastic(NULL,0,5,3,3,MODE_SMA,STO_LOWHIGH))==INVALID_HANDLE)
        {
         printf("Error creating MACD indicator");
         return(false);
        }
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+

here you can do this with the stochastic

//--- check for long position (BUY) possibility
   if(m_macd_current<20)
      if(m_macd_current>m_signal_current && m_macd_previous<m_signal_previous)
         if(MathAbs(m_macd_current)>(m_macd_open_level))
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//--- check for short position (SELL) possibility
   if(m_macd_current>80)
      if(m_macd_current<m_signal_current && m_macd_previous>m_signal_previous)
         if(m_macd_current>(m_macd_open_level))

and here you can try it in the tester

Files:
0001.mq5  23 kb
 

Gentlemen, thanks for answering I really appreciate it ... but unfortunately nothing works ... Why do you think so? I'll send you the codes from mine as well - you tell me what needs to be corrected to get the right range ...

***

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2021.04.21
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
SanAlex:

Here is an Expert Advisor from the terminal - which you can experiment with.

you can change the indicator here

here you can do this with the stochastic

and here you can try it in the tester

Gentlemen, thanks for answering I really appreciate it... but unfortunately nothing works ... Why do you think so? I'll send you the codes from mine as well - tell me what you need to tweak to get the right range

***

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2021.04.21
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
financion.comission:

Gentlemen, thanks for answering I really appreciate it ... but unfortunately nothing works ... Why do you think so? I'll send you the codes from mine as well - you tell me what needs to be corrected to get the right range ...

***

Please use button Code to insert your code (press the button and then insert your code in the window that appears) or use button Attach file to attach the code.

 
Vladimir Karputov:

Please insert code using button (pressed button, inserted code in appeared window) or attach code using button.

Thank you for your feedback ... I did it as you said and got 54 errors and 8 warnings from your codes ... that's too bad ... what shall we do ? ?

I will send you my codes ... maybe you can adjust the range ...

***

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2021.04.21
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
we just need to adjust the range !!!
Reason: