Valeria 181 Robot Strategy Improved 2.4

Author: ChaoZhang, Date: 2023-12-15 10:13:38


Overview: This strategy opens long/short positions based on Bollinger Bands crossover signals and pursues profits in the trending market with stop loss and take profit. Its advantages lie in keep tracking trends, reasonable stop loss and take profit configuration, controllable drawdown, suitable for medium and long term trading, especially in stock index, forex and crypto markets with obvious trending characters.

Principles: The strategy consists of three parts: BB crossover signals, fixed position sizing and dynamic stop loss and take profit. BB crossover system judges the breakout through bands generated by moving averages and standard deviation. Golden cross for long and dead cross for short. Fix 100% position either long or short to maximize profits following trends. Stop loss and take profit levels will be adjusted based on the latest entry price, so as to lock profit and control drawdown along the trend movement.

Specifically, BB bands are calculated with moving averages and standard deviation of closing prices. Golden cross above upper band gives buy signal while dead cross below lower band gives sell signal. They attempt to identify potential reversal points and trading opportunities. 100% position aims to pursue maximum profits by fully following trends. Dynamic stop loss and take profit are modified based on the latest entry price. Stop loss distance is set reasonably to control drawdown. Take profit distance is set to obtain more profits according to market fluctuation.


  1. Keep profits along trends, benefit from main direction through BB signal and full position.

  2. Controllable drawdown via dynamic stop loss and take profit based on entry price. Values can be optimized accordingly.

  3. Wide application in major markets with trends, especially suitable for stock index, forex and crypto assets.

  4. Simple logic and easy to implement technically with BB and fixed percent. No complex pattern or model judgments.

  5. High capital use efficiency by 100% long/short position to maximize capital allocation.

Risks and solutions:

  1. Invalid BB signal risks. Will cause wrong trading signals if BB judgment fails, solved by combining other indicators on trend judgment.

  2. Drawdown risks in consolidations, addressed by reducing position sizing and optimizing stop loss distance.

  3. Frequent trading risks in volatile markets with continuous stop loss jump between long and short. Can widen stop loss distance properly to reduce unnecessary triggers.

  4. Market risks from unexpected big events leading to irrational price spikes. Suggest to pay attention to key policies and events.


  1. Consider other indicators like MACD, KDJ together with BB to avoid misjudgments.

  2. Adjust stop loss and take profit distances based on market volatility.

  3. Select reasonable parameters for different market types. Such as larger standard deviation and moving average period for volatile markets.

  4. Optimize parameter values through machine learning algorithms for better performance.

Summary: The strategy is a typical trend following arbitrage system. It keeps profitable along obvious trends in multiple markets. The logic is simple and clean making it easy to implement technically. By configuring proper stop loss and take profit levels, the maximum drawdown can be effectively controlled. In general, this is an efficient trend trading strategy with stable returns, simple logic and easy execution. Highly recommend for quantitative trading.

start: 2022-12-08 00:00:00
end: 2023-12-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

strategy("Valeria 181 Bot Strategy Mejorado 2.21", overlay=true, margin_long=100, margin_short=100)
var float lastLongOrderPrice = na
var float lastShortOrderPrice = na

longCondition = ta.crossover(ta.sma(close, 1), ta.sma(close, 4))
if (longCondition)
    strategy.entry("Long Entry", strategy.long)  // Enter long

shortCondition = ta.crossunder(ta.sma(close, 1), ta.sma(close, 4))
if (shortCondition)
    strategy.entry("Short Entry", strategy.short)  // Enter short

if (longCondition)
    lastLongOrderPrice := close

if (shortCondition)
    lastShortOrderPrice := close

// Calculate stop loss and take profit based on the last executed order's price
stopLossLong = lastLongOrderPrice - 170  // 10 USDT lower than the last long order price
takeProfitLong = lastLongOrderPrice + 150  // 100 USDT higher than the last long order price
stopLossShort = lastShortOrderPrice + 170  // 10 USDT higher than the last short order price
takeProfitShort = lastShortOrderPrice - 150  // 100 USDT lower than the last short order price

// Apply stop loss and take profit to long positions
strategy.exit("Long Exit", from_entry="Long Entry", stop=stopLossLong, limit=takeProfitLong)

// Apply stop loss and take profit to short positions
strategy.exit("Short Exit", from_entry="Short Entry", stop=stopLossShort, limit=takeProfitShort)