Can someone help? Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #254088 quote
    Marco
    Participant
    New

    Hopefully someone can helps and able to fix this code to work, somehow it trigger no trade, this code build for Nsadaq 100, 10 min time frame.

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM PRELOADBARS = 10000

    ONCE QtyContracts = 1
    PositionSize = QtyContracts

    //——————————————————————–
    // Parameters
    //——————————————————————–
    LookbackStructure = 8 // swing lookback
    FreshnessTapsMax = 10 // allow many retests before invalidation
    StopPaddingPts = 2
    TakeProfitR = 2
    MinExpansionAtr = 0 // disabled to force zone creation for testing

    //——————————————————————–
    // State variables
    //——————————————————————–
    ONCE InitialEquity = 1000
    ONCE Equity = InitialEquity
    ONCE MyPointValue = 1

    ZoneActive = 0
    ZoneType = 0 // 1 = demand, -1 = supply
    ZoneHigh = 0
    ZoneLow = 0
    ZoneTaps = 0
    ZoneAge = 0
    ZoneValid = 0
    ZoneCreationBar = 0

    EntryPrice = 0
    StopPrice = 0
    TargetPrice = 0

    //——————————————————————–
    // Indicators
    //——————————————————————–
    AtrLen = 7
    AtrValue = AverageTrueRange[AtrLen](Close)
    BarRange = High – Low

    //——————————————————————–
    // Zone Identification: Demand (swing low) and Supply (swing high)
    // – NO ATR filter (MinExpansionAtr = 0) so zones form reliably in backtest
    //——————————————————————–
    IF ZoneActive = 0 THEN

    // Demand = current Low is the lowest low of the lookback window
    IF Low = Lowest[LookbackStructure](Low) THEN
    ZoneLow = Low
    ZoneHigh = High
    ZoneType = 1
    ZoneActive = 1
    ZoneValid = 1
    ZoneTaps = 0
    ZoneAge = 0
    ZoneCreationBar = BARINDEX
    ENDIF

    // Supply = current High is the highest high of the lookback window
    IF ZoneActive = 0 AND High = Highest[LookbackStructure](High) THEN
    ZoneLow = Low
    ZoneHigh = High
    ZoneType = -1
    ZoneActive = 1
    ZoneValid = 1
    ZoneTaps = 0
    ZoneAge = 0
    ZoneCreationBar = BARINDEX
    ENDIF

    ENDIF

    //——————————————————————–
    // Manage Zone Lifecycle
    //——————————————————————–
    IF ZoneActive = 1 THEN

    ZoneAge = ZoneAge + 1

    // Count a retest only when price ENTERS the zone after being outside it on prior bar
    IF BARINDEX > ZoneCreationBar THEN
    IF Low <= ZoneHigh AND High >= ZoneLow THEN // current bar overlaps zone
    IF Low[1] > ZoneHigh OR High[1] < ZoneLow THEN // prior bar was outside
    ZoneTaps = ZoneTaps + 1
    ENDIF
    ENDIF
    ENDIF

    // expire on too many retests or excessive age
    IF ZoneTaps > FreshnessTapsMax OR ZoneAge > 2000 THEN
    ZoneValid = 0
    ZoneActive = 0
    ENDIF

    ENDIF

    //——————————————————————–
    // Entry Logic (simple bounce confirmation to force trades)
    // – Demand: price touches zone and closes higher than previous close (bounce)
    // – Supply: price touches zone and closes lower than previous close (drop)
    //——————————————————————–
    CanEnterLong = 0
    CanEnterShort = 0
    RiskPts = 0

    IF ZoneActive = 1 AND ZoneValid = 1 THEN

    // Demand: zoneType = 1
    IF ZoneType = 1 THEN
    IF BARINDEX > ZoneCreationBar THEN
    // current bar overlaps zone (touch or enter)
    IF Low <= ZoneHigh AND High >= ZoneLow THEN
    // simple bounce confirmation: current close > previous close
    IF Close > Close[1] THEN
    CanEnterLong = 1
    EntryPrice = Close
    StopPrice = ZoneLow – StopPaddingPts
    RiskPts = EntryPrice – StopPrice
    ENDIF
    ENDIF
    ENDIF

    // Supply: zoneType = -1
    ELSIF ZoneType = -1 THEN
    IF BARINDEX > ZoneCreationBar THEN
    IF Low <= ZoneHigh AND High >= ZoneLow THEN
    // simple momentum confirmation: current close < previous close
    IF Close < Close[1] THEN
    CanEnterShort = 1
    EntryPrice = Close
    StopPrice = ZoneHigh + StopPaddingPts
    RiskPts = StopPrice – EntryPrice
    ENDIF
    ENDIF
    ENDIF
    ENDIF

    ENDIF

    //——————————————————————–
    // Orders and sizing
    //——————————————————————–
    IF (CanEnterLong = 1 OR CanEnterShort = 1) AND NOT ONMARKET THEN

    Size = QtyContracts

    IF CanEnterLong = 1 THEN
    TargetPrice = EntryPrice + TakeProfitR * MAX(1, RiskPts)
    BUY Size CONTRACTS AT MARKET
    SET STOP LOSS StopPrice
    SET TARGET PROFIT TargetPrice
    ENDIF

    IF CanEnterShort = 1 THEN
    TargetPrice = EntryPrice – TakeProfitR * MAX(1, RiskPts)
    SELLSHORT Size CONTRACTS AT MARKET
    SET STOP LOSS StopPrice
    SET TARGET PROFIT TargetPrice
    ENDIF

    // mark zone consumed
    ZoneValid = 0
    ZoneActive = 0

    ENDIF

    //—————————

    #254113 quote
    Iván González
    Moderator
    Master

    Hi. The problem is that you are continuously resetting the state variables.
    If you remove them, you will start to see operations.

    robertogozzi and Marco thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Can someone help? Thanks


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Marco @wingyip Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
2 months, 4 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/29/2025
Status: Active
Attachments: No files
Logo Logo
Loading...