Debugging exit 2 which use stochastic (simple logic)

MQL5 Indicadores Asesores Expertos

Trabajo finalizado

Plazo de ejecución 9 minutos
Comentario del Cliente
developer deliver the job according to my need
Comentario del Ejecutor
Thank you!

Tarea técnica

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)


Han respondido

1
Desarrollador 1
Evaluación
(1)
Proyectos
0
0%
Arbitraje
2
0% / 100%
Caducado
0
Libre
2
Desarrollador 2
Evaluación
(1)
Proyectos
2
0%
Arbitraje
1
0% / 100%
Caducado
0
Libre
Ha publicado: 2 ejemplos
3
Desarrollador 3
Evaluación
(2)
Proyectos
3
0%
Arbitraje
1
0% / 0%
Caducado
2
67%
Libre
4
Desarrollador 4
Evaluación
(3)
Proyectos
1
0%
Arbitraje
5
0% / 100%
Caducado
0
Libre
5
Desarrollador 5
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
6
Desarrollador 6
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
7
Desarrollador 7
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
8
Desarrollador 8
Evaluación
(311)
Proyectos
557
35%
Arbitraje
79
32% / 43%
Caducado
202
36%
Trabaja
9
Desarrollador 9
Evaluación
(7)
Proyectos
5
0%
Arbitraje
6
0% / 83%
Caducado
1
20%
Trabaja
10
Desarrollador 10
Evaluación
(10)
Proyectos
19
37%
Arbitraje
2
0% / 100%
Caducado
4
21%
Trabajando
11
Desarrollador 11
Evaluación
(16)
Proyectos
35
23%
Arbitraje
4
0% / 50%
Caducado
2
6%
Trabaja
12
Desarrollador 12
Evaluación
(4)
Proyectos
3
33%
Arbitraje
2
0% / 100%
Caducado
0
Libre
13
Desarrollador 13
Evaluación
(16)
Proyectos
20
10%
Arbitraje
8
38% / 38%
Caducado
3
15%
Trabaja
14
Desarrollador 14
Evaluación
Proyectos
2
0%
Arbitraje
0
Caducado
1
50%
Libre
15
Desarrollador 15
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
16
Desarrollador 16
Evaluación
(13)
Proyectos
20
40%
Arbitraje
3
0% / 67%
Caducado
3
15%
Libre
17
Desarrollador 17
Evaluación
(6)
Proyectos
7
14%
Arbitraje
1
0% / 100%
Caducado
1
14%
Libre
18
Desarrollador 18
Evaluación
(635)
Proyectos
856
48%
Arbitraje
29
38% / 17%
Caducado
63
7%
Libre
19
Desarrollador 19
Evaluación
(22)
Proyectos
29
3%
Arbitraje
4
25% / 0%
Caducado
3
10%
Trabaja
20
Desarrollador 20
Evaluación
(561)
Proyectos
649
33%
Arbitraje
41
41% / 46%
Caducado
11
2%
Ocupado
21
Desarrollador 21
Evaluación
(255)
Proyectos
262
30%
Arbitraje
0
Caducado
3
1%
Libre
Ha publicado: 2 ejemplos
22
Desarrollador 22
Evaluación
(3)
Proyectos
6
17%
Arbitraje
1
0% / 0%
Caducado
1
17%
Trabaja
23
Desarrollador 23
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
24
Desarrollador 24
Evaluación
(10)
Proyectos
14
43%
Arbitraje
0
Caducado
3
21%
Libre
25
Desarrollador 25
Evaluación
(18)
Proyectos
22
9%
Arbitraje
6
33% / 50%
Caducado
1
5%
Trabajando
26
Desarrollador 26
Evaluación
Proyectos
0
0%
Arbitraje
0
Caducado
0
Libre
Ha publicado: 1 artículo, 2 ejemplos
Solicitudes similares
I have existing compiled indicator and script files (EX4) and would like to have them recreated in both MQL4. ⚠️ Important: This project is NOT for decompiling or reverse engineering. Instead, the goal is to: Analyze the behavior and output of the provided files Recreate equivalent functionality from scratch Deliverables: 1 MQL4 indicator source code (.mq4) 1 MQL4 script source code (.mq4) Requirements: The recreated
I need a good programmer to help convert an existing indicator to a trading EA that can work on both MT4 and MT5. The expected features on the EA is as follows: Max Spread: Magic Number: Take Profit: Stop Loss: Trailing Stop: Fixed Lot Size: Money Management: false/true Min Lot Size: Max Lot Size: Risk to Trade %: Daily Profit Target %: Add news filter. Get my jobs with source code
A perfect indicator 30 - 80 USD
Merge nearby zones yes/no Alert on/off Label on/off Show only current relevant zones near price yes/no Distance filter from current price Zone transparency Colors Preferred Output on Chart: I want the indicator to show only: the strongest nearby support zones under price the strongest nearby resistance zones above price major higher timeframe zones clean chart view I do not want excessive clutter. Entry Assistance
Criei um Robô para a venda alta precisão que automatiza a estratégia de correção média de Larry Williams. Possui filtros de tendência seletiva, controle de lote por risco percentual e execução rápida. Compatível com contas Hedge e Netting. Configuração simples e otimizada para mercados de alta volatilidade. *55(16) 993786056
SMC ORDER BLOCK 30 - 60 USD
I want already build FULLY AUTOMATED order block MT5 XAUUSD HTF H4 ENTRY LTF M15 - Show result on live account. m15 ob entry in the direction of h4 ob bias the developper to provide source code in the end
I need an MT5 Expert Advisor built as a high-precision volumizer for Forex. Its core purpose is to generate controlled trading volume for rebates, while still maintaining low-risk account growth. I am not looking for aggressive profit chasing. I am looking for a stable, intelligent EA that can produce volume in a disciplined way without damaging the account. The ideal system should trade major currency pairs, avoid
1. IF price forms: - Higher highs + higher lows → TREND = BUY - Lower highs + lower lows → TREND = SELL ELSE → NO TRADE 2. IF: - Trend = BUY - Price retraces to support zone - Bullish engulfing candle forms - TDI green crosses above red (optional) THEN: - Execute BUY 3. IF: - Trend = SELL - Price retraces to resistance - Bearish engulfing forms - TDI confirms THEN: - Execute SELL 4. Risk per trade = 1% of account Lot
I need a high frequency trading robot for gold in one or 5 minute timeframe the robot should have spread filter where it should only open trades below a set spread should have news filter to allow trading during fundal news or not the robot should have input in number of minutes to close all open trades and remove pending orders before fundamental news as part of news filter. It should also have the number of minutes
Hello! I want to programm EA that uses volume profile indicator, but I am not sure if this is possible. Only experienced programmers please, I will not select a programmer who did only few jobs. Before starting I need to make sure you understand everything and that this is for sure technically possible
Hello, I am looking for a professional trading system including: 1- Trading Bot (Expert Advisor): - Good profit performance - High security and strong risk management - Works efficiently during high market volatility (news and strong movements) - Works on all pairs (Forex + Gold) 2- Signal Indicator: - Provides clear Buy and Sell signals - Includes Take Profit and Stop Loss - No repaint (signals must not change or

Información sobre el proyecto

Presupuesto
30 - 100 USD