[Logical & Code Help] Scalping Small CounterTrend with Big Trend

shanmugapradeep

Active Trader
Dec 18, 2020
165
13
34
40
Hello,


In a trending market, I try to take trades during small counter-trend moves. For example, in an uptrend, the market moves down, then goes back up strongly, then pulls back slightly, and then goes up again. During these smaller pullbacks (counter-trend moves), I take buy trades in the direction of the larger trend. The same logic applies in a downtrend for sell trades.

I have created an MQL EA based on this logic. I need your help to verify and validate whether my code is correct. If there are any issues, please suggest how to fix them. Here is my EA code:


Here is basic diagram.




1763733014819.png


1763732959040.png









Code :

MQL4:
double RSI_Value = iRSI(NULL, PERIOD_CURRENT, 14, PRICE_CLOSE, 0);
double BB_Upper_Resistance = iBands(NULL, PERIOD_CURRENT, 20, 2.0, 0, PRICE_CLOSE, MODE_UPPER, 0);
double BB_Lower_Support = iBands(NULL, PERIOD_CURRENT, 20, 2.0, 0, PRICE_CLOSE, MODE_LOWER, 0);
double BB_MiddleBand = iBands(NULL, PERIOD_CURRENT, 20, 2.0, 0, PRICE_CLOSE, MODE_MAIN, 0);
double iMovingAverage = iMA(NULL, PERIOD_CURRENT, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
//double iMovingAverage = iMA(NULL, PERIOD_CURRENT, 50, 0, MODE_EMA, PRICE_CLOSE, 0); - Ignore
bool CandleGreen_S0 = iClose(NULL, PERIOD_CURRENT, 0) > iOpen(NULL, PERIOD_CURRENT, 0);
 
//Buy Trade
if((RSI_Value < 30) &&
Bid < BB_Lower_Support && Bid < BB_MiddleBand &&
Bid > iMovingAverage && (iMovingAverage < BB_Lower_Support || iMovingAverage > BB_Upper_Resistance) &&
CandleGreen_S0)
{
//Buy Order
}
 
//Sell Trade
if((RSI_Value > 70) &&
Bid > BB_Upper_Resistance && Bid > BB_MiddleBand &&
Bid < iMovingAverage && (iMovingAverage < BB_Lower_Support || iMovingAverage > BB_Upper_Resistance) &&
!CandleGreen_S0)
{
//Sell Order
}