Simple MA System, 4xdev.com free

by 4xdev.team in category Other at 06/01/2022
Description

Hey-ho, great traders! 

Let us introduce the cBot with Moving Averages. This cool trading tool will help you to track the crossing of two MAs and react to the price crossing of one of the MAs.

 

Features

The Simple MA system can:

  • Check the formed bars to cross two MAs, therefore avoiding false signals.
  • Monitor the current bar and current prices for crossing one of the MAs and the price.
  • Manage positions. 
  • Calculate all the risks for the entire position.
  • Remove the Stop Loss level on the opening price after overcoming a certain distance thanks to the BreakEven option. In this case, your trade won’t be a loss-making one.

Note! If the short-term MA crosses the long-term one upwards, the trading robot enters a long position. If there is a downward crossover, the EA will enter a short position.

 

Parameters

We have equipped our EA with more than 14 additional parameters. So, you can configure the cBot according to your needs! Moreover, you can change opening conditions for Buy and Sell orders using the input parameters.

Note! Try the Simple MA system on your demo account first before going live.


 

Other Products

Ichimoku Cloud System: https://ctrader.com/algos/cbots/show/2859  

PSAR Strategy: 

ADR Custom Indicator: 

Daily H/L Custom Indicator: 

BB Trading Strategy: 

 

Contact Info

Contact us via support@4xdev.com 

Check out our cozy Telegram blog for traders:https://t.me/Forexdev  

Visit our website to find more tools and programming services:https://bit.ly/3BtyUap 

Take a look at our YouTube channel:https://www.youtube.com/channel/UChsDb4Q8X2Vl5DJ7H8PzlHQ   


Try top-notch trading tools — with 4xDev.

 

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
´╗┐using cAlgo.API;
using cAlgo.API.Indicators;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Siple_MA : Robot
    {
        public enum ENUM_TP_TYPE
        {
            Fixed = 0,
            RiskRatio = 1
        }
        public enum ENUM_RISK_SOURCE
        {
            Equity = 0,
            Balance = 1
        }

        public enum ENUM_LOT_TYPE
        {
            Fixed_Lot = 0,
            Percent = 1
        }
        public enum ENUM_CROSS_TYPE
        {
            Ask_Bid = 1,
            // Ask/Bid
            Close_Price = 0
            // Close Price
        }

        public enum ENUM_SIGNAL_TYPE
        {
            MA_Cross = 0,
            // MAs cross
            Price_Touch = 1
            // Price hits First MA
        }


        #region Input Fast MA Parameters
        [Parameter("Fast MA Type", Group = "Fast MA Parameters")]
        public MovingAverageType FastType { get; set; }

        [Parameter("Fast MA Source", Group = "Fast MA Parameters")]
        public DataSeries FastSeries { get; set; }

        [Parameter("Fast MA Period", Group = "Fast MA Parameters", DefaultValue = 10)]
        public int FastPeriods { get; set; }
        #endregion

        #region Input Slow MA Parameters
        [Parameter("Slow MA Type", Group = "Slow MA Parameters")]
        public MovingAverageType SlowType { get; set; }

        [Parameter("Slow MA Source", Group = "Slow MA Parameters")]
        public DataSeries SlowSeries { get; set; }

        [Parameter("Slow MA Period", Group = "Slow MA Parameters", DefaultValue = 60)]
        public int SlowPeriods { get; set; }
        #endregion

        #region Input Trade Parameters
        [Parameter("Label", Group = "Trade Parameters", DefaultValue = "Simple MA")]
        public string Label { get; set; }

        [Parameter("Applied price", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_TYPE.Close_Price)]
        public ENUM_CROSS_TYPE priceType { get; set; }

        [Parameter("Signal Type", Group = "Trade Parameters", DefaultValue = ENUM_SIGNAL_TYPE.MA_Cross)]
        public ENUM_SIGNAL_TYPE signalType { get; set; }

        [Parameter("Take Profit type", Group = "Trade Parameters", DefaultValue = ENUM_TP_TYPE.Fixed)]
        public ENUM_TP_TYPE tpType { get; set; }

        [Parameter("Stop Loss in pips", Group = "Trade Parameters", DefaultValue = 0)]
        public double SL { get; set; }

        [Parameter("Take Profit value", Group = "Trade Parameters", DefaultValue = 0)]
        public double TP { get; set; }

        [Parameter("Close on the opposite signal", Group = "Trade Parameters", DefaultValue = true)]
        public bool oppositeClose { get; set; }

        [Parameter("Max Orders", Group = "Trade Parameters", DefaultValue = 1)]
        public int maxOrders { get; set; }

        [Parameter("Use Reverse Trade", Group = "Trade Parameters", DefaultValue = true)]
        public bool reverseTrade { get; set; }

        #endregion

        #region Input Lot Size Parameters
        [Parameter("Lot Type", Group = "Lot Size", DefaultValue = ENUM_LOT_TYPE.Fixed_Lot)]
        public ENUM_LOT_TYPE lotType { get; set; }

        [Parameter("Risk Source", Group = "Lot Size", DefaultValue = ENUM_RISK_SOURCE.Balance)]
        public ENUM_RISK_SOURCE riskSource { get; set; }

        [Parameter("Risk/Lot Value", Group = "Lot Size", DefaultValue = 0.1)]
        public double risk { get; set; }
        #endregion

        #region Input Break Even Parameters
        [Parameter("Use BreakEven", Group = "BreakEven", DefaultValue = false)]
        public bool UseBE { get; set; }
        [Parameter("BreakEven Start(pips)", Group = "BreakEven", DefaultValue = 10)]
        public double BEStart { get; set; }

        [Parameter("BreakEven Profit(pips)", Group = "BreakEven", DefaultValue = 0)]
        public double BEProfit { get; set; }
        #endregion

        private MovingAverage fastMA;
        private MovingAverage slowMA;

        protected override void OnStart()
        {
            fastMA = Indicators.MovingAverage(FastSeries, FastPeriods, FastType);
            slowMA = Indicators.MovingAverage(SlowSeries, SlowPeriods, SlowType);

            if (priceType == ENUM_CROSS_TYPE.Ask_Bid)
            {
                lastAsk = Ask;
                lastBid = Bid;
            }
            else
            {
                lastClose = Bars.ClosePrices.Last(0);
            }
            lastMA = fastMA.Result.Last(0);
            // Put your initialization logic here
        }


        double lastAsk;
        double lastBid;
        double lastClose;
        double lastMA;

        DateTime lastBar;

        protected override void OnTick()
        {
            if (UseBE)
                BreakEven();
            double ma = 0;
            // Put your core logic here
            if (lastBar != Bars.OpenTimes.Last(0))
            {
                if (signalType == ENUM_SIGNAL_TYPE.MA_Cross)
                {
                    lastBar = Bars.OpenTimes.Last(0);
                    double ma1 = fastMA.Result.Last(1);
                    double ma1prev = fastMA.Result.Last(2);
                    double ma2 = slowMA.Result.Last(1);
                    double ma2prev = slowMA.Result.Last(2);
                    int currCross = CheckCross(ma1, ma1prev, ma2, ma2prev);
                    if (currCross == 0)
                    {
                        if (oppositeClose)
                        {
                            CloseOrders(TradeType.Sell);
                        }
                        if ((CalculateOrders() < maxOrders))
                        {
                            OpenOrder(TradeType.Buy);
                        }
                    }
                    if (currCross == 1)
                    {
                        if (oppositeClose)
                        {
                            CloseOrders(TradeType.Buy);
                        }
                        if ((CalculateOrders() < maxOrders))
                        {
                            OpenOrder(TradeType.Sell);
                        }
                    }
                }
                else
                {
                    ma = fastMA.Result.Last(0);

                    double prevPrice = priceType == ENUM_CROSS_TYPE.Ask_Bid ? lastAsk : lastClose;
                    double currPrice = priceType == ENUM_CROSS_TYPE.Ask_Bid ? Ask : Bars.ClosePrices.Last(0);
                    if (currPrice >= ma && prevPrice < lastMA)
                    {
                        if (CheckOrders())
                        {
                            OpenOrder(TradeType.Buy);
                        }
                        //Open Buy
                    }
                    prevPrice = priceType == ENUM_CROSS_TYPE.Ask_Bid ? lastBid : lastClose;
                    currPrice = priceType == ENUM_CROSS_TYPE.Ask_Bid ? Bid : Bars.ClosePrices.Last(0);
                    if (currPrice <= ma && prevPrice > lastMA)
                    {
                        if (CheckOrders())
                        {
                            OpenOrder(TradeType.Sell);
                        }
                        //Open Sell
                    }
                }
            }
            lastMA = ma;
            lastAsk = Ask;
            lastBid = Bid;
            lastClose = Bars.ClosePrices.Last(0);
        }

        bool CheckOrders()
        {
            if (Positions.Find(Label, Symbol) != null)
                return false;
            return true;
        }

        int CalculateOrders()
        {
            return Positions.FindAll(Label, Symbol).Length;
        }

        void CloseOrders(TradeType type)
        {
            if (reverseTrade)
                type = type == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            foreach (var pos in Positions.FindAll(Label, Symbol, type))
            {
                ClosePosition(pos);
            }
        }

        void OpenOrder(TradeType type)
        {
            if (reverseTrade)
                type = type == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            double op;
            double tp = tpType == ENUM_TP_TYPE.Fixed ? TP : SL * TP;
            double sl;

            double source = riskSource == ENUM_RISK_SOURCE.Balance ? Account.Balance : Account.Equity;

            double volumeInUnits = 0;
            if (lotType == ENUM_LOT_TYPE.Fixed_Lot)
                volumeInUnits = Symbol.QuantityToVolumeInUnits(risk);
            else
                volumeInUnits = CalculateVolume(SL, risk, source);

            if (volumeInUnits == -1)
                return;
            ExecuteMarketOrder(type, SymbolName, volumeInUnits, Label, SL, TP);
        }

        private double CalculateVolume(double stopLossPips, double riskSize, double source)
        {
            // source = Account.Balance or Account.Equity
            double riskPerTrade = source * riskSize / 100;
            double totalPips = stopLossPips;

            double _volume;
            double exactVolume = riskPerTrade / (Symbol.PipValue * totalPips);
            if (exactVolume >= Symbol.VolumeInUnitsMin)
            {
                _volume = Symbol.NormalizeVolumeInUnits(exactVolume);
            }
            else
            {
                _volume = -1;
                Print("Not enough Equity to place minimum trade, exactVolume " + exactVolume + " is not >= Symbol.VolumeInUnitsMin " + Symbol.VolumeInUnitsMin);
            }
            return _volume;
        }

        int CheckCross(double v1, double v1prev, double v2, double v2prev)
        {
            if (v1prev < v2prev && v1 > v2)
                return 0;
            if (v1prev > v2prev && v1 < v2)
                return 1;
            return -1;
        }
        private void BreakEven()
        {
            if (!UseBE)
                return;

            foreach (var pos in Positions.FindAll(Label, SymbolName))
            {
                if (pos.TradeType == TradeType.Buy)
                {
                    if (Symbol.Ask >= pos.EntryPrice + BEStart * Symbol.PipSize && (pos.StopLoss < pos.EntryPrice + BEProfit * Symbol.PipSize || pos.StopLoss == null))
                    {
                        ModifyPosition(pos, pos.EntryPrice + BEProfit * Symbol.PipSize, pos.TakeProfit);
                    }
                }
                if (pos.TradeType == TradeType.Sell)
                {
                    if (Symbol.Bid <= pos.EntryPrice - BEStart * Symbol.PipSize && (pos.StopLoss > pos.EntryPrice - BEProfit * Symbol.PipSize || pos.StopLoss == null))
                    {
                        ModifyPosition(pos, pos.EntryPrice + BEProfit * Symbol.PipSize, pos.TakeProfit);
                    }
                }
            }
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
Comments

kennedystewart341893 - January 07, 2022 @ 06:26

This is really a pretty good and detailed document for me to refer to this limited knowledge of mine. And if you want to try to relax as well as train your own reflexes, then the game Drift Boss is the best choice for you. Once again, thank you very much to the author ^^

junaidraz278 - January 23, 2022 @ 20:50

This Trading Strategy is awesome. My friend refer this and tried now loving it. If you want to be a successful trader you need to apply this must.

henrylucas2k20 - January 24, 2022 @ 09:55

Great tool as usual I have ever used. For success trading journey you should take a look at this MA system. Thanks for 4xdev team for their great efforts.  

shamsulzoha5 - January 25, 2022 @ 00:42

All in all a good moving average system. The availability of the code allows me to modify it to my wishes. Far better than the normal moving averages. Recommended.

satib62685 - January 26, 2022 @ 12:25

A basic machine works against a single load force with a single applied force. the work done on the load is equivalent to the work done by the applied force, even when friction losses are taken into account. the machine can raise the output force on kanye west black leather jacket in the load's distance travelled. the mechanical advantage is defined as the ratio of output to applied force.

LeonardoBaliza - February 10, 2022 @ 00:13

Would it be possible to add a third average? The function of this third average would be to block sell or buy trades when it was above or below the average. Example: Do not open buy trades if it is above the third average.

saladine123 - March 30, 2022 @ 18:05

Hi,

I have just started to use your Cbot Simple MA cross and really appreciate the effort provided. I am however having an issue with MA Cross direction and execution. You mentioned in the description that if fast MA crosses up over slow MA, a buy signal should be triggered. Conversley, a fast MA crossing down Slow MA produces a sell order. However, on my system, the opposite is happening. A cross up gives sell signal and cross down gives buy signal.

Perhaps you can point me in the right direction in order to correct this?

Thanking you in advance!!

ciaraveum008 - June 28, 2022 @ 09:19

The vivified accounts which I am making at last are more visionary and striking when seemed conceivable going from the past ones. Click https://www.sentencecorrector.biz/become-the-expert-sentence-fixer-follow-the-guidelines-to-error-free-sentences/ to know how to accomplish this work. It's beginning and end next to's an eating up possible delayed consequence of following your evaluations.

ciaraveum008 - June 28, 2022 @ 09:27

Grateful for giving this report on your evident music plan. Being a temperamental admirer of your singing, Just gander at https://www.grammarcheckeronline.org/how-to-correct-my-grammar-online/ I want to perceive that you will like it. I everything saw at keep as a sound level of control for the presence of your new music tracks.

ciaraveum008 - August 25, 2022 @ 14:35

I was watching out for your melodic show for really the focal event when that is the clarification I was missing and remained mindful of. You can visit check sentence grammar for additional encounters as for embellishment. A particularly huge store of mistaking for me when the dependable program started.

ciaraveum008 - August 25, 2022 @ 14:37

It was genuinely puzzling and talking with to look at in any way at all of the exercises of Qatar ExxonMobil. Really take a gander at this www.paragraphchecker.com/check-my-paragraph-for-errors/ to get tremendous assistance with it. I especially visited Qatar to invite this festival.

deleonandrews4942917 - November 03, 2022 @ 09:41

These codes give me a headache, every time I learn to code I feel sleepy and have to play diggy to relieve stress, do you guys feel like me.

4xdev.team - December 05, 2022 @ 14:33

@LeonardoBaliza, we can add a third average. Please write to our support (support@4xdev.com) to clarify the cost of such a modification.

4xdev.team - December 05, 2022 @ 14:38

@saladine123 most likely, the Use Reverse Trade parameter is enabled. Just turn it off and everything will be fine.

0