Can someone help? Thanks

Forums ProRealTime English forum ProOrder support Can someone help? Thanks

Viewing 1 post (of 1 total)
  • #254088

    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

    //—————————

Viewing 1 post (of 1 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login