- Problem on the Stochastic indicator
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- how to code a ea with ma on stochastic indicator
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.
- www.mql5.com
Please tell me if these parameters can be set in the EA "" generate ""
thank you in advance ...!
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); }
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
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 ...
***
- 2021.04.21
- www.mql5.com
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
***
- 2021.04.21
- www.mql5.com
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 to insert your code (press the button and then insert your code in the window that appears) or use button to attach the code.
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 ...
***
- 2021.04.21
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use