Debugging exit 2 which use stochastic (simple logic)

MQL5 Indicators Experts

Job finished

Execution time 9 minutes
Feedback from customer
developer deliver the job according to my need
Feedback from employee
Thank you!

Specification

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)


Responded

1
Developer 1
Rating
(1)
Projects
0
0%
Arbitration
2
0% / 100%
Overdue
0
Free
2
Developer 2
Rating
(1)
Projects
2
0%
Arbitration
1
0% / 100%
Overdue
0
Free
Published: 2 codes
3
Developer 3
Rating
(2)
Projects
3
0%
Arbitration
1
0% / 0%
Overdue
2
67%
Free
4
Developer 4
Rating
(3)
Projects
1
0%
Arbitration
5
0% / 100%
Overdue
0
Free
5
Developer 5
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
6
Developer 6
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
7
Developer 7
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
8
Developer 8
Rating
(318)
Projects
565
35%
Arbitration
81
31% / 44%
Overdue
204
36%
Free
9
Developer 9
Rating
(7)
Projects
5
0%
Arbitration
5
0% / 80%
Overdue
1
20%
Working
10
Developer 10
Rating
(14)
Projects
27
41%
Arbitration
3
0% / 67%
Overdue
6
22%
Working
11
Developer 11
Rating
(16)
Projects
35
23%
Arbitration
4
0% / 50%
Overdue
2
6%
Working
12
Developer 12
Rating
(4)
Projects
3
33%
Arbitration
2
0% / 100%
Overdue
0
Free
13
Developer 13
Rating
(17)
Projects
21
14%
Arbitration
8
38% / 38%
Overdue
3
14%
Loaded
14
Developer 14
Rating
Projects
2
0%
Arbitration
0
Overdue
1
50%
Free
15
Developer 15
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
16
Developer 16
Rating
(13)
Projects
20
40%
Arbitration
3
0% / 67%
Overdue
3
15%
Free
17
Developer 17
Rating
(6)
Projects
7
14%
Arbitration
1
0% / 100%
Overdue
1
14%
Free
18
Developer 18
Rating
(645)
Projects
872
48%
Arbitration
29
38% / 17%
Overdue
63
7%
Free
19
Developer 19
Rating
(22)
Projects
29
3%
Arbitration
4
25% / 0%
Overdue
3
10%
Working
20
Developer 20
Rating
(611)
Projects
711
33%
Arbitration
45
49% / 42%
Overdue
14
2%
Working
21
Developer 21
Rating
(258)
Projects
267
30%
Arbitration
0
Overdue
3
1%
Working
Published: 2 codes
22
Developer 22
Rating
(8)
Projects
14
21%
Arbitration
2
0% / 50%
Overdue
3
21%
Working
23
Developer 23
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
24
Developer 24
Rating
(10)
Projects
14
43%
Arbitration
0
Overdue
3
21%
Free
25
Developer 25
Rating
(21)
Projects
27
7%
Arbitration
9
33% / 33%
Overdue
1
4%
Working
26
Developer 26
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Working
Published: 16 articles, 2 codes
Similar orders
Hi, I am looking for an already made profitable EA. It can be an indicator but then it must be possible to make an EA from the indicator. Will need to test before payment (this can be in demo or limited time test). I will pay up to $6000. Do not apply if you want an upfront payment. I need to test for a few times first. Mostly only pips matters. I look much the risk safety, money management, risk reward, and overall
Привіт. Шукаю когось, хто б застосував мій код як бота . Я торгую індексом Aus_200 SFE (не XJO). Бот базується на MACD входу/виходу, RSI, стохастиці та vwap. Як тільки роботу приймуть, мені потрібно внести кілька коректив; однак, нічого суттєвого. Дякую
SMC Martingale Pro is an advanced MetaTrader 5 Expert Advisor designed for high-volatility markets like XAU/USD. It combines institutional Smart Money Concepts with a dynamic risk recovery system. Key Features Dual FVG Engine: Automatically identifies and renders both bullish and bearish Fair Value Gaps in real time. Multi-Timeframe Flexibility: Operates independently of the active chart timeframe to target
I am looking for an experienced Sierra Chart ACSIL (C++) developer to create a custom indicator that measures the average Prior Day High-Low range over a configurable number of trading days (default: 7 days) using a 23-hour trading session
I have a technical specification ready for a custom alert indicator in NinjaTrader 8 (NinjaScript / C#). Important clarification: it is NOT an automatic trading bot, it is solely a visual indicator (arrows/lines on the chart) and sound alerts (notifications) based on EMA crossovers and range breakouts (ORB 15m) on lower timeframes for futures (MES). I already have the exact rules written out unambiguously
Custom MT5 EA for buy stop and sell stop breakout strategy.’ ‘Requirements, develop a custom Expert Advisor for MetaTrader 5 that places buy-stop and sell-stop pending orders based on defined breakout rules.’ ‘All important values adjustable via inputs.’ ‘Includes stop loss, take profit, trailing stop, and configurable risk management.’ ‘One trade at a time, works on demo before live.’ Provide source code and
I have an automated trading strategy in NinjaTrader 8 (C# / NinjaScript) that is currently under development. Before diving into technical details, I’d like to ask a quick question from someone who's interested. Do you work on existing / in-progress codebases to debug, refactor, or add new features, or do you strictly build projects from scratch? NOTE : Only professional Developer should apply for this project
السلام عليكم ورحمة الله وبركاته، ​أبحث عن مبرمج MQL5 خبير ومتمكن جداً لتطوير روبوت تداول (Expert Advisor) محترف لمنصة MetaTrader 5 يعمل باستراتيجية هيدج محددة بصفقة واحدة فقط في كل اتجاه (1 Buy & 1 Sell Max) مع إدارة مخاطر صارمة. ​المواصفات والاستراتيجية المطلوبة: ​1. آلية الهيدج المحدود (Single Position Hedging Limit): ​الحد الأقصى للصفقات: يُسمح للروبوت بفتح صفقة شراء واحدة (1 Buy) وصفقة بيع واحدة (1 Sell) فقط كحد
Looking for A verifiable, disciplined XAUUSD analyst with controlled drawdown, consistent stop-loss use, clear communication and the capacity to service a live community. To send daily London and New York signals exclusively in my channel on Telegram
SENIOR MQL5 / QUANTITATIVE DEVELOPER REQUIRED — PROFESSIONAL AI-ASSISTED MT5 TRADING SYSTEM Project Overview I am seeking a highly experienced MQL5 developer, quantitative trading-system engineer or small specialist team to design and build a professional, fully auditable MetaTrader 5 trading system. This is not a request for a basic indicator conversion, copied Expert Advisor, martingale robot, grid-recovery system

Project information

Budget
30 - 100 USD