var config = { 
	  baseBet: { label: "Base Bet", value: 0.05, type: "number" }, 
	  payout: { label: "Payout Target", value: 2, type: "number" }, 
	  redThreshold: { label: "Wait for X Reds Under Payout Target", value: 5, type: "number" }, 
	  lossMultiplier: { label: "Loss Multiplier (Martingale)", value: 2, type: "number" }, 
	  maxBet: { label: "Max Bet Limit", value: 100, type: "number" }, 
	  stop: { label: "Stop if next bet >", value: 1e8, type: "number" } 
	};
 
	function main() { 
	  var currentBet = config.baseBet.value; 
	  var isWaitingMode = true; // Start in waiting mode 
	  var consecutiveReds = 0; 
	  var totalGames = 0; 
	  var sessionWins = 0; 
	  var sessionLosses = 0;
 
	  // Function to count consecutive reds from history (using payout target as threshold) 
	  function countConsecutiveReds() { 
	    var redCount = 0; 
	    for (var i = 0; i < game.history.length; i++) { 
	      if (game.history[i].odds < config.payout.value) { // Use payout target as threshold 
	        redCount++; 
	      } else { 
	        break; // Stop counting when we hit a green (>=payout target) 
	      } 
	    } 
	    return redCount; 
	  }
 
	  // Function to display recent history (simplified, only show crash multipliers) 
	  function showRecentHistory() { 
	    var historyStr = "Recent: "; 
	    for (var i = 0; i < Math.min(8, game.history.length); i++) { 
	      var crash = game.history[i].odds; 
	      var color = crash >= config.payout.value ? "" : ""; 
	      historyStr += color + crash.toFixed(2) + "x "; 
	    } 
	    log.info(historyStr); 
	  }
 
	  game.onBet = function () { 
	    totalGames++; 
	     
	    // Count current consecutive reds 
	    consecutiveReds = countConsecutiveReds(); 
	     
	    // Show current status 
	    showRecentHistory(); 
	     
	    if (isWaitingMode) { 
	      // WAITING MODE - Check if we have enough reds to start betting 
	      if (consecutiveReds >= config.redThreshold.value) { 
	        isWaitingMode = false; 
	        currentBet = config.baseBet.value; 
	        log.success(" THRESHOLD MET! " + consecutiveReds + " consecutive reds under " + config.payout.value + "x - Starting to bet!"); 
	      } else { 
	        log.info(" WAITING - Need " + config.redThreshold.value + " reds under " + config.payout.value + "x, currently have " + consecutiveReds + " consecutive reds"); 
	        return; // Skip betting this round 
	      } 
	    }
 
	    // BETTING MODE - Place actual bet 
	    if (currentBet > config.maxBet.value) { 
	      currentBet = config.maxBet.value; 
	      log.warn(" Bet capped at maximum: " + config.maxBet.value); 
	    }
 
	    if (currentBet > config.stop.value) { 
	      log.error(" Bet too high: " + currentBet + " - STOPPING!"); 
	      game.stop(); 
	      return; 
	    }
 
	    log.success(" Game #" + totalGames + " - BETTING: " + currentBet.toFixed(6) + " at " + config.payout.value + "x"); 
	    log.info(" Session: " + sessionWins + " wins, " + sessionLosses + " losses");
 
	    game.bet(currentBet, config.payout.value).then(function (payout) { 
	      if (payout > 1) { 
	        // WIN - Reset to base bet and go back to waiting mode 
	        sessionWins++; 
	        var profit = currentBet * (config.payout.value - 1); 
	         
	        log.success(" WIN! Profit: " + profit.toFixed(6) + " | Crash: " + payout.toFixed(2) + "x"); 
	        log.success(" Resetting to WAITING mode - need " + config.redThreshold.value + " new reds under " + config.payout.value + "x"); 
	         
	        // Reset everything 
	        currentBet = config.baseBet.value; 
	        isWaitingMode = true; 
	         
	      } else { 
	        // LOSS - Martingale (increase bet) but stay in betting mode 
	        sessionLosses++; 
	         
	        log.error(" LOSS! Crash: " + payout.toFixed(2) + "x | Lost: " + currentBet.toFixed(6)); 
	         
	        // Increase bet for next round (martingale) 
	        currentBet = currentBet * config.lossMultiplier.value; 
	         
	        log.info(" Next bet: " + currentBet.toFixed(6) + " (Martingale x" + config.lossMultiplier.value + ")"); 
	        log.info(" Still in BETTING mode - will continue until win"); 
	         
	        // Check if next bet would be too high 
	        if (currentBet > config.maxBet.value) { 
	          log.warn(" Next bet would exceed max limit - will be capped!"); 
	        } 
	      } 
	    }); 
	  }; 
	}