Debugging exit 2 which use stochastic (simple logic)

MQL5 指标 专家

工作已完成

执行时间9 分钟
员工反馈
Thank you!
客户反馈
developer deliver the job according to my need

指定

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)


反馈

1
开发者 1
等级
(1)
项目
0
0%
仲裁
2
0% / 100%
逾期
0
空闲
2
开发者 2
等级
(1)
项目
2
0%
仲裁
1
0% / 100%
逾期
0
空闲
发布者: 2 代码
3
开发者 3
等级
(2)
项目
3
0%
仲裁
1
0% / 0%
逾期
2
67%
空闲
4
开发者 4
等级
(3)
项目
1
0%
仲裁
5
0% / 100%
逾期
0
空闲
5
开发者 5
等级
项目
0
0%
仲裁
0
逾期
0
空闲
6
开发者 6
等级
项目
0
0%
仲裁
0
逾期
0
空闲
7
开发者 7
等级
项目
0
0%
仲裁
0
逾期
0
空闲
8
开发者 8
等级
(319)
项目
574
35%
仲裁
83
31% / 45%
逾期
207
36%
空闲
9
开发者 9
等级
(7)
项目
5
0%
仲裁
5
0% / 80%
逾期
1
20%
工作中
10
开发者 10
等级
(16)
项目
30
40%
仲裁
3
33% / 67%
逾期
7
23%
工作中
11
开发者 11
等级
(16)
项目
35
23%
仲裁
4
0% / 50%
逾期
2
6%
工作中
12
开发者 12
等级
(4)
项目
3
33%
仲裁
2
0% / 100%
逾期
0
空闲
13
开发者 13
等级
(19)
项目
22
18%
仲裁
9
33% / 44%
逾期
3
14%
工作中
发布者: 1 代码
14
开发者 14
等级
项目
2
0%
仲裁
0
逾期
1
50%
空闲
15
开发者 15
等级
项目
0
0%
仲裁
0
逾期
0
空闲
16
开发者 16
等级
(13)
项目
20
40%
仲裁
3
0% / 67%
逾期
3
15%
空闲
17
开发者 17
等级
(6)
项目
7
14%
仲裁
1
0% / 100%
逾期
1
14%
空闲
18
开发者 18
等级
(648)
项目
876
48%
仲裁
29
38% / 17%
逾期
63
7%
空闲
19
开发者 19
等级
(22)
项目
29
3%
仲裁
4
25% / 0%
逾期
3
10%
空闲
20
开发者 20
等级
(634)
项目
741
34%
仲裁
49
53% / 39%
逾期
14
2%
工作中
21
开发者 21
等级
(258)
项目
269
29%
仲裁
2
50% / 0%
逾期
3
1%
工作中
发布者: 2 代码
22
开发者 22
等级
(10)
项目
17
18%
仲裁
2
0% / 50%
逾期
3
18%
已载入
23
开发者 23
等级
项目
0
0%
仲裁
0
逾期
0
空闲
24
开发者 24
等级
(10)
项目
14
43%
仲裁
0
逾期
3
21%
空闲
25
开发者 25
等级
(22)
项目
28
7%
仲裁
9
33% / 33%
逾期
1
4%
工作中
26
开发者 26
等级
(1)
项目
1
100%
仲裁
1
0% / 0%
逾期
0
工作中
发布者: 36 文章, 9 代码
相似订单
I am looking for an experienced MQL5 developer or development team to build a scalable Telegram-to-MT5 copy trading system. The main purpose of the system is to monitor trading signals from my Telegram channel and automatically execute those signals on connected client MT5 accounts. Core Requirements Receive and parse trading signals from Telegram Automatically execute trades on connected MT5 accounts Support more
Thana ram 30 - 200 USD
Hello, I want to develop a custom MT5 Expert Advisor (EA) for XAUUSD Gold. IMPORTANT: I want a proper rule-based automated trading EA, NOT a martingale, grid or guaranteed-profit bot. 1. MARKET & TIMEFRAME - Platform: MT5 - Symbol: XAUUSD only - Main trend timeframe: M15 - Entry timeframe: M5 - Must support broker suffixes such as XAUUSDm, XAUUSD., etc. 2. TREND RULE BUY trend: - M15 price above EMA 50 - EMA 50 above
I need a TradingView Pine Script (v6) indicator that gives BUY and SELL signals in real time on the live chart. MAIN REQUIREMENT – NO REPAINTING: 1. Signals must appear only when the candle closes (barstate.isconfirmed). Example: on 1-min chart, signal for the 10:35 candle must appear at 10:36 and never disappear or move. 2. Signals on historical bars must look exactly the same as they looked live. 3. No lookahead
Description I am looking for a highly skilled MQL5 Developer & Trader with strong experience in EA optimization, stress testing, and forward validation. The EA is already coded and running. What I need now is: 1.Simple code editing, code adjustment/upgrading and code tamplates inserting, 2.Parameter Optimization & Re-Validation – Find the best stable settings for XAUUSD (not overfitted). 3.Robustness / Stress Testing
المطلوب موشر لتداول الذهب مجرب وقوية يعطي اشاره قوية فقط مع وقف خساره ومختبر ومجرب في حال الموافقه علي لموشر بعد التجربه لمدة ٣ ايام يتم الشراء دايم مبلغ ٢٠٠ دولار
Strategy 40 - 60 USD
yo i have a strategy i would really like to turn into a signal bot basically please this is very technical and serious to me the strategy needs more time 1 time frame and the bot most be 100% accurate
can you help me use a Tickblaze Algo NRBO on the NT platform? I have it somewhat set up, but I have other questions about running it & knowing how to operate it in NT. Thank you if anyone have experience in this kindly bib and let do it asap
I need a trading system similar to the attached files. Check attachment for details on the indicator. i guess the indicator contains some of (Rainbow MA , MTF Dashboard , Symbol Switcher , and Trend Histogram), though may not be exactly as listed
I have a EA/Bot I’ve designed and want it to be put onto me MetaTrader5 this month. I’m new here and also need to figure out how to get a live account and add a UK broker
Hi. I am looking for an experienced MQL5 developer for an advanced XAUUSD MT5 indicator. Before choosing a developer, I would like to see a small proof-of-concept or an example of a similar indicator you have already developed. My final indicator must be written from scratch in MQL5 and I must receive the complete .mq5 source code + compiled .ex5 . Main requirements: XAUUSD MT5 / MQL5 Indicator only — NO AutoTrading

项目信息

预算
30 - 100 USD