//@version=4 strategy(title="Random Entries Work", shorttitle="REW", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD,commission_type=strategy.commission.percent,commission_value=0) // === GENERAL INPUTS === strategy = input(defval="Long Only",title="Direction",options=["Long Only", "Short Only", "Random"]) enter_frequency = input(defval=10,minval=1,maxval=100,title="Percent Chance to Enter") exit_frequency = input(defval=3, minval=0,maxval=100,title="Percent Chance to Exit",tooltip="This should be much lower than Percent Chance to Enter. Higher values decrease time in market. Lower values increase time in market.") start_year = input(defval=2020, title="Start Year") // === LOGIC === r = random(0,100) enter = enter_frequency > r[0] exit = exit_frequency > r[0] direction = random(0,100) >= 50 // === STRATEGY - LONG POSITION EXECUTION === enterLong() => strategy.opentrades == 0 and enter and (strategy == "Long Only" or (strategy == "Random") and direction) and time > timestamp(start_year, 01, 01, 01, 01) exitLong() => exit strategy.entry(id="Long", long=strategy.long, when=enterLong()) strategy.close(id="Long", when=exitLong()) // === STRATEGY - SHORT POSITION EXECUTION === enterShort() => strategy.opentrades == 0 and enter and (strategy == "Short Only" or (strategy == "Random" and not direction)) and time > timestamp(start_year, 01, 01, 01, 01) exitShort() => exit strategy.entry(id="Short", long=strategy.short, when=enterShort()) strategy.close(id="Short", when=exitShort())
// === TIPS ===
//
// -Increasing «Percent Chance to Exit» will shorten the time in a trade. You can see the «Avg # Bars In Trade» go down as you increase. If «Percent Chance to Exit» is too high, the study won't be in the market long enough to catch any movement, possibly exiting on the same bar most of the time.
// -If you're getting the red screen, that means the strategy lost so much money it went broke. Try reducing the percent equity on the Properties tab.
// -Switch the start year to avoid black swan events like the covid drop in 2020.
// -
// === FINDINGS ===
//
// Most markets lose money with a «Random» direction strategy.
// Most markets lose ALL money with a «Short Only» strategy.
// Most markets make money with a «Long Only» strategy.
//
// Try this strategy on: Bitcoin (BTCUSD) and the NASDAQ (QQQ).
//
// There are two popular memes right now: «Bitcoin to the moon» and «Stocks only go up». Both are seemingly true. Bitcoin was the best performing asset of the 2010's, gaining several billion percent in gains. The stock market is on a 100 year long uptrend. Why? BECAUSE FIAT CURRENCIES ALWAYS GO DOWN! This is inflation. If we measure the market in terms of others assets instead of fiat, the Long Only strategy doesn't work anymore.
// Try this strategy on: Bitcoin/GLD (BTCUSD/GLD), the Eurodollar (EURUSD), and the S&P 500 measured in gold (SPY/GLD).
//
// Bitcoin measured in gold (BTCUSD/GLD) still works with a Long Only strategy because Bitcoin increased in value over both USD and gold.
// The Eurodollar (EURUSD) generally loses money no matter what, especially if you add any commission. This makes sense as they are both fiat currencies with similar inflation schedules.
// Gold and the S&P 500 have gained roughly the same amount since ~2000. Some years will show better results for a long strategy, while others will favor a short strategy. Now look at just SPY or GLD (which are both measured in USD by default!) and you'll see the same trend again: a Long Only strategy crushes even when entering and exiting randomly.
//
// === «JUST TELL ME WHAT TO DO, YOU NERD!» ===
//
// Bulls always win and Bears always lose because fiat currencies go to zero.
НИКТО и НИКОГДА не торгует случайными входами, как бы они эту случайность не проповедовали. Иначе бы они делали направления и время входов подбрасыванием монетки или сигналов из генератора случайных чисел. )))
Про нормальное распределение приращений цен была гипотеза, но я её даже проверять не стал, а принял как данное.
1. Не надо шортить рынки Это вывод для случайного входа! Ведь профит там генерируется за счет глобального тренда вверх
Справедливее было бы составить случайный портфель всего по чуть-чуть.
Там преимущество лонга сохранится, но уже не будет столь явным. И, возможно, профита по нему не будет из-за комиссий.
ГМК и Сбер — волатильные ликвидные. То есть хорошие для системной торговли. Новатэк ещё легче по волатильности, но менее ликвиден.