Category Trend  Published on 18/05/2024

XAUUSD 7m account size 25000 USD 1:30 free

Description

Description: the bot is for free

if you really appreciate my hard work please drop any cent if you can in my PayPal: https://www.paypal.me/shapoorpopalzai, otherwise enjoy the bot and have fun ;-)

I have also removed the trail period, it is unlimited!!!

Note: check the bot in optimizer and choose the best as per your requirements. below is the example of the parameter which I use.

The optimizer give  you the best time frame and parameters to trade.

You can choose with other Items like BTCUSD, EURUSD..etc

This C# code is for a cAlgo robot designed to execute trades based on a moving average crossover strategy. Here's a breakdown of its key components:

Parameters:

  1. FastMAPeriod: Specifies the period for the fast moving average.
  2. SlowMAPeriod: Specifies the period for the slow moving average.
  3. RiskPercentage: Sets the risk percentage per trade.
  4. ATRPeriod: Sets the period for calculating the Average True Range (ATR).
  5. TakeProfitATRMultiplier: Multiplier for calculating the take profit level based on ATR.
  6. StopLossPips: Sets the initial stop loss in pips.
  7. AdditionalStopLossPips: Sets an additional stop loss level in pips.
  8. MaxStopLossThreshold: Sets the maximum stop loss threshold in pips.
  9. MaxLotSize: Specifies the maximum lot size for a trade.
  10. MaxEquityDrawdown: Sets the maximum equity drawdown allowed as a percentage.
  11. AllowMultipleOrders: Determines whether multiple orders are allowed to be opened simultaneously.

Initialization:

  • The robot initializes its moving averages (fastMA and slowMA) and sets initial values for variables like maxLotSize, maxEquityDrawdown, and peakEquity.
  • It checks for an expiry date and stops trading if the current date exceeds it.

OnTick():

  • This method is called on every tick (price update).
  • It calculates the drawdown percentage based on peak equity and pauses trading if the drawdown exceeds a predefined threshold.

OnBar():

  • This method is called on every new bar (candlestick).
  • It checks for open positions or pending orders and exits if any exist.
  • Calculates risk amount, ATR, and stop loss distances.
  • Executes buy or sell orders based on moving average crossover, with appropriate stop loss and take profit levels.
  • Pauses trading if stop loss exceeds the maximum threshold.

Helper Methods:

  • IsBullishMarket() and IsBearishMarket(): Determine market sentiment based on open and close prices.
  • CalculateATR(): Calculates the Average True Range.

PauseTrading():

  • Method to pause trading when maximum drawdown is reached.

This robot aims to automate trading decisions based on a simple moving average crossover strategy while incorporating risk management techniques like stop loss and maximum drawdown control.


using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class XAUSD5mctrader10000bot : Robot
    {
        [Parameter("Fast MA Period", DefaultValue = 10)]
        public int FastMAPeriod { get; set; }

        [Parameter("Slow MA Period", DefaultValue = 30)]
        public int SlowMAPeriod { get; set; }

        [Parameter("Risk Percentage", DefaultValue = 0.04, MinValue = 0.01, MaxValue = 0.04)]
        public double RiskPercentage { get; set; }

        [Parameter("ATR Period", DefaultValue = 14)]
        public int ATRPeriod { get; set; }

        [Parameter("Take Profit ATR Multiplier", DefaultValue = 1.0, MinValue = 0.5, MaxValue = 10)]
        public double TakeProfitATRMultiplier { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 75)]
        public int StopLossPips { get; set; }

        [Parameter("Max Lot Size", DefaultValue = 2.0, MinValue = 0.01)]
        public double MaxLotSize { get; set; }

        [Parameter("Max Equity Drawdown", DefaultValue = 0.04, MinValue = 0.01, MaxValue = 0.5)]
        public double MaxEquityDrawdown { get; set; }

        [Parameter("Allow Multiple Trades", DefaultValue = true)]
        public bool AllowMultipleTradesEnabled { get; set; }

        private MovingAverage fastMA;
        private MovingAverage slowMA;
        private double peakEquity = 0;
        private bool canTrade = true; // Flag to control multiple trades

        protected override void OnStart()
        {
            try
            {
                fastMA = Indicators.MovingAverage(Bars.ClosePrices, FastMAPeriod, MovingAverageType.Simple);
                slowMA = Indicators.MovingAverage(Bars.ClosePrices, SlowMAPeriod, MovingAverageType.Simple);

                peakEquity = Account.Equity;
            }
            catch (Exception ex)
            {
                Print("Error in OnStart: " + ex.Message);
                LogError("OnStart", ex);
            }
        }

        protected override void OnTick()
        {
            try
            {
                // Update peak equity
                peakEquity = Math.Max(peakEquity, Account.Equity);

                // Calculate drawdown as a percentage of peak equity
                double equityDrawdown = (peakEquity - Account.Equity) / peakEquity;

                // Check if drawdown exceeds the equity threshold
                if (equityDrawdown > MaxEquityDrawdown)
                {
                    // Take action to mitigate drawdown (e.g., pause trading)
                    PauseTrading();
                }
            }
            catch (Exception ex)
            {
                Print("Error in OnTick: " + ex.Message);
                LogError("OnTick", ex);
            }
        }

        protected override void OnBar()
        {
            try
            {
                // Check if there are any open positions or pending orders
                if (!AllowMultipleTradesEnabled && (!canTrade || Positions.Count > 0 || PendingOrders.Count > 0))
                {
                    Print("There are open positions or pending orders. Cannot open new trades.");
                    return;
                }

                double riskAmount = Account.Balance * RiskPercentage;
                double atr = CalculateATR(ATRPeriod);

                double takeProfitPips = atr * TakeProfitATRMultiplier;

                double volumeInUnits = Symbol.QuantityToVolumeInUnits(Math.Min(riskAmount / (StopLossPips * Symbol.PipSize * Symbol.LotSize), MaxLotSize));

                // Moving Average Crossover Strategy
                if (fastMA.Result.Last(1) > slowMA.Result.Last(1) && fastMA.Result.Last(2) <= slowMA.Result.Last(2))
                {
                    if (IsBullishMarket())
                    {
                        double takeProfitPrice = Symbol.Ask + (takeProfitPips * Symbol.PipSize);
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "Buy Order", null, StopLossPips, takeProfitPrice.ToString());
                        canTrade = AllowMultipleTradesEnabled; // Allow multiple trades if set to true
                    }
                }
                else if (fastMA.Result.Last(1) < slowMA.Result.Last(1) && fastMA.Result.Last(2) >= slowMA.Result.Last(2))
                {
                    if (IsBearishMarket())
                    {
                        double takeProfitPrice = Symbol.Bid - (takeProfitPips * Symbol.PipSize);
                        ExecuteMarketOrder(TradeType.Sell, SymbolName, volumeInUnits, "Sell Order", null, StopLossPips, takeProfitPrice.ToString());
                        canTrade = AllowMultipleTradesEnabled; // Allow multiple trades if set to true
                    }
                }
            }
            catch (Exception ex)
            {
                Print("Error in OnBar: " + ex.Message);
                LogError("OnBar", ex);
            }
        }

        private bool IsBullishMarket()
        {
            return Bars.OpenPrices.Last(1) < Bars.ClosePrices.Last(1);
        }

        private bool IsBearishMarket()
        {
            return Bars.OpenPrices.Last(1) > Bars.ClosePrices.Last(1);
        }

        private double CalculateATR(int period)
        {
            try
            {
                double trSum = 0;
                for (int i = 1; i <= period; i++)
                {
                    double tr = Math.Max(Bars.HighPrices[i] - Bars.LowPrices[i], Math.Max(Math.Abs(Bars.HighPrices[i] - Bars.ClosePrices[i - 1]), Math.Abs(Bars.LowPrices[i] - Bars.ClosePrices[i - 1])));
                    trSum += tr;
                }
                return trSum / period;
            }
            catch (Exception ex)
            {
                Print("Error in CalculateATR: " + ex.Message);
                LogError("CalculateATR", ex);
                return 0;
            }
        }

        private void PauseTrading()
        {
            // Implement logic to pause trading (e.g., set a flag to stop placing new trades)
            // You might also consider closing existing positions or reducing position sizes
            Print("Maximum Drawdown is exceeded. Pausing the trading...");
            canTrade = false; // Prevent further trades
        }

        private void LogError(string method, Exception ex)
        {
            // Implement logging to an external file or service for better monitoring
            Print($"{method} error: {ex.Message}");
        }
    }
}


SH
shapor33

Joined on 08.04.2024 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Arian Bot XAUUSD 5m BTCUSD 5m 1month trail bot.algo
  • Rating: 3.33
  • Installs: 440
  • Modified: 18/05/2024 22:12
Comments
Log in to add a comment.
AR
artursgalaida · 6 months ago

Hello, the stop loss doesn't work?

SH
shapor33 · 6 months ago

I have put it for free you can download it

CA
catinasandrei27 · 6 months ago

Cannot download, its still set as paid algo, maybe set is as free? Thank you

AK
AK2620 · 6 months ago

Unable to download

SH
shapor33 · 7 months ago

Man I am not a good seller, you can use it for free, I have removed the expiry date

MZ
mzmughal · 7 months ago

is it trail version??