Debugging exit 2 which use stochastic (simple logic)

MQL5 Indikatoren Experten

Spezifikation

1) Core strategy logic (state machine)

States:

  • BEGINNING_00 (idle)

  • SETUP_00 → SETUP_01 → SETUP_02 → SETUP_03

  • SELL mirror required

Donchian touch triggers:

  • BUY_SETUP_00 triggers ONLY when price touches Donchian LOW

  • SELL_SETUP_00 triggers ONLY when price touches Donchian HIGH

  • Special case: if a candle touches BOTH Donchian high and low, use WAD trend on that candle to decide BUY vs SELL on that candle.

Restart-on-touch (important):

  • If there is no position at the close of candle n, and candle n touches Donchian, then the setup must restart to Setup_00 from candle n (even if previously in Setup_01/02/03).

  • This affects which candle is the “first setup candle” and therefore affects fixed cut-loss, retracement reference, and TP1 base.

Valid setup bar count rules:

  • setup candle t, t+1, t+2, t+3 are valid setup candles

  • t+4 is last chance for a pending stop order fill (same as Python logic)

Fixed stop loss rule (big requirement):

  • In SETUP_01, the cut loss (SL) must be fixed at the FIRST Setup01 candle.

  • Entry trigger level can trail each new setup candle.

  • Intrabar special case:

    • If price breaks the stop-loss side first (e.g., long breaks below stop level) then breaks the trigger level later in the same candle, then the SL is adjusted to the new extreme (and sizing adjusted if needed). Mirror for short.

Entry types (user selectable)
A) Normal stop entry:

  • Long: Buy Stop at setup candle High + 1 pip + spread (bid-stream model)

  • Short: Sell Stop at setup candle Low - 1 pip (bid-stream model)

B) Retracement entry:

  • Virtual breakout trigger starts retrace logic when breakout trigger is hit

  • Long: Buy Limit at % retracement from swing high toward swing ref

  • Short: Sell Limit at % retracement from swing low toward swing ref

  • CAP rule:

    • Long: if limit > breakout stop-entry price, cap it at breakout stop-entry

    • Short: if limit < breakout stop-entry price, cap it at breakout stop-entry

TP1 / TP2 exits
Two-position hedging mode:

  • At entry, open two separate positions:

    • TP1 leg = 50% volume, has server-side TP at TP1

    • Runner leg = 50% volume, no TP; TP2 logic activates only after TP1 is closed

  • Preferred over partial close

TP1:

  • Default TP1 = 1R, but in retracement mode TP1 is based on virtual breakout entry (not the retrace fill price)

TP2 method A — Stochastic trailing (this is the main area that still has issues):
Scanning start:

  • If TP1 hits on candle t, start scanning TP2 on candle t+1

Activation (whichever happens first after scanning starts):

  • Long: %K ≥ 80 OR %K crosses below %D

  • Short: %K ≤ 20 OR %K crosses above %D
    Important:

  • If TP1 hit and %K is already beyond threshold when scanning starts, activate immediately (no need to cross into it).

Trailing start:

  • If activation happens on candle a, trailing begins on candle a+1:

    • Long: stop = low(a) − 1 pip (applied from a+1 onward)

    • Short: stop = high(a) + 1 pip (applied from a+1 onward)

  • Tighten-only trailing (never loosens)

TP2 method B — PSAR trailing:

  • PSAR(t-1) trailing after TP1 closed

  • Freeze when PSAR flips to wrong side; resume when PSAR flips back
    (PSAR seems okay)

Risk / sizing:

  • Position size is risk n% of capital m (both inputs)

  • For JPY pairs etc, sizing uses OrderCalcProfit-based calculation to avoid tick-value conversion issues

Execution model:

  • Bid-stream core logic

  • Spread adjustments applied where required (e.g., buy entries, sell SL/TP, etc.)

2) What’s currently wrong

Most state machine is correct now, but TP2 Stochastic trailing sometimes:

  • does not activate when it should

  • or trails using the wrong candle reference

  • or appears inconsistent (sometimes correct, sometimes wrong)

I suspect a combination of:

  • activation gating timing (TP1 close time vs when EA detects it)

  • bar indexing / shift

  • position selection context (PositionSelectByTicket affecting subsequent PositionGet* calls)

  • SL modify failures due to stops/freeze (needs explicit logging)


Bewerbungen

1
Entwickler 1
Bewertung
(1)
Projekte
0
0%
Schlichtung
2
0% / 50%
Frist nicht eingehalten
0
Arbeitet
2
Entwickler 2
Bewertung
(1)
Projekte
2
0%
Schlichtung
1
0% / 100%
Frist nicht eingehalten
0
Frei
Veröffentlicht: 2 Beispiele
3
Entwickler 3
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Arbeitet
4
Entwickler 4
Bewertung
(3)
Projekte
1
0%
Schlichtung
5
0% / 100%
Frist nicht eingehalten
0
Frei
5
Entwickler 5
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
6
Entwickler 6
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
7
Entwickler 7
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
8
Entwickler 8
Bewertung
(305)
Projekte
548
35%
Schlichtung
79
32% / 42%
Frist nicht eingehalten
197
36%
Beschäftigt
9
Entwickler 9
Bewertung
(2)
Projekte
2
0%
Schlichtung
2
0% / 50%
Frist nicht eingehalten
1
50%
Beschäftigt
10
Entwickler 10
Bewertung
(6)
Projekte
14
43%
Schlichtung
2
0% / 100%
Frist nicht eingehalten
1
7%
Arbeitet
11
Entwickler 11
Bewertung
(15)
Projekte
34
24%
Schlichtung
4
0% / 50%
Frist nicht eingehalten
2
6%
Arbeitet
12
Entwickler 12
Bewertung
(4)
Projekte
3
33%
Schlichtung
2
0% / 100%
Frist nicht eingehalten
0
Frei
13
Entwickler 13
Bewertung
(15)
Projekte
18
6%
Schlichtung
8
38% / 38%
Frist nicht eingehalten
2
11%
Arbeitet
Ähnliche Aufträge
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ #property strict // Inputs input int EMA_Fast = 9; input int EMA_Slow = 21; input int RSI_Period = 14; input double Lots = 0.1; input int StopLoss = 20; // وقف خسارة (بـ نقاط) input int TakeProfit = 40; // هدف (بـ نقاط)
Indicator 130+ USD
To trade Forex and pass FTMO challenges by combining: Smart Money Concepts (SMC), RSI divergence and Strict filtering to avoid overtrading and drawdown. If you’re experienced in this let me know. Thank you very much
Attached Files Can be used for reference. Please thoroughly understand the requirements and mql5 & set files before accepting the request. 1. Only Accept the job request if you are able to complete on time 2. I want you to show me demo of the Bot created and tested in Demo account for at least 3 days 3. I want you to show me the back tested results for last 5 years 4. 2 bots Need to be created Bot 1 with attached
// Add this to your EA after ExportState() function void SendToBase44(const string state, const string dir, double entry, double sl, double tp) { string url = " https://preview-sandbox--ee0a32a725b788974de435e8cef40b7a.base44.app/api/functions/receiveEAState "; string headers = "Content-Type: application/json\r\n"; string json = "{" "\"symbol\":\""+_Symbol+"\","
Hello! I am looking for an experienced, top-rated developer to build highly profitable strategy software that provides accurate signals for both long-term and short-term trades. The software must analyse the market correctly, indicating when to enter and where to set Take Profit (TP) and Stop Loss (SL) levels. It must deliver accurate results across all markets, including Forex, cryptocurrencies, metals, indices, and
I would like an experienced developer to work with. I have an existing EA I would like to modify. The EA works well on demo account but for some reasons, is not profitable on live account. I want an experienced developer to optimise it for a live account. Note: I only have a trial version of the EA, I do not have the source code
I am looking for an experienced MT4 Expert Advisor developer to help backtest and optimize an existing EA for prop firm trading . The EA currently trades Gold (XAUUSD) on M1/M5 , and the goal is to make it low-risk, stable, and prop-firm friendly , while also identifying a more aggressive preset for evaluation phases
I am looking for an experienced MQL5 developer to build a professional MT5 software (indicator or semi-automated EA) for metals and major forex pairs. 📌 PLATFORM & MARKETS Platform: MetaTrader 5 Instruments: XAUUSD (Gold vs USD) XAGUSD (Silver vs USD) EURUSD GBPUSD USDJPY Trading styles: Scalping Intraday / short-term swing 🎯 MAIN OBJECTIVE I do NOT want an aggressive fully automated robot. I want a
I am seeking an experienced freelance marketing and algorithmic trading specialist to develop a user-friendly automated trading bot for the Pocket Option platform. The system should feature a simple and secure interface that allows direct login using my existing credentials. The bot will be designed to operate exclusively on multiple OTC currency pairs (a minimum of 10, such as EUR/USD OTC, GBP/JPY OTC, and similar
I am looking for someone who has or who can modify the Margin Trader EA by MaryJane preferably the MT5 version by making it pyramid using a fixed lot size addition(preferably 1st trade lot size) instead of using all the margin available to define the lotsize

Projektdetails

Budget
30 - 100 USD

Kunde

Veröffentlichte Aufträge1
Anzahl der Schlichtungen0