Replies

ctid1574514
05 Dec 2019, 18:00

RE: RE: RE: RE: RE:

freedoomltr said:

If anyone have a code with the swap included let me know.

 

Not sure how to add it.  I use the line as a rough visual guide in a cbot and close with the exact profit value that has swap, commission spread etc.

I have added text top right with the value if you close the trade if this helps. 

Updated the Code above


@ctid1574514

ctid1574514
05 Dec 2019, 12:33

RE: RE: RE:

freedoomltr said:

ctid1574514 said:

deleted

thanks a lot!

Where can I add this? Does it include the swap?

 

Create a new indicator and paste the code in to it and click the build icon. 

The <code>  at the start and </code> at the end should not entered 

No it does not include the swap.  It just works out where the average price it.


@ctid1574514

ctid1574514
05 Dec 2019, 07:24

Multi Symbol Sample Trend cBot

The Sample Trend cBot trading 3 pairs.

I would have liked to have not used the switch and not declared all the indicators separately so it can scale to more pairs,  but it works trading multiple pairs on a back test

 

using System;
using System.Linq;
using System.Text;
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 MultSymbol : Robot
    {
        public Symbol[] MySymbols;

        [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 slowMaEURUSD;
        private MovingAverage fastMaEURUSD;
        private MovingAverage slowMaUSDJPY;
        private MovingAverage fastMaUSDJPY;
        private MovingAverage slowMaGBPUSD;
        private MovingAverage fastMaGBPUSD;

        private const string label = "MultSymbolcBot";

        protected override void OnStart()
        {
            MySymbols = Symbols.GetSymbols("EURUSD", "USDJPY", "GBPUSD");
            foreach (var symbol in MySymbols)
            {
                symbol.Tick += Symbol_Tick;
            }

            Bars seriesEURUSD = MarketData.GetBars(TimeFrame, "EURUSD");
            Bars seriesUSDJPY = MarketData.GetBars(TimeFrame, "USDJPY");
            Bars seriesGBPUSD = MarketData.GetBars(TimeFrame, "GBPUSD");

            fastMaEURUSD = Indicators.MovingAverage(seriesEURUSD.ClosePrices, FastPeriods, MAType);
            slowMaEURUSD = Indicators.MovingAverage(seriesEURUSD.ClosePrices, SlowPeriods, MAType);

            fastMaUSDJPY = Indicators.MovingAverage(seriesUSDJPY.ClosePrices, FastPeriods, MAType);
            slowMaUSDJPY = Indicators.MovingAverage(seriesUSDJPY.ClosePrices, SlowPeriods, MAType);

            fastMaGBPUSD = Indicators.MovingAverage(seriesGBPUSD.ClosePrices, FastPeriods, MAType);
            slowMaGBPUSD = Indicators.MovingAverage(seriesGBPUSD.ClosePrices, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {

        }

        protected override void OnStop()
        {

        }

        private void Symbol_Tick(SymbolTickEventArgs obj)
        {
            foreach (var symbol in MySymbols)
            {
                switch (symbol.Name)
                {
                    case "EURUSD":
                        SymbolTrade(symbol, fastMaEURUSD, slowMaEURUSD);
                        break;
                    case "USDJPY":
                        SymbolTrade(symbol, fastMaUSDJPY, slowMaUSDJPY);
                        break;
                    case "GBPUSD":
                        SymbolTrade(symbol, fastMaGBPUSD, slowMaGBPUSD);
                        break;
                }
            }
        }

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

        private void SymbolTrade(Symbol SymbolName, MovingAverage MaNameFast, MovingAverage MaNameSlow)
        {
            var longPosition = Positions.Find(label, SymbolName.Name, TradeType.Buy);
            var shortPosition = Positions.Find(label, SymbolName.Name, TradeType.Sell);

            var currentSlowMa = MaNameSlow.Result.Last(0);
            var currentFastMa = MaNameFast.Result.Last(0);
            var previousSlowMa = MaNameSlow.Result.Last(1);
            var previousFastMa = MaNameFast.Result.Last(1);

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

 


@ctid1574514

ctid1574514
05 Dec 2019, 04:41

RE:

deleted


@ctid1574514

ctid1574514
05 Dec 2019, 04:35

RE:

freedoomltr said:

No one with this?

Try this.  It is the first indicator I have done 

 

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


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

        [Parameter("Buy & Sell Lines")]
        public bool BuySell { get; set; }

        [Parameter("Average Line")]
        public bool Avg { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private double AvgPrice;
        private double BuyPrice;
        private double SellPrice;


        protected override void Initialize()
        {
            //DisplayStatusOnChart();
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
            DisplayStatusOnChart();
        }


        private void DisplayStatusOnChart()
        {
            if (Avg && Positions.Count(x => x.SymbolName == SymbolName) > 1)
            {
                Chart.DrawHorizontalLine("apoint", CalculateAveragePositionPrice(), Color.Yellow, 2, LineStyle.Dots);
            }
            else
                Chart.RemoveObject("apoint");
            if (BuySell && Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName) > 1)
            {
                Chart.DrawHorizontalLine("bpoint", CalculateAveragePositionPriceSplit(TradeType.Buy), Color.Lime, 2, LineStyle.Dots);
            }
            else
                Chart.RemoveObject("bpoint");
            if (BuySell && Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName) > 1)
            {
                Chart.DrawHorizontalLine("spoint", CalculateAveragePositionPriceSplit(TradeType.Sell), Color.LightPink, 2, LineStyle.Dots);
            }
            else
            {
                Chart.RemoveObject("spoint");
            }

            Chart.DrawStaticText("pan", GenerateStatusText(), VerticalAlignment.Top, HorizontalAlignment.Left, Color.Tomato);
        }


        private double CalculateAveragePositionPrice()
        {
            double result = 0;
            double averagePrice = 0;
            double count = 0;
            AvgPrice = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolName == SymbolName)
                {
                    averagePrice += position.EntryPrice * position.VolumeInUnits;
                    count += position.VolumeInUnits;
                    AvgPrice += position.NetProfit;
                }
            }

            if (averagePrice > 0 && count > 0)
            {
                result = Math.Round(averagePrice / count, Symbol.Digits);
            }
            return result;
        }


        private double CalculateAveragePositionPriceSplit(TradeType tradeType)
        {
            double result = 0;
            double averagePrice = 0;
            double count = 0;
            BuyPrice = 0;
            SellPrice = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolName == SymbolName)
                {
                    if (position.TradeType == tradeType)
                    {
                        averagePrice += position.EntryPrice * position.VolumeInUnits;
                        count += position.VolumeInUnits;
                    }
                    if (position.TradeType == TradeType.Buy)
                    {
                        BuyPrice += position.NetProfit;
                    }
                    else if (position.TradeType == TradeType.Sell)
                    {
                        SellPrice += position.NetProfit;
                    }
                }
            }

            if (averagePrice > 0 && count > 0)
            {
                result = Math.Round(averagePrice / count, Symbol.Digits);
            }
            return result;
        }

        private string GenerateStatusText()
        {
            var statusText = "";
            if (Avg)
            {
                statusText += "Average |" + Math.Round(AvgPrice, 2) + "\n";
            }
            if (BuySell)
            {
                statusText += "Buy |" + Math.Round(BuyPrice, 2) + "\n";
                statusText += "Sell |" + Math.Round(SellPrice, 2) + "\n";
            }
            return statusText;
        }
    }
}

 


@ctid1574514

ctid1574514
05 Dec 2019, 04:08 ( Updated at: 21 Dec 2023, 09:21 )

RE: RE:

firemyst said:

PanagiotisCharalampous said:

Hi FireMyst,

https://ctrader.com/forum/ctrader-support/22129 Yes

https://ctrader.com/forum/ctrader-support/21482 No

https://ctrader.com/forum/ctrader-support/21540 No 

https://ctrader.com/forum/calgo-support/21534 No

Please join our Telegram group where we report such updates e.g. 

Best Regards,

Panagiotis 

Join us on Telegram

 

HI @Panagiotis:

Thank you for the updates. I think you need to at least update thread 22129 then to indicate to everyone it has been resolved :-)

As for Telegram - we have the forums - how hard is it to create a separate forum and/or a read-only thread and include the updates there? Users should not have to download another application and join yet another Spotware group in that application to now find out the latest updates.

Or is Spotware going to put a Directory on their website that tells users what they should do and where they should go to get certain information?

  •  Spotware.com -> product information, sales information, download actual products
  •  Facebook -> latest sales/marketing promotions
  •  cTrader.com -> forums and latest API announcements
  •  Telegram -> latest change release logs

etc etc etc.

Getting a bit ridiculous don't you think?

How many 3rd party applications, services, and systems does Spotware want us to sign up to in order to use and get information on their products?

 

 

 

 

@Panagiotis:
I really do not want to install the Telegram app just for ctrader updates. Please can the latest change logs be posted to the forum as @FireMyst  requested.
I could not find a version of telegram that runs on the web.  Please don't make us install yet another app on PC's just for this 


@ctid1574514

ctid1574514
23 Nov 2019, 03:16

RE: RE:

Panagiotis Charalampous said:

danblackadder said:

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 

Hi danblackadder,

It will be included in 3.7

Best Regards,

Panagiotis

https://ctrader.com/forum/suggestions/21283?page=6#post-56

3.7 will be before xmas 


@ctid1574514

ctid1574514
23 Nov 2019, 03:15

RE: RE:

Panagiotis Charalampous said:

danblackadder said:

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 

Hi danblackadder,

It will be included in 3.7

Best Regards,

Panagiotis

https://ctrader.com/forum/suggestions/21283?page=6#post-56

 

3.7 will be before Xmas


@ctid1574514

ctid1574514
18 Oct 2019, 05:42

RE: RE:

dordkash@gmail.com said:

Panagiotis Charalampous said:

Hi reza h,

We do not have an ETA yet.

Best Regards,

Panagiotis

Hi

I did not catch

What is ETA?

estimated time of arrival (ETA)


@ctid1574514