hamirady60
hamirady60's avatar

Info

Username:hamirady60
Name:hamirady60
Member since: 25 Apr 2022

About

None

Signature

None

Last Algorithm Comments

@Gann Hilo:  26 Apr 2022, 20:11


Not exactly, I want the position to close after the price crosses the 10 gann Let me put it that way Opening position: Passing both gann 10 and 100   close position: Cross the gun 10

Last Forum Posts

@martinagle:  14 Oct 2022, 15:00


Hi help me please!

 I want to add the martingale method to this robot
And I also want to not double the volume after 3 more losing.

Thank you.

using System;
using System.Linq;
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 FractalsSample : Robot
    {
        private double _volumeInUnits;
        private RelativeStrengthIndex _rsi;
            
        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Volume (Lots)", DefaultValue = 0.01)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 0)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 0)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "X")]
        public string Label { get; set; }

 

        public Position[] BotPositions
        {
            get { return Positions.FindAll(Label); }
        }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
          _rsi = Indicators.RelativeStrengthIndex(SourceSeries, 14);
             
        }

        protected override void OnBar()
        {

            var cBotPositions = Positions.FindAll(Label);

 

            if (_rsi.Result.LastValue  < 30)
            {
                ClosePositions(TradeType.Sell); 
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
            }

            else if (_rsi.Result.LastValue  > 70)
            {
                ClosePositions(TradeType.Buy);
            
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
            }
        }


        private void ClosePositions(TradeType tradeType)
        {

            foreach (var position in BotPositions)
            { 
                if (position.TradeType != tradeType)
                    continue;
                ClosePosition(position);
            }
        }



    }
}
 

@Close position after 5 bar passes:  20 Sep 2022, 09:27


Hello
I need a method to close the position only if there are least 5 bars after opening the position.
It means should be at least 5 bars between opening and closing a position.

Thank you very much

@Robot not running:  09 Jun 2022, 21:13


Hello
I wrote this code in version (4.2.10) of C Trader and it worked well, but when it works on version (4.1) that my broker has and my real account is in it , it does not work

please guide me

And If the problem is because the update version has arrived, will there be the same problem for the next time the new update comes?

I apologize for the poor English I know

thank you

.

.

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

namespace cAlgo.RobotsKO
{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class FractalsSample37 : Robot
    {
        private double _volumeInUnits;
        private Fractals _fractals;

        [Parameter("Source")]
        private DataSeries SourceSeries { get; set; }

        [Parameter("Max Spread", DefaultValue = 2, MinValue = 0, MaxValue = 300)]
        public double MaxSpread { get; set; }

        [Parameter("Volume (Lots)", DefaultValue = 0.01)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 20)]
        private double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 60)]
        private double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "Sample")]
        public string Label { get; set; }


        private RelativeStrengthIndex _rsi;
        private ExponentialMovingAverage _ema17rsi;

        public Position[] BotPositions
        {
            get { return Positions.FindAll(Label); }
        }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _fractals = Indicators.Fractals(5);
            _rsi = Indicators.RelativeStrengthIndex(SourceSeries, 14);
            _ema17rsi = Indicators.ExponentialMovingAverage(_rsi.Result, 14);


        }

        protected override void OnBar()
        {

            var cBotPositions = Positions.FindAll(Label);

            ///////////////////////////////////////////////////////////////////////////////////////////

            if (_fractals.UpFractal.LastValue < Bars.ClosePrices.Last(1))
            {
                ClosePositions(TradeType.Sell);
                if (cBotPositions.Length == 0 && (_ema17rsi.Result.LastValue < (_rsi.Result.LastValue)) && Symbol.Spread < MaxSpread * Symbol.PipSize)
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
            }

            else if (_fractals.DownFractal.LastValue > Bars.ClosePrices.Last(1))
            {
                ClosePositions(TradeType.Buy);
                if (cBotPositions.Length == 0 && _ema17rsi.Result.LastValue > (_rsi.Result.LastValue) && Symbol.Spread < MaxSpread * Symbol.PipSize)
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
            }
        }


        private void ClosePositions(TradeType tradeType)
        {

            foreach (var position in BotPositions)
            {



                ClosePosition(position);
            }
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////////

    }
}

@zig ziag:  06 May 2022, 10:17


Hello 

i need help
I want to make changes to this Robot
If the price breaks it previous trend, the position will open
Rule:

Buy- Wherever high was seen and then low. Wait for the price to close above that high
Sell - wherever low was seen and then high. Wait for the price to close below the previous lowest level

*

*

*

*

*

using cAlgo.API;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class ZigZagCycleBot : Robot
    {
        private Position _position;
        private ZigZag _zigZag;
        private double _prevValue;


        [Parameter(DefaultValue = 12)]
        public int ZzDepth { get; set; }

        [Parameter(DefaultValue = 550)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 5)]
        public int ZzDeviation { get; set; }

        [Parameter(DefaultValue = 3)]
        public int ZzBackStep { get; set; }

        [Parameter(DefaultValue = 100000, MinValue = 0)]
        public int Volume { get; set; }


        protected override void OnStart()
        {
            _zigZag = Indicators.GetIndicator<ZigZag>(ZzDepth, ZzDeviation, ZzBackStep);
        }

        protected override void OnBar()
        {
            if (Trade.IsExecuting)
                return;

            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;


            double lastValue = _zigZag.Result.LastValue;

            if (!double.IsNaN(lastValue))
            {

                // Buy                
                if (lastValue < _prevValue && !isLongPositionOpen)
                {
                    ClosePosition();
                    Buy();
                }
                // Sell
                else if (lastValue > _prevValue && _prevValue > 0.0 && !isShortPositionOpen)
                {
                    ClosePosition();
                    Sell();
                }

                _prevValue = lastValue;
            }
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            _position = openedPosition;
            Trade.ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), null);
        }

        private void ClosePosition()
        {
            if (_position == null)
                return;
            Trade.Close(_position);
            _position = null;
        }

        private void Buy()
        {
            Trade.CreateBuyMarketOrder(Symbol, Volume);
        }

        private void Sell()
        {
            Trade.CreateSellMarketOrder(Symbol, Volume);
        }

        private double? GetAbsoluteStopLoss(Position position, int stopLoss)
        {
            return position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * stopLoss : position.EntryPrice + Symbol.PipSize * stopLoss;
        }

    }
}

@Help to build:  05 May 2022, 12:55


Hello, thank you very much for your time
I want to build a robot that can find breakouts in the Renko chart ,when a candle passes the previous resistance, it enters the trade
And robot should not have open more than one trade
I uploaded this photo to better understand what I mean
Thanks again

@turn indicator into a robot:  04 May 2022, 10:30


hi

I want to this indicator into a robot with a slight difference. We have two green and red lines here. I want the sell position to open whenever the red line closes one candle lower than the previous red line.
And whenever the green line goes one candle higher than the previous green line, the buy position will open

In fact, I want to get a breakout from the Ranko chart
And I think it is good to use this indicator
Thank you very much for your help

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TrendZonePrice : Indicator
    {
        ////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////
        ////////////////  Variables ...........................!
        ////////////////////////////////////////////////////////


        [Parameter("Show High,Low", DefaultValue = true)]
        public bool showHL { get; set; }


        private IndicatorDataSeries _haOpen;
        private IndicatorDataSeries _haClose;
        private IndicatorDataSeries _haHigh;
        private IndicatorDataSeries _haLow;






        ////////////////////////////////////////////////////////////////////////
        ////////// initializer ................................................!
        ////////////////////////////////////////////////////////////////////////

        protected override void Initialize()
        {
            _haOpen = CreateDataSeries();
            _haClose = CreateDataSeries();
            _haHigh = CreateDataSeries();
            _haLow = CreateDataSeries();
        }




        /////////////////////////////////////////////////////////////////////////
        /////// Calculation ....................................................!
        /////////////////////////////////////////////////////////////////////////


        public override void Calculate(int index)
        {
            var open = Bars.OpenPrices[index];
            var high = Bars.HighPrices[index];
            var low = Bars.LowPrices[index];
            var close = Bars.ClosePrices[index];
            var time = Bars.OpenTimes[index];

            var haClose = (open + high + low + close) / 4;
            var haOpen = (index > 0) ? (_haOpen[index - 1] + _haClose[index - 1]) / 2 : (open + close) / 2;
            var haHigh = Math.Max(Math.Max(high, haOpen), haClose);
            var haLow = Math.Min(Math.Min(low, haOpen), haClose);

            _haOpen[index] = haOpen;
            _haHigh[index] = haHigh;
            _haLow[index] = haLow;
            _haClose[index] = haClose;

            Chart.ChartType = ChartType.Line;
            var clr = haClose > haOpen ? "green" : "red";
            Chart.DrawTrendLine("line" + index, Bars.OpenTimes[index - 1], Bars.ClosePrices[index - 1], time, close, clr, 3);

            if (showHL)
            {
                Chart.DrawEllipse("high" + index, time, high, time, high, clr, 3);
                Chart.DrawEllipse("low" + index, time, low, time, low, clr, 3);

                Chart.DrawTrendLine("verticle" + index, time, high, time, low, clr, 1, LineStyle.DotsVeryRare);
                Chart.DrawTrendLine("upperline" + index, Bars.OpenTimes[index - 1], Bars.HighPrices[index - 1], time, high, clr, 1, LineStyle.DotsVeryRare);
                Chart.DrawTrendLine("lowerline" + index, Bars.OpenTimes[index - 1], Bars.LowPrices[index - 1], time, low, clr, 1, LineStyle.DotsVeryRare);
            }
        }




    }
}

@Can I run the C-Trader trading robot on my mobile?:  28 Apr 2022, 14:42


hi , i have a question

Can I run the C-Trader trading robot on my mobile?

@Gann Hilo:  27 Apr 2022, 11:50


Dear Ahmad, I referred. The robot successfully built, but does not open any position

Please check it again

using System;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class GannHiLoRobot : Robot
    {
        private GannHighLow _firstGann, _secondGann, _thirdGann;

        private Position _position;

        [Parameter("1st Gann Period", DefaultValue = 50)]
        public int FirstGannPeriod { get; set; }

        [Parameter("2nd Gann Period", DefaultValue = 10)]
        public int SecondGannPeriod { get; set; }

        [Parameter("3rd Gann Period", DefaultValue = 100)]
        public int ThirdGannPeriod { get; set; }

        [Parameter("Volume", DefaultValue = 10000)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 0)]
        public int StopLoss { get; set; }


        [Parameter(DefaultValue = 0)]
        public int TakeProfit { get; set; }


        [Parameter(DefaultValue = 0)]
        public double SLTrigger { get; set; }

        [Parameter(DefaultValue = 0)]
        public double TrailingStop { get; set; }

        private bool _isTrigerred;


        protected bool UseTrailingStop
        {
            get { return SLTrigger > 0.0 && TrailingStop > 0.0; }
        }

        protected override void OnStart()
        {
            _firstGann = Indicators.GetIndicator<GannHighLow>(FirstGannPeriod);
            _secondGann = Indicators.GetIndicator<GannHighLow>(SecondGannPeriod);
            _thirdGann = Indicators.GetIndicator<GannHighLow>(ThirdGannPeriod);

        }

        protected override void OnTick()
        {

            if (Trade.IsExecuting || _position == null)
                return;

            if (UseTrailingStop)
                Trail();

        }

        /// <summary>
        /// If close price rises above the GannHighLow indicator a buy is triggered and 
        /// if the prices falls below the GannHighLow  indicator a sell is triggered.
        /// </summary>
        protected override void OnBar()
        {
            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;


            if (_firstGann.Result.HasCrossedAbove(MarketSeries.Close, 1) && _secondGann.Result.HasCrossedBelow(_thirdGann.Result, 1) && !isShortPositionOpen)
            {
                ClosePosition();
                Sell();
            }
            else if (_firstGann.Result.HasCrossedBelow(MarketSeries.Close, 1) && _secondGann.Result.HasCrossedAbove(_thirdGann.Result, 1) && !isLongPositionOpen)
            {
                ClosePosition();
                Buy();
            }
        }


        /// <summary>
        /// Close the existing position
        /// </summary>
        private void ClosePosition()
        {
            if (_position == null)
                return;

            Trade.Close(_position);
            _position = null;
        }

        /// <summary>
        /// Send a Buy trade request
        /// </summary>
        private void Buy()
        {
            Request request = new MarketOrderRequest(TradeType.Buy, Volume) 
            {
                Label = "Gann HiLo",
                //SlippagePips = 1,
                StopLossPips = StopLoss > 0 ? (int?)StopLoss : null,
                TakeProfitPips = TakeProfit > 0 ? (int?)TakeProfit : null
            };
            Trade.Send(request);
        }

        /// <summary>
        /// Send a Sell trade request
        /// </summary>
        private void Sell()
        {
            Request request = new MarketOrderRequest(TradeType.Sell, Volume) 
            {
                Label = "Gann HiLo",
                //SlippagePips = 1,
                StopLossPips = StopLoss > 0 ? (int?)StopLoss : null,
                TakeProfitPips = TakeProfit > 0 ? (int?)TakeProfit : null
            };
            Trade.Send(request);
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            _position = openedPosition;
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

        /// <summary>
        /// Trailing Stop
        /// </summary>
        private void Trail()
        {
            if (_position.TradeType == TradeType.Buy)
            {
                double distance = Symbol.Bid - _position.EntryPrice;

                if (distance >= SLTrigger * Symbol.PipSize)
                {
                    if (!_isTrigerred)
                    {
                        _isTrigerred = true;
                        Print("Trailing Stop Loss triggered...");
                    }

                    double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits);

                    if (_position.StopLoss == null || newStopLossPrice > _position.StopLoss)
                    {
                        Trade.ModifyPosition(_position, newStopLossPrice, _position.TakeProfit);
                    }
                }
            }
            else
            {
                double distance = _position.EntryPrice - Symbol.Ask;

                if (distance >= SLTrigger * Symbol.PipSize)
                {
                    if (!_isTrigerred)
                    {
                        _isTrigerred = true;
                        Print("Trailing Stop Loss triggered...");
                    }

                    double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits);

                    if (_position.StopLoss == null || newStopLossPrice < _position.StopLoss)
                    {
                        Trade.ModifyPosition(_position, newStopLossPrice, _position.TakeProfit);
                    }
                }
            }
        }

    }
}

@Gann Hilo:  26 Apr 2022, 18:57


Hi, I need the help of developers This robot does not work

This gives an Error : The type or namespace name 'GannHighLow' could not be found (are you missing a using directive or an assembly reference?)

Thanks to Mr. Ahmad

this is code:

using System;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class GannHiLoRobot : Robot
    {
        private GannHighLow _firstGann, _secondGann, _thirdGann;

        private Position _position;

        [Parameter("1st Gann Period", DefaultValue = 50)]
        public int FirstGannPeriod { get; set; }

        [Parameter("2nd Gann Period", DefaultValue = 10)]
        public int SecondGannPeriod { get; set; }

        [Parameter("3rd Gann Period", DefaultValue = 100)]
        public int ThirdGannPeriod { get; set; }

        [Parameter("Volume", DefaultValue = 10000)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 0)]
        public int StopLoss { get; set; }


        [Parameter(DefaultValue = 0)]
        public int TakeProfit { get; set; }


        [Parameter(DefaultValue = 0)]
        public double SLTrigger { get; set; }

        [Parameter(DefaultValue = 0)]
        public double TrailingStop { get; set; }

        private bool _isTrigerred;


        protected bool UseTrailingStop
        {
            get { return SLTrigger > 0.0 && TrailingStop > 0.0; }
        }

        protected override void OnStart()
        {
            _firstGann = Indicators.GetIndicator<GannHighLow>(FirstGannPeriod);
            _secondGann = Indicators.GetIndicator<GannHighLow>(SecondGannPeriod);
            _thirdGann = Indicators.GetIndicator<GannHighLow>(ThirdGannPeriod);

        }

        protected override void OnTick()
        {

            if (Trade.IsExecuting || _position == null)
                return;

            if (UseTrailingStop)
                Trail();

        }

        /// <summary>
        /// If close price rises above the GannHighLow indicator a buy is triggered and 
        /// if the prices falls below the GannHighLow  indicator a sell is triggered.
        /// </summary>
        protected override void OnBar()
        {
            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;


            if (_firstGann.Result.HasCrossedAbove(MarketSeries.Close, 1) && _secondGann.Result.HasCrossedBelow(_thirdGann.Result, 1) && !isShortPositionOpen)
            {
                ClosePosition();
                Sell();
            }
            else if (_firstGann.Result.HasCrossedBelow(MarketSeries.Close, 1) && _secondGann.Result.HasCrossedAbove(_thirdGann.Result, 1) && !isLongPositionOpen)
            {
                ClosePosition();
                Buy();
            }
        }


        /// <summary>
        /// Close the existing position
        /// </summary>
        private void ClosePosition()
        {
            if (_position == null)
                return;

            Trade.Close(_position);
            _position = null;
        }

        /// <summary>
        /// Send a Buy trade request
        /// </summary>
        private void Buy()
        {
            Request request = new MarketOrderRequest(TradeType.Buy, Volume) 
            {
                Label = "Gann HiLo",
                //SlippagePips = 1,
                StopLossPips = StopLoss > 0 ? (int?)StopLoss : null,
                TakeProfitPips = TakeProfit > 0 ? (int?)TakeProfit : null
            };
            Trade.Send(request);
        }

        /// <summary>
        /// Send a Sell trade request
        /// </summary>
        private void Sell()
        {
            Request request = new MarketOrderRequest(TradeType.Sell, Volume) 
            {
                Label = "Gann HiLo",
                //SlippagePips = 1,
                StopLossPips = StopLoss > 0 ? (int?)StopLoss : null,
                TakeProfitPips = TakeProfit > 0 ? (int?)TakeProfit : null
            };
            Trade.Send(request);
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            _position = openedPosition;
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

        /// <summary>
        /// Trailing Stop
        /// </summary>
        private void Trail()
        {
            if (_position.TradeType == TradeType.Buy)
            {
                double distance = Symbol.Bid - _position.EntryPrice;

                if (distance >= SLTrigger * Symbol.PipSize)
                {
                    if (!_isTrigerred)
                    {
                        _isTrigerred = true;
                        Print("Trailing Stop Loss triggered...");
                    }

                    double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits);

                    if (_position.StopLoss == null || newStopLossPrice > _position.StopLoss)
                    {
                        Trade.ModifyPosition(_position, newStopLossPrice, _position.TakeProfit);
                    }
                }
            }
            else
            {
                double distance = _position.EntryPrice - Symbol.Ask;

                if (distance >= SLTrigger * Symbol.PipSize)
                {
                    if (!_isTrigerred)
                    {
                        _isTrigerred = true;
                        Print("Trailing Stop Loss triggered...");
                    }

                    double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits);

                    if (_position.StopLoss == null || newStopLossPrice < _position.StopLoss)
                    {
                        Trade.ModifyPosition(_position, newStopLossPrice, _position.TakeProfit);
                    }
                }
            }
        }

    }
}

@vidya trend:  26 Apr 2022, 11:52


Hello
I have an idea for this indicator but I need the help of developers
First of all, let me say   this indicator belongs to C-Trader, I did not make it
I want to use two Vidya lines but it does not have "Sigma" settings
I want to add Sigma capability to it
Can anyone help me?
Thank you very much

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Trend cBot" will buy when fast period moving average crosses the slow period moving average and sell when 
//    the fast period moving average crosses the slow period moving average. The orders are closed when an opposite signal 
//    is generated. There can only by one Buy or Sell order at any time.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("MA Type", Group = "Moving Average")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Source", Group = "Moving Average")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", Group = "Moving Average", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", Group = "Moving Average", DefaultValue = 5)]
        public int FastPeriods { get; set; }



        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
            var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
            }
        }

        private double VolumeInUnits
        {
            get { return Symbol.QuantityToVolumeInUnits(Quantity); }
        }
    }
}

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.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
Gann Hilo
  7
  0
  475
free  25 Apr 2022
Hello, can anyone help me? I want to add a condition to this indicator but I do not know how to code I want this  indicator to have another Gan Hilo For example,  two GannHilo 10 and 100, and the position opens when the price crosses both, but when the price returns from the Gun 10, the position closes. My language is not English so I hope you understand what I mean And thank you very much for helping me