Same bar entry and exit, how to stop re-entry after exit?

After Buy & Sell at the same bar, it buy again immediately.
How to stop the immediate Re-entry after sell the position at the same bar?

For stopping the re-entry, I tried add tradedir, failed
And then I add signalTriggered to mark the bar is traded also fail to remove the excess signal.

How to Stop the immediate Re-entry after exit??
Many Thanks

tradeDir = 0;

// Use loops to handle trades and conditions
// Use loops to handle trades and conditions
for (i = 1; i < BarCount; i++) {
    // Reset lossTrades counter and signalTriggered at the start of each day
   
   

    // Reset signalTriggered for the current bar
    signalTriggered = 0;



    // Short condition: 15-bar MA crosses above 5-bar MA
    if (downcon[i] AND tradeDir == 0 AND signalTriggered == 0) {
        Buy[i] = 1;
        BuyPrice[i] = Open[i];
        stopPrice = BuyPrice[i] + stopAmount;
        profitPrice = BuyPrice[i] - profitAmount;
        tradeDir = -1;
        signalTriggered = 1; // Mark that a signal has been triggered for this bar
    }

    // Cover condition: profit reaches 100 units or loss reaches 30 units
    if (tradeDir == -1) {
        if (H[i] > stopPrice) {
            Sell[i] = 2;
            SellPrice[i] = Max(Open[i], stopPrice);
            tradeDir = 0;
        }
        else if (L[i] < profitPrice) {
            Sell[i] = 3;
            SellPrice[i] = Min(Open[i], profitPrice);
            tradeDir = 0;  
        }

    }
}

your code seems incomplete, the issue may be in the redacted code.

Complete code alrady, i do buy only

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.