Add randomness to entries
Use a random entry condition to skip some entry opportunities and explore how your strategy responds. This complements testing different profit targets, stop losses, and expiration choices.
Example: a 50% entry filter
Open the AI Editor and add a random condition to your strategy's Entry section:
"Entry": {
"Schedule": {
"BeforeMarketCloseMinutes": "30",
"Every": "day"
},
"Conditions": [
"random(0, 1) == 1"
]
}
This is a fragment of a Strategy Definition. Keep your other entry settings and conditions when applying it.
At each evaluation, random(0, 1) draws either 0 or 1 with equal probability. The comparison passes when it draws 1, giving this filter a 50% chance of allowing entry. Other entry conditions and settings must also allow the trade.
The example checks daily, 30 minutes before market close. If the filter rejects an entry, it skips that opportunity; it does not schedule a replacement trade. A later scheduled check may allow entry.
Change the probability
For a different probability, use a larger integer range. For example:
"Conditions": [
"random(1, 100) <= 25"
]
This filter has a 25% chance of passing each time it is evaluated. It does not guarantee that exactly one quarter of entry opportunities will produce trades.
See Script Engine built-in functions for the random function and other expressions.
Compare with your original strategy
Keep a baseline run without the random filter. Use Clone to add the filter, leaving the other settings unchanged, then compare the backtest results.
You can combine the random filter with Implied Volatility or up/down-day conditions. Validate the Strategy Definition in MesoSim before running it.