Cardano Trading Strategy Sample Code

A momemtum based strategy for trading cardano
The short URL of the present article is: https://netbizint.com.au/cardano-trading-code

Below is the complete trading code for the “Cardano Triple Cross” strategy, written in Pine Script. This code can be directly used on the TradingView platform, which is one of the most popular charting tools for cryptocurrency traders.

This script translates the entire strategy—including the triple EMA crossover, the confirmation filters (MACD, RSI, ADX), and the two-part risk management plan—into an automated strategy that you can backtest and apply to a chart.

How to Use This Code in TradingView

  1. Open a Cardano Chart: Go to(https://www.tradingview.com/) and open a chart for ADAUSD (or your preferred Cardano pair) on the 4-hour (240-minute) timeframe.
  2. Open Pine Editor: At the bottom of the chart, click on the “Pine Editor” tab.
  3. Paste the Code: Delete any existing template code in the editor and paste the complete script provided below.
  4. Add to Chart: Click the “Add to chart” button.
  5. See the Results: The strategy’s signals (buy/sell arrows) will appear on your chart. In the “Strategy Tester” tab at the bottom, you can see the backtested performance, including net profit, number of trades, and win rate.
  6. Adjust Settings (Optional): You can click the “Settings” gear icon on the strategy in the top-left of your chart to change the indicator periods or risk management parameters to suit your trading style.

Pine Script Code for Cardano Triple Cross Strategy

Pine Script

// © 2025 Award-Winning Writer
// This script implements the "Cardano Triple Cross" strategy, a comprehensive trend-following system.
// It uses a triple EMA crossover for the primary signal, confirmed by MACD, RSI, and ADX filters.
// Risk management includes a volatility-based stop-loss (ATR) and a two-part take-profit system.

//@version=5
strategy("Cardano Triple Cross Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.1)

// =================================================================================
//                           1. USER-CONFIGURABLE INPUTS
// =================================================================================

// --- Moving Average Settings ---
ma_group = "Moving Average Settings"
short_ema_len = input.int(9, "Short EMA Period", group=ma_group)
medium_ema_len = input.int(21, "Medium EMA Period", group=ma_group)
long_ema_len = input.int(55, "Long EMA Period", group=ma_group)

// --- Confirmation Indicator Settings ---
indicator_group = "Confirmation Indicator Settings"
rsi_len = input.int(14, "RSI Period", group=indicator_group)
adx_len = input.int(14, "ADX Period", group=indicator_group)
macd_fast_len = input.int(12, "MACD Fast Period", group=indicator_group)
macd_slow_len = input.int(26, "MACD Slow Period", group=indicator_group)
macd_signal_len = input.int(9, "MACD Signal Period", group=indicator_group)

// --- Filter Levels ---
filter_group = "Filter Levels"
rsi_filter_level = input.float(50.0, "RSI Centerline", group=filter_group)
adx_filter_level = input.float(25.0, "ADX Trend Strength Level", group=filter_group)

// --- Risk Management Settings ---
risk_group = "Risk Management Settings"
atr_len = input.int(14, "ATR Period", group=risk_group)
atr_multiplier = input.float(2.0, "ATR Stop Loss Multiplier", group=risk_group)
risk_reward_ratio = input.float(2.0, "Take Profit 1 Risk/Reward Ratio", group=risk_group)

// =================================================================================
//                           2. INDICATOR CALCULATIONS
// =================================================================================

// --- Moving Averages ---
ema_short = ta.ema(close, short_ema_len)
ema_medium = ta.ema(close, medium_ema_len)
ema_long = ta.ema(close, long_ema_len)

// --- Confirmation Indicators ---
rsi = ta.rsi(close, rsi_len)
[macd_line, macd_signal, _] = ta.macd(close, macd_fast_len, macd_slow_len, macd_signal_len)
[di_plus, di_minus, adx] = ta.dmi(high, low, close, adx_len)

// --- Risk Management Indicator ---
atr = ta.atr(atr_len)

// --- Plot Indicators on Chart for Visualization ---
plot(ema_short, "Short EMA", color=color.new(color.green, 0), linewidth=2)
plot(ema_medium, "Medium EMA", color=color.new(color.red, 0), linewidth=2)
plot(ema_long, "Long EMA", color=color.new(color.blue, 0), linewidth=3)

// =================================================================================
//                           3. TRADING LOGIC & CONDITIONS
// =================================================================================

// --- Define Crossover Events ---
bullish_crossover = ta.crossover(ema_short, ema_medium)
bearish_crossover = ta.crossunder(ema_short, ema_medium)

// --- Define Trend Conditions ---
is_uptrend = ema_medium > ema_long and close > ema_long
is_downtrend = ema_medium < ema_long and close < ema_long

// --- Define Confirmation Filter Conditions ---
rsi_bullish_confirm = rsi > rsi_filter_level
rsi_bearish_confirm = rsi < rsi_filter_level
macd_bullish_confirm = macd_line > macd_signal
macd_bearish_confirm = macd_line < macd_signal
adx_trend_confirm = adx > adx_filter_level

// --- Combine All Conditions for Final Entry Signals ---
long_condition = is_uptrend and bullish_crossover and rsi_bullish_confirm and macd_bullish_confirm and adx_trend_confirm
short_condition = is_downtrend and bearish_crossover and rsi_bearish_confirm and macd_bearish_confirm and adx_trend_confirm

// =================================================================================
//                           4. STRATEGY EXECUTION & RISK MANAGEMENT
// =================================================================================

// --- Calculate Stop Loss and Take Profit Levels ---
long_stop_price = close - (atr * atr_multiplier)
long_tp1_price = close + ((close - long_stop_price) * risk_reward_ratio)

short_stop_price = close + (atr * atr_multiplier)
short_tp1_price = close - ((short_stop_price - close) * risk_reward_ratio)

// --- Execute Long (Buy) Trade ---
if (long_condition)
    strategy.entry("Long", strategy.long)
    // Set the initial stop loss and the first take profit for 50% of the position
    strategy.exit("Long TP1/SL", from_entry="Long", qty_percent=50, limit=long_tp1_price, stop=long_stop_price)
    // Set the trailing stop for the remaining 50% of the position
    strategy.exit("Long Trailing SL", from_entry="Long", stop=ema_medium)

// --- Execute Short (Sell) Trade ---
if (short_condition)
    strategy.entry("Short", strategy.short)
    // Set the initial stop loss and the first take profit for 50% of the position
    strategy.exit("Short TP1/SL", from_entry="Short", qty_percent=50, limit=short_tp1_price, stop=short_stop_price)
    // Set the trailing stop for the remaining 50% of the position
    strategy.exit("Short Trailing SL", from_entry="Short", stop=ema_medium)

// --- Plot Buy/Sell Signals on Chart ---
plotshape(long_condition, "Buy Signal", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
plotshape(short_condition, "Sell Signal", shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)


Explanation of the Code’s Logic

  • Section 1: Inputs: This section defines all the variables that you can easily change from the strategy’s settings menu on your chart. This allows you to experiment with different EMA periods (e.g., for day trading vs. swing trading), RSI levels, or risk parameters without having to edit the code itself.  
  • Section 2: Indicator Calculations: The script calculates the values for the three EMAs, the RSI, the MACD, the ADX, and the ATR for each candle on the chart. These calculations are the foundation for the trading logic.
  • Section 3: Trading Logic: This is the core of the strategy.
    • It first identifies the primary signal: the crossover of the short-term EMA and the medium-term EMA (bullish_crossover, bearish_crossover).
    • It then checks the trend filter (are the faster EMAs above/below the long-term EMA?).
    • Finally, it checks all the confirmation filters (RSI, MACD, ADX) to ensure they align with the trade direction.
    • A final long_condition or short_condition is only true if the primary signal and all confirmation filters are met simultaneously. This enforces the principle of confluence.  
  • Section 4: Strategy Execution:
    • When a valid long_condition or short_condition is detected, the strategy.entry() function opens a trade.
    • The strategy.exit() function is used to manage the trade with the two-part exit plan:
      1. The first strategy.exit() call sets the initial stop-loss (based on ATR) and the first take-profit target (based on the risk/reward ratio). It is set to close qty_percent=50, meaning it will only close half of the position.  
      2. The second strategy.exit() call manages the remaining 50% of the position. It uses the medium-term EMA (ema_medium) as a dynamic trailing stop-loss, allowing the trade to capture the majority of the trend.  
  • Plotting: The plot() functions draw the moving averages on your chart, and the plotshape() functions draw the green “Buy” and red “Sell” arrows, giving you clear visual cues for each valid trading signal.

Disclaimer: This script is provided for educational purposes only and is not financial advice. Trading cryptocurrencies involves significant risk, and past performance is not indicative of future results. Always conduct thorough backtesting and risk assessment before deploying any automated strategy with real capital. Sources and related content

How To Use Moving Averages – Moving Average Trading 101 – Tradeciety

Tradeciety logo featuring a stylized green and blue bird, representing Forex trading and financial strategy.

tradeciety.com/how-to-use-moving-averages

What Is A Triple Moving Average Crossover and How to Use Them? – PrimeXBT

Source icon

primexbt.com/for-traders/what-is-a-triple-moving-average-crossover

The Triple Moving Average Crossover Strategy (With Examples)

Source icon

howtotrade.com/tradi

Tags:

No responses yet

Leave a Reply

Latest Comments

No comments to show.