指定

import pandas as pd
import numpy as np

def generate_signals(data):
    signals = pd.DataFrame(index=data.index)
    signals['price'] = data['Close']
    
    # Calculate moving averages
    signals['short_ma'] = data['Close'].rolling(window=20, min_periods=1).mean()
    signals['long_ma'] = data['Close'].rolling(window=50, min_periods=1).mean()
    
    # Generate buy signals
    signals['buy_signal'] = np.where(signals['short_ma'] > signals['long_ma'], 1, 0)
    
    # Generate sell signals
    signals['sell_signal'] = np.where(signals['short_ma'] < signals['long_ma'], -1, 0)
    
    return signals

def backtest_strategy(signals, initial_capital=10000):
    positions = pd.DataFrame(index=signals.index).fillna(0.0)
    positions['asset'] = 1000 * signals['buy_signal'] + -1000 * signals['sell_signal']
    
    # Calculate portfolio value
    portfolio = positions.multiply(signals['price'], axis=0)
    pos_diff = positions.diff()
    portfolio['holdings'] = (positions.multiply(signals['price'], axis=0)).sum(axis=1)
    portfolio['cash'] = initial_capital - (pos_diff.multiply(signals['price'], axis=0)).sum(axis=1).cumsum()
    portfolio['total'] = portfolio['cash'] + portfolio['holdings']
    portfolio['returns'] = portfolio['total'].pct_change()
    
    return portfolio

# Example usage:
# Assuming 'data' is a DataFrame containing historical price data with 'Date' as index and 'Close' as a column
# signals = generate_signals(data)
# portfolio = backtest_strategy(signals)
# print(portfolio.tail())

反馈

1
开发者 1
等级
(278)
项目
373
72%
仲裁
19
32% / 47%
逾期
14
4%
空闲
发布者: 14 代码
2
开发者 2
等级
(250)
项目
460
26%
仲裁
140
20% / 59%
逾期
100
22%
工作中
3
开发者 3
等级
(296)
项目
475
40%
仲裁
105
40% / 24%
逾期
80
17%
繁忙
发布者: 2 代码
相似订单
==== GENERAL SETTINGS ==== Buy trades = true Sell trades = true Upper Band period = 20 Lower Band period = 10 Timeframe = 1 Hour Next signal bars= 5 Order Comment = Donchian Channel EA Magic number = 123 Maximum allowed spread = 20 Maximum allowed slippage = 20 ====TRADE SETTINGS ==== Trade volume = VOLUME_FIXED / VOLUME_PERCENT Fixed Lots = 0.01 Risk percent of Balance = 5 TP Points (0 to No TP) = 100 SL Points (0
Looking for a Scalping bot, it Must be on MT5, Takes many trades , Any strategy is fine, Has to be profitable last 3 months backtest, Send me a demo license file to check it's performance
I hope to acquire a profitable and existing expert advisor (EA) from the gold market, with complete source code, to add to our client portfolio. you can WECHAT: Faca7898 Please note EA when adding friends. It should be clarified that this does not require you to formulate or design new strategies. If you already have a verified, consistent, and production-ready EA, I am willing to purchase it immediately and engage
I’m looking for an experienced developer to help build a trading bot for Polymarket , focused on short-term crypto prediction markets (e.g. 5–15 minute intervals). The strategy is fully rule-based and operates on binary outcome markets (YES/NO shares). The bot should be able to: monitor live market prices and probabilities, execute trades based on predefined conditions, manage positions dynamically before market
Eu preciso disso. A linha central do TMA (17,5,1.5) será a principal referência. Outra linha de média móvel (AVG) de 3 períodos decrescentes 2. As ordens serão as seguintes: abaixo, somente compra de TMA; acima, somente venda de TMA. O sinal de entrada será o seguinte: se o preço estiver acima da Média Móvel Tarifária (TMA), será apenas para venda; quando o preço se mantiver abaixo da Média Móvel Tarifária (AVG)
Hola, estoy buscando un desarrollador MQL5 con experiencia real en trading algorítmico. Necesito un EA para XAUUSD con: Control de Drawdown filtro de mercado (tendencia vs rango) gestión de riesgo dinámica optimización para sesiones específicas Antes de avanzar quisiera saber: ¿Qué experiencia tienes con EAs en MT5? ¿Has trabajado con estrategias de oro (XAUUSD)? ¿Cómo gestionas el drawdown en un bot? ¿Puedes mostrar
Double ma 30+ USD
Create an EA on moving averages. The EA will open a trade when the price is above the averages. It will open another when it is below the averages. Ability to work on any timeframe. Ability to use a news filter and a martingale...or to work on a grid
There is a programming god without EA here. I want to find someone to make an EA to operate gold and silver. There is a model, but it can't run. So I want to find someone to make professional improvements to make my EA run. If you are interested, you can WECHAT: 15113958263. Please note EA when adding friends
Iam seeking for a good trade robot/indicator debugging developer to finalize and close profits for me,in both my exneas blocker and MT5,for expert advisor for trading both gold xausd and sliver xagusd,l really want a perfect robot that can herence and risk management principles,not to leave out am a beginner
I am looking for non-repainting indicator to run in all sessions for scalping gold , happy to discuss if you have developed such indicators which can show profit and stop loss levels

项目信息

预算
30 - 50 USD
截止日期
 1  14 天