Topics
Replies
                     social.trading
                     10 Oct 2019, 12:54
                                    
Hello Panagiotis,
sorry, where can I find the log?
best regards
@social.trading
                     social.trading
                     10 Oct 2019, 12:44
                                            ( Updated at: 21 Dec 2023, 09:21 )
                                    
RE:
Hello Panagiotis,
I tried your code, but as you see from the screenshot, it is entering the if loop, printing false, but not playing the sound or printing Print("Play Buy Sound");

best regards
@social.trading
                     social.trading
                     10 Oct 2019, 11:19
                                    
Hello Panagiotis,
yes I put at the beginning of the if loop, this code:
ChartObjects.DrawText("", "" + alreadyPlayed, StaticPosition.TopRight, Colors.White);
and the return is false, so the sound should play, but it isn't.
Yes the sound and the path are all correct, because it plays endless if I don't use the bool alreadyPlayed.
I'm some coding expierence, but seems not to be enough to implement this correctly.
best regards
@social.trading
                     social.trading
                     10 Oct 2019, 11:06
                                    
Hello Panagiotis,
unfortunaetly even once it isn't playing it, although the alreadyPlayed is set later to true. Any idea how to improve it, maybe different coding way.
best regards
@social.trading
                     social.trading
                     10 Oct 2019, 10:38
                                    
Hello Panagiotis,
Actually, I'm trying to modifiy already exisiting indicator: https://ctrader.com/algos/indicators/show/1741
and add to it a sound notification:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class LvAMaCross : Indicator
    {
        [Parameter("MA Type", DefaultValue = MovingAverageType.TimeSeries)]
        public MovingAverageType maType { get; set; }
        [Parameter("Slow Period", DefaultValue = 30, MinValue = 1)]
        public int slowPeriod { get; set; }
        [Parameter("Fast Period", DefaultValue = 12, MinValue = 1)]
        public int fastPeriod { get; set; }
        [Parameter("Time Frame MA", DefaultValue = "Hour")]
        public TimeFrame timeFrame { get; set; }
        [Output("Sell Point", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 15)]
        public IndicatorDataSeries SellSeries { get; set; }
        [Output("Buy Point", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 15)]
        public IndicatorDataSeries BuySeries { get; set; }
        public bool alreadyPlayed = false;
        public IndicatorDataSeries FastDataSeries { get; set; }
        public IndicatorDataSeries SlowDataSeries { get; set; }
        //market series cho timeframe cần tính
        public MarketSeries selectedSeries;
        public MovingAverage fastMA;
        public MovingAverage slowMA;
        protected override void Initialize()
        {
            FastDataSeries = CreateDataSeries();
            SlowDataSeries = CreateDataSeries();
            if (timeFrame == MarketSeries.TimeFrame)
            {
                selectedSeries = MarketSeries;
                fastMA = Indicators.MovingAverage(MarketSeries.Close, fastPeriod, maType);
                slowMA = Indicators.MovingAverage(MarketSeries.Close, slowPeriod, maType);
            }
            else
            {
                selectedSeries = MarketData.GetSeries(timeFrame);
                fastMA = Indicators.MovingAverage(selectedSeries.Close, fastPeriod, maType);
                slowMA = Indicators.MovingAverage(selectedSeries.Close, slowPeriod, maType);
            }
        }
        public override void Calculate(int index)
        {
            var selectedIndex = selectedSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            if (selectedIndex == -1)
            {
                return;
            }
            FastDataSeries[index] = fastMA.Result[selectedIndex];
            SlowDataSeries[index] = slowMA.Result[selectedIndex];
            if (isCrossBelow())
            {
                // sell
                SellSeries[index] = MarketSeries.High[index];
                if (IsLastBar)
                {
                    ChartObjects.DrawText("text1", "SELL", StaticPosition.Center, Colors.White);
                    if (!alreadyPlayed)
                    {
                        ChartObjects.DrawText("", "" + alreadyPlayed, StaticPosition.BottomRight, Colors.White);
                        Notifications.PlaySound("...action.mp3");
                        alreadyPlayed = true;
                      
                    }
                }
            }
            else if (isCrossAbove())
            {
                // buy 
                BuySeries[index] = MarketSeries.Low[index];
                if (IsLastBar)
                {
                    ChartObjects.DrawText("text1", "BUY", StaticPosition.Center, Colors.White);
                    if (!alreadyPlayed)
                    {
                        ChartObjects.DrawText("", "" + alreadyPlayed, StaticPosition.TopRight, Colors.White);
                        Notifications.PlaySound("...action.mp3");
                        alreadyPlayed = true;
                    }
                }
            }
        }
        #region Predicate
        public bool isCrossAbove()
        {
            return FastDataSeries.HasCrossedAbove(SlowDataSeries, 0);
        }
        public bool isCrossBelow()
        {
            return FastDataSeries.HasCrossedBelow(SlowDataSeries, 0);
        }
        #endregion
    }
}
@social.trading
                     social.trading
                     10 Oct 2019, 09:42
                                    
Hello Panagiotis,
thank you for your feedback. The issue here how to play it once? Because the if loof will repeat. I also tried with bool true/false, but it is not working.
best regards
@social.trading
                     social.trading
                     09 Oct 2019, 20:13
                                    
Any help from some expert here? I think it should be very simple.
@social.trading
social.trading
10 Oct 2019, 15:57 ( Updated at: 21 Dec 2023, 09:21 )
Hello Panagiotis,
yes there I was looking, but I don't have it (pic attached). I also looked how to add but failed.
best regards
@social.trading