Library "SnowdexUtils" the various function that often use when create a strategy trading.
f_backtesting_date(train_start_date, train_end_date, test_date, deploy_date) Backtesting within a specific window based on deployment and testing dates. Parameters: train_start_date (int): the start date for training the strategy. train_end_date (int): the end date for training the strategy. test_date (bool): if true, backtests within the period from `train_end_date` to the current time. deploy_date (bool): if true, the strategy backtests up to the current time. Returns: given time falls within the specified window for backtesting.
f_init_ma(ma_type, source, length) Initializes a moving average based on the specified type. Parameters: ma_type (simple string): the type of moving average (e.g., "RMA", "EMA", "SMA", "WMA"). source (float): the input series for the moving average calculation. length (simple int): the length of the moving average window. Returns: the calculated moving average value.
f_init_tp(side, entry_price, rr, sl_open_position) Calculates the target profit based on entry price, risk-reward ratio, and stop loss. The formula is `tp = entry price + (rr * (entry price - stop loss))`. Parameters: side (bool): the trading side (true for long, false for short). entry_price (float): the entry price of the position. rr (float): the risk-reward ratio. sl_open_position (float): the stop loss price for the open position. Returns: the calculated target profit value.
f_round_up(number, decimals) Rounds up a number to a specified number of decimals. Parameters: number (float) decimals (int) Returns: The rounded-up number.
f_get_pip_size() Calculates the pip size for the current instrument. Returns: Pip size adjusted for Forex instruments or 1 for others.
f_table_get_position(value) Maps a string to a table position constant. Parameters: value (string): String representing the desired position (e.g., "Top Right"). Returns: The corresponding position constant or `na` for invalid values.
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai satu perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman.
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.