MT5 EA based on stochastic

MQL5 Esperti

Specifiche

EA Name: Stochastic EA (MT5)

Timeframe
Works only on M1, M5


Indicators & Settings
1. Stochastic Oscillator
%K Period: 14 (editable)
%D Period: 3 (editable)
Slowing: 3 (editable)
Buy Level: 10 (editable via input Buy Level)
Sell Level: 90 (editable via input Sell Level)
2. Simple Moving Average (SMA)
Period: 100 (editable via input SMA Period)
Acts as a hard filter for trades:
Buy trades only if price > SMA100
Sell trades only if price < SMA100


Entry Rules:

BUY

  • Stochastic crosses below Buy Level (default 10) from above
  • Current price above SMA100
  • Max trades not exceeded
  • Grid spacing respected for multiple positions
  • Immediate entry on the current candle; no waiting for candle close.

SELL
  • Stochastic crosses above Sell Level (default 90) from below
  • Current price below SMA100
  • Max trades not exceeded
  • Grid spacing respected for multiple positions
  • Immediate entry on the current candle; no waiting for candle close
Trade Management
  • Maximum positions per direction: 10
  • Grid layering: 2-5 pips apart (editable via Grid Step Pips)
  • Fixed lot (FixedLot) or % of account risk (Risk Percent) selectable
  • Stop Loss: Manual SL in pips (Stop Loss Pips) applied to all trades
  • Take Profit: None (all trades rely on SL or manual close)
  • Manual close safe: EA will not open new trades until stochastic crosses the levels again after a position is closed

Behavior Notes

1. Trades only open when SMA filter AND stochastic condition are met simultaneously.

2. If price moves back into neutral zones (around 50), no new trades are triggered unless stochastic crosses the defined Buy/Sell levels again.

3. EA continuously monitors each tick and respects grid spacing and max trades rules.

4. Fully customizable via inputs - stochastic periods, SMA period, Buy/Sell levels, lot size, risk, stop loss, grid spacing, and max trades.


How it Works (Step-by-Step)

1. Check SMA100

  • Price above SMA100 → Only BUY trades allowed
  • Price below SMA100 → Only SELL trades allowed

2. Check Stochastic

  • BUY: crosses below Buy Level (default 10) → open BUY
  • SELL: crosses above Sell Level (default 90) → open SELL

3. Check Grid

  • New trades only if distance from last open ≥ GridStepPips (2-5 pips)
  • Max 10 positions per direction

4. Apply Stop Loss

  • * SL in pips as set in input

5. Manual Close Safe

  • If trades are manually closed, EA waits for fresh stochastic cross before opening again



//+------------------------------------------------------------------+

//| Stochastic EA - MT5 (No TP, Manual Close Safe)          |

//+------------------------------------------------------------------+

#property strict


#include <Trade/Trade.mqh>

CTrade trade;


//---------------- INPUTS ----------------//

input int      KPeriod      = 14;

input int      DPeriod      = 3;

input int      Slowing      = 3;


input int      SMAPeriod    = 100;


input bool     UseRiskPct   = false;

input double   FixedLot     = 0.10;

input double   RiskPercent  = 1.0;


input int      StopLossPips = 20;


input int      MaxTrades    = 10;

input double   GridStepPips = 2.0;   // 2–5 pips


//---------------- GLOBALS ----------------//

int stochHandle;

int smaHandle;

double lotSize;


bool buyReady = true;

bool sellReady = true;

double lastK = 50.0; // previous stochastic


//+------------------------------------------------------------------+

int OnInit()

{

   if(_Period != PERIOD_M1)

   {

      Alert("This EA works on M1 timeframe only.");

      return INIT_FAILED;

   }


   stochHandle = iStochastic(_Symbol, PERIOD_M1,

                             KPeriod, DPeriod, Slowing,

                             MODE_SMA, STO_LOWHIGH);


   smaHandle = iMA(_Symbol, PERIOD_M1,

                   SMAPeriod, 0, MODE_SMA, PRICE_CLOSE);


   if(stochHandle == INVALID_HANDLE || smaHandle == INVALID_HANDLE)

      return INIT_FAILED;


   lotSize = LotSizeCalc();


   return INIT_SUCCEEDED;

}


//+------------------------------------------------------------------+

double LotSizeCalc()

{

   if(!UseRiskPct)

      return FixedLot;


   double riskMoney = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100.0;

   double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);

   double slPoints  = StopLossPips * _Point * 10;


   double lot = riskMoney / (slPoints / _Point * tickValue);

   return NormalizeDouble(lot, 2);

}


//+------------------------------------------------------------------+

int CountPositions(int type)

{

   int count = 0;

   for(int i=0; i<PositionsTotal(); i++)

   {

      if(PositionSelectByIndex(i))

      {

         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&

            PositionGetInteger(POSITION_TYPE) == type)

            count++;

      }

   }

   return count;

}


//+------------------------------------------------------------------+

double LastOpenPrice(int type)

{

   for(int i=PositionsTotal()-1; i>=0; i--)

   {

      if(PositionSelectByIndex(i))

      {

         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&

            PositionGetInteger(POSITION_TYPE) == type)

            return PositionGetDouble(POSITION_PRICE_OPEN);

      }

   }

   return 0;

}


//+------------------------------------------------------------------+

void OnTick()

{

   double k[2], sma[1];

   if(CopyBuffer(stochHandle, 0, 0, 2, k) <= 0) return;

   if(CopyBuffer(smaHandle, 0, 0, 1, sma) <= 0) return;


   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   double grid = GridStepPips * _Point * 10;


   int buyCount  = CountPositions(POSITION_TYPE_BUY);

   int sellCount = CountPositions(POSITION_TYPE_SELL);


   // ---------------- RESET FLAGS ----------------

   if(buyCount == 0 && k[0] > 10) buyReady = true;  // reset buy after zone crossed

   if(sellCount == 0 && k[0] < 90) sellReady = true; // reset sell after zone crossed


   // ---------------- BUY ENTRY ----------------

   if(buyReady && k[1] > 10 && k[0] <= 10 && bid > sma[0] && buyCount < MaxTrades)

   {

      if(buyCount == 0 || bid < LastOpenPrice(POSITION_TYPE_BUY) - grid)

      {

         double sl = bid - StopLossPips * _Point * 10;

         if(trade.Buy(lotSize, _Symbol, ask, sl, 0))

            buyReady = false; // prevent re-entry until stochastic resets

      }

   }


   // ---------------- SELL ENTRY ----------------

   if(sellReady && k[1] < 90 && k[0] >= 90 && bid < sma[0] && sellCount < MaxTrades)

   {

      if(sellCount == 0 || ask > LastOpenPrice(POSITION_TYPE_SELL) + grid)

      {

         double sl = ask + StopLossPips * _Point * 10;

         if(trade.Sell(lotSize, _Symbol, bid, sl, 0))

            sellReady = false; // prevent re-entry until stochastic resets

      }

   }


   // update previous stochastic

   lastK = k[0];

}
























Con risposta

1
Sviluppatore 1
Valutazioni
(241)
Progetti
303
28%
Arbitraggio
33
24% / 61%
In ritardo
9
3%
Occupato
2
Sviluppatore 2
Valutazioni
(496)
Progetti
963
74%
Arbitraggio
27
19% / 67%
In ritardo
100
10%
Caricato
Pubblicati: 1 articolo, 6 codici
3
Sviluppatore 3
Valutazioni
(438)
Progetti
691
34%
Arbitraggio
34
68% / 9%
In ritardo
22
3%
In elaborazione
4
Sviluppatore 4
Valutazioni
(10)
Progetti
13
23%
Arbitraggio
3
33% / 67%
In ritardo
1
8%
In elaborazione
5
Sviluppatore 5
Valutazioni
(18)
Progetti
22
9%
Arbitraggio
4
50% / 50%
In ritardo
1
5%
Caricato
6
Sviluppatore 6
Valutazioni
(64)
Progetti
83
28%
Arbitraggio
9
33% / 56%
In ritardo
9
11%
Gratuito
Pubblicati: 1 codice
7
Sviluppatore 7
Valutazioni
(373)
Progetti
479
23%
Arbitraggio
57
56% / 25%
In ritardo
55
11%
Occupato
8
Sviluppatore 8
Valutazioni
(323)
Progetti
502
19%
Arbitraggio
33
42% / 30%
In ritardo
33
7%
Caricato
9
Sviluppatore 9
Valutazioni
(33)
Progetti
38
21%
Arbitraggio
5
0% / 60%
In ritardo
0
Gratuito
10
Sviluppatore 10
Valutazioni
(21)
Progetti
30
57%
Arbitraggio
0
In ritardo
1
3%
In elaborazione
11
Sviluppatore 11
Valutazioni
(333)
Progetti
400
53%
Arbitraggio
20
55% / 15%
In ritardo
29
7%
Occupato
12
Sviluppatore 12
Valutazioni
(24)
Progetti
31
19%
Arbitraggio
4
50% / 25%
In ritardo
4
13%
Gratuito
13
Sviluppatore 13
Valutazioni
(3)
Progetti
4
0%
Arbitraggio
1
0% / 0%
In ritardo
0
Gratuito
14
Sviluppatore 14
Valutazioni
(6)
Progetti
5
0%
Arbitraggio
2
50% / 50%
In ritardo
2
40%
Gratuito
15
Sviluppatore 15
Valutazioni
Progetti
0
0%
Arbitraggio
0
In ritardo
0
Gratuito
16
Sviluppatore 16
Valutazioni
(1)
Progetti
2
0%
Arbitraggio
2
0% / 100%
In ritardo
0
In elaborazione
17
Sviluppatore 17
Valutazioni
(14)
Progetti
20
35%
Arbitraggio
6
33% / 50%
In ritardo
0
In elaborazione
18
Sviluppatore 18
Valutazioni
(626)
Progetti
844
48%
Arbitraggio
27
37% / 15%
In ritardo
63
7%
In elaborazione
19
Sviluppatore 19
Valutazioni
(9)
Progetti
13
38%
Arbitraggio
0
In ritardo
3
23%
In elaborazione
20
Sviluppatore 20
Valutazioni
(617)
Progetti
1427
59%
Arbitraggio
31
81% / 0%
In ritardo
10
1%
Gratuito
21
Sviluppatore 21
Valutazioni
(206)
Progetti
333
35%
Arbitraggio
66
12% / 58%
In ritardo
87
26%
Gratuito
22
Sviluppatore 22
Valutazioni
Progetti
0
0%
Arbitraggio
0
In ritardo
0
Gratuito
23
Sviluppatore 23
Valutazioni
(57)
Progetti
84
26%
Arbitraggio
24
13% / 58%
In ritardo
7
8%
In elaborazione
24
Sviluppatore 24
Valutazioni
(27)
Progetti
38
24%
Arbitraggio
14
0% / 93%
In ritardo
4
11%
Gratuito
25
Sviluppatore 25
Valutazioni
(29)
Progetti
36
53%
Arbitraggio
2
50% / 50%
In ritardo
3
8%
Gratuito
26
Sviluppatore 26
Valutazioni
Progetti
0
0%
Arbitraggio
0
In ritardo
0
Gratuito
27
Sviluppatore 27
Valutazioni
(306)
Progetti
550
35%
Arbitraggio
79
32% / 42%
In ritardo
198
36%
Caricato
28
Sviluppatore 28
Valutazioni
(3)
Progetti
3
0%
Arbitraggio
2
0% / 50%
In ritardo
1
33%
Caricato
29
Sviluppatore 29
Valutazioni
(2292)
Progetti
2886
63%
Arbitraggio
122
44% / 25%
In ritardo
428
15%
Caricato
30
Sviluppatore 30
Valutazioni
Progetti
0
0%
Arbitraggio
0
In ritardo
0
Gratuito
Pubblicati: 2 codici
31
Sviluppatore 31
Valutazioni
(19)
Progetti
33
55%
Arbitraggio
5
80% / 20%
In ritardo
3
9%
Gratuito
32
Sviluppatore 32
Valutazioni
(2)
Progetti
3
33%
Arbitraggio
0
In ritardo
0
Gratuito
33
Sviluppatore 33
Valutazioni
(540)
Progetti
622
33%
Arbitraggio
37
38% / 51%
In ritardo
11
2%
Occupato
34
Sviluppatore 34
Valutazioni
(270)
Progetti
552
49%
Arbitraggio
57
40% / 37%
In ritardo
228
41%
In elaborazione
35
Sviluppatore 35
Valutazioni
Progetti
0
0%
Arbitraggio
0
In ritardo
0
Gratuito
36
Sviluppatore 36
Valutazioni
(8)
Progetti
11
9%
Arbitraggio
3
33% / 33%
In ritardo
4
36%
Caricato
37
Sviluppatore 37
Valutazioni
(390)
Progetti
416
30%
Arbitraggio
74
19% / 70%
In ritardo
52
13%
In elaborazione
38
Sviluppatore 38
Valutazioni
(49)
Progetti
63
21%
Arbitraggio
11
27% / 55%
In ritardo
5
8%
Gratuito
39
Sviluppatore 39
Valutazioni
Progetti
0
0%
Arbitraggio
1
0% / 100%
In ritardo
0
Gratuito
40
Sviluppatore 40
Valutazioni
(511)
Progetti
549
53%
Arbitraggio
13
69% / 15%
In ritardo
3
1%
Gratuito
41
Sviluppatore 41
Valutazioni
(2629)
Progetti
3341
67%
Arbitraggio
77
48% / 14%
In ritardo
342
10%
Gratuito
Pubblicati: 1 codice
42
Sviluppatore 42
Valutazioni
(24)
Progetti
25
68%
Arbitraggio
0
In ritardo
1
4%
Caricato
Pubblicati: 5 codici
43
Sviluppatore 43
Valutazioni
(301)
Progetti
307
69%
Arbitraggio
2
100% / 0%
In ritardo
0
Gratuito
Pubblicati: 1 codice
Ordini simili
MT5 DEVS NEEDS 70+ USD
Hi, I'm contacting/hired to inquire about the possibility of creating an expert advisor dashboard scanner for MT5. The scanner already exists, but the current developer can't add sound notifications. I also need additional custom options. I'll leave you the link to the sample scanner. https://www.mql5.com/it/market/product/137093?source=External I need the scanner for "Sweep and close" candles with a custom alert
Project Title: MT5 Algo Trading EA (Single Strategy + License Panel + Ownership + Manual Trade) --- Project Description I am looking for an experienced MT5 (MQL5) developer to create a clean, stable and professional Algo Trading EA for my company and future clients. This is a long-term business project, not a one-time personal EA. --- 1. Strategy Requirements - Only 1 single trading strategy - No martingale - No grid
I have an existing indicator- but may need some source code adjustment to make it into an EA. Attached source file, mql file and set file. All 6 filters need to be on 'TRUE' to check if the EA works correctly
Hi, I have an EA, which places limit orders only by reading the text files in common folder (in a specific format) I need to make some updates in the EA: 1. Limit to Market Entry Adjustment: True/False · By default, when placing a buy limit order, if the current price, is below the limit price mentioned in the file, the order gets triggered as market entry. · By enabling the above option as True, it
write me a fast eurusd and btc scalping robot using ema trend filter m1 and m5 entries lowspread check, less trades, strict risk management fixed tp/sl ssesion filter and tick based exists
need an MT5 Expert Advisor for XAUUSD. The EA logic is based on Asian session range and London continuation. Main rules: 1. Asian session - User-defined start and end time - Calculate Asian High and Low - Calculate Asian range 2. Quality filter - Trade only if Asian range is between minimum and maximum values (inputs) 3. Entry - One trade setup per day - If BUY bias: Place Buy Limit at Asian Low minus buffer - If
I want to create an intraday EA designed to trade RSI pullbacks in the direction of the dominant trend during sufficient volatility, scales out profits, and automatically stands aside when market conditions stop supporting its edge. It should have the following features and are based on the following indicators: Trade FX on M15 Enter based on RSI, EMA and ATR Scale out profits using a multi-TP structure Trade only
I need a marketer who can actively sell my MetaTrader EA and generate real purchases. Offer Upfront: $50 (to start work immediately) Commission: 30% per sale on NET price (after payment processor/platform fees; VAT/taxes excluded) Commission is paid only on verified sales tracked through unique links/coupons. Your Job (what “SELL” means here) You must: Bring targeted buyers (traders, forex/crypto communities
hello great developer I am looking for a trading bot that can automatically execute trades on my behalf. I am a member of a premium Telegram signals group, and I would like the bot to place all trades automatically and atomically as soon as the signals are posted in the group. The primary issue I am facing is that the group operates during London trading hours, and I occasionally miss signals due to time differences
Strategy Development: Suggest a high-probability trading strategy based on Technical Analysis (using indicators like RSI, MACD, or Price Action). Risk Management: Explain how to calculate position sizing so I don't lose more than 1-2% of my capital per trade. Market Analysis: Teach me how to identify Support and Resistance levels and how to spot a trend reversal. Psychology: Give me 5 golden rules to maintain

Informazioni sul progetto

Budget
100 - 200 USD
Scadenze
da 2 a 4 giorno(i)

Cliente

Ordini effettuati1
Numero di arbitraggi0