Specification

# Import necessary libraries
import pandas as pd

# Define parameters
stop_loss_percentage = 0.02  # Set stop loss percentage (2% in this example)
take_profit_percentage = 0.05  # Set take profit percentage (5% in this example)

# Read historical price data
df = pd.read_csv("historical_data.csv")  # Replace with your historical data file or API integration

# Calculate moving averages
df['SMA_50'] = df['Close'].rolling(window=50).mean()
df['SMA_200'] = df['Close'].rolling(window=200).mean()

# Initialize variables
position = None
entry_price = 0.0

# Start trading loop
for i in range(200, len(df)):
    current_price = df['Close'].iloc[i]

    # Check for entry conditions
    if position is None and df['SMA_50'].iloc[i] > df['SMA_200'].iloc[i]:
        position = 'long'
        entry_price = current_price
        print(f"Enter long position at {entry_price}")

    elif position is None and df['SMA_50'].iloc[i] < df['SMA_200'].iloc[i]:
        position = 'short'
        entry_price = current_price
        print(f"Enter short position at {entry_price}")

    # Check for exit conditions
    if position == 'long' and current_price >= (1 + take_profit_percentage) * entry_price:
        position = None
        exit_price = current_price
        print(f"Exit long position at {exit_price}")
        profit = exit_price - entry_price
        print(f"Profit: {profit}")

    elif position == 'long' and current_price <= (1 - stop_loss_percentage) * entry_price:
        position = None
        exit_price = current_price
        print(f"Exit long position at {exit_price}")
        loss = exit_price - entry_price
        print(f"Loss: {loss}")

    elif position == 'short' and current_price <= (1 - take_profit_percentage) * entry_price:
        position = None
        exit_price = current_price
        print(f"Exit short position at {exit_price}")
        profit = entry_price - exit_price
        print(f"Profit: {profit}")

    elif position == 'short' and current_price >= (1 + stop_loss_percentage) * entry_price:
        position = None
        exit_price = current_price
        print(f"Exit short position at {exit_price}")
        loss = entry_price - exit_price
        print(f"Loss: {loss}")

Responded

1
Developer 1
Rating
(2)
Projects
2
0%
Arbitration
1
0% / 0%
Overdue
2
100%
Free
2
Developer 2
Rating
(42)
Projects
62
8%
Arbitration
12
58% / 42%
Overdue
1
2%
Free
3
Developer 3
Rating
(35)
Projects
50
42%
Arbitration
3
33% / 33%
Overdue
4
8%
Free
4
Developer 4
Rating
(6)
Projects
10
50%
Arbitration
6
17% / 50%
Overdue
3
30%
Working
5
Developer 5
Rating
(5)
Projects
4
50%
Arbitration
4
0% / 75%
Overdue
0
Free
Similar orders
Hello developers here, I need a professional developer that can help me to develop an mt5 trading bot that works according to my strategy, I will be sharing my strategy in the inbox, Let me know if you can develop it, I will be waiting for your response
I am looking developer who can code pocket option data and insert in to costume candle Heikin in trading view. I want to trade otc as such its up to developer to get pocket option data stream and then make costume candle Heikin inside of trading view. Their will be a drop down menu in setting that will use to pick the otc pair. Developer must have way to chat on mobile app also. We will use
I need an EA in based of this indicator. It have buffers. The owner told me it..., So I need an expert who can do this I will attached the file right now
Robo382 30+ USD
OLA /// a minha estratégia de operação automatizada seria assim onda de impulsao com correcao no nivel de 38,2 % com stop 14.6% ou seja fibo de 0% ao 100%
HI, I'm looking for an experienced person who can add buy/sell indications and Alerts on existing Pinescript along with little modification of the script and the script should connect to MT5 platform using pineconnector MT5 platform should excute trade instantly as based on the alerts/indications on tradingview script
HI, I'm looking for an experienced person who can add buy/sell indications/Alerts on existing Pinescript code along with little modification of the script and the script should connect to MT5 platform using pineconnector MT5 platform should execute trade instantly as based on the alerts/indications on tradingview script
Hey, im looking for a person who can create an my very own version of pineconnector, which should have all the option of pineconnector and it should be user-friendly without any complications
HI, I'm looking for an experienced person who can add buy/sell indications and Alerts on existing Pinescript along with little modification of the script and the script should connect to MT5 platform using pineconnector MT5 platform should excute trade instantly as based on the alerts/indications on tradingview script
I want the trade to trigger anytime it sees the opportunity on all time frames, sl tp should be automated and all trades should be trigger anytime on cpi news and etc
I need you to convert my tradingview pinescript to mt4, I have just $10 for it now, But i am going to give you more work later on cause i still have more work i am going to need you to work on for me, and i will be paying with crypto, Thank You

Project information

Budget
30+ USD
For the developer
27 USD
Deadline
from 1 to 2 day(s)