Replies

sascha.dawe
17 May 2021, 10:48 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Thanks Panagiotis,

If this helps, here is the error exception code that pops up.

 

Regards,

Sascha

 


@sascha.dawe

sascha.dawe
22 Apr 2021, 13:06

RE: RE:

Thanks Firemyst,

This appears to be the issue. I added a time delay of 10 seconds and the sound played fine. So it appears, that while loading the bars on start up, caused interference with the sound notification on the indicator.

Cheers,

Sascha

 

firemyst said:

sascha.dawe said:

Hi,

 

I am having trouble playing sound notifications in an indicator in the latest version of Ctrader 4.0.

Yes, I have sound enabled and notifications on Ctrader and Filesystem access is enabled. I have

also converted this code to a cBot and the sound works fine. What could be causing this issue?

See demonstration code below.

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class TestSound : Indicator
    {
        [Parameter("Enable Sound Alerts", Group = "Sound", DefaultValue = false)]
        public bool soundAlerts { get; set; }
        [Parameter("Sound Filename", Group = "Sound", DefaultValue = "foghorn.mp3")]
        public string filename { get; set; }

        private string path;
        private bool notified = false;

        protected override void Initialize()
        {
            try
            {
                var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                path = Path.Combine(desktopFolder, filename);
                Print(path);
            } catch (Exception error)
            {
                Print("Error: " + error);
            }
            PlaySound();
        }

        public override void Calculate(int index)
        {
            if (!notified)
            {
                notified = true;
                PlaySound();
            }
        }

        private void PlaySound()
        {
            if (soundAlerts)
            {
                try
                {
                    Notifications.PlaySound(path);
                } catch (Exception error)
                {
                    Print("Error: " + error);
                }
            }
        }
    }
}

 

 

Have you tried stepping through your code in Visual Studio debug mode to see what happens?

Also, because ticks could be coming in rather quickly, the system might be trying to play, but then gets stopped immediately when the next tick comes in because the "notified" variable is never set to true. I've had that happen before when trying to play sounds too quickly in succession.

Finally, what's the Print/logging output?

 


@sascha.dawe

sascha.dawe
11 Dec 2020, 07:10

RE:

enisjahja said:

Hi, 

 

Can anybody help me with this code:

(I want to make when it hits SL enter opposite direction and when it hits TP countinue with the position trade direction.)

This is the martingale code:

 

// -------------------------------------------------------------------------------------------------
//
//    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 Martingale cBot" creates a random Sell or Buy order. If the Stop loss is hit, a new 
//    order of the same type (Buy / Sell) is created with double the Initial Volume amount. The cBot will 
//    continue to double the volume amount for  all orders created until one of them hits the take Profit. 
//    After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount.
//
// -------------------------------------------------------------------------------------------------

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 SampleMartingalecBot : Robot
    {
        [Parameter("Initial Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double InitialQuantity { get; set; }

        [Parameter("Stop Loss", Group = "Protection", DefaultValue = 40)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Protection", DefaultValue = 40)]
        public int TakeProfit { get; set; }


        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialQuantity, GetRandomTradeType());
        }

        private void ExecuteOrder(double quantity, GetRandomTradeType())
        {
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(quantity);
            var result = ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolName != SymbolName)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialQuantity, position.TradeType);
            }
            else
            {
                ExecuteOrder(position.Quantity * 2, position.TradeType==TradeType.Buy?TradeType.Sell:TradeType.Buy);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

Try this code: I have update the OnPositionsClosed() function.

Regards,

Sascha


@sascha.dawe

sascha.dawe
18 May 2020, 14:17

RE:

PanagiotisCharalampous said:

Hi sascha.dawe,

There seem to be a lot of issues with your code. A couple of points you should revisit

1) Try adding output attributes to your SampleSignalMultiSymbol indicator

2) Revisit your indexing. Doesn't seem to make much sense to me.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks Panagiotis,

Is an output attribute strictly necessary though for the signal to be passed through?

I don't really want an output to the screen from this indicator. I just want various time frame signals to be passed through

to the one chart panel, where buy/sell buttons will be displayed on screen.

Regards,

Sascha

 


@sascha.dawe

sascha.dawe
23 Mar 2020, 11:59

RE:

Fantastic,

This is a good starting point.

 

Thanks,

Sascha

 


@sascha.dawe

sascha.dawe
04 Mar 2020, 00:59

RE:

PanagiotisCharalampous said:

Hi Takis,

Symbols.GetSymbol() doesn't work in optimization. You will need to replace the references to symbol with strings.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis, 

Could you provide a little more information on this:

Such as what I would replace this line with?

Symbol symbol = Symbols.GetSymbol("AUD" + quoteCurrency);

Thanks,

Sascha


@sascha.dawe

sascha.dawe
24 Feb 2020, 13:20 ( Updated at: 21 Dec 2023, 09:21 )

RE:

PanagiotisCharalampous said:

Hi sascha.dawe,

Can you explain to us what do you think is wrong?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

See two attached screenshots. Both show daily time frame VWAP on 1 hr chart. The reference indicator (VWAP) shows the band correctly. The other one (BVWAP) is warped. BVWAP includes two offset bands, but these can be ignored.

I would use the original VWAP indicator, but the time frame user input is not included in the source code at all, even though the source code is accessible?

What am I doing wrong here?

Thanks,

Sascha

 

 

VWAP

 

 

BVWAP

 

 

 

 

 


@sascha.dawe

sascha.dawe
23 Feb 2020, 12:39 ( Updated at: 21 Dec 2023, 09:21 )

RE:

I was able to find a solution to this problem using the formula on this page. https://math.stackexchange.com/questions/2114895/point-ellipse-collision-test

 

sascha.dawe said:

Hi,

 

I was wondering how to workout if closed price is on the inside or outside of the ellipse chart object.  

This specifically relates to the curved area of the ellipse and the corresponding price/level, not whether the closed price is higher or lower than the bottom and top point of the ellipse.

See below screenshot.

Thanks,

Sascha

.

 

 


@sascha.dawe

sascha.dawe
28 Oct 2019, 11:42

Actually, I think I have it sorted, thanks.

After your last post regarding the weakness of using a time based method, I changed my approach.

Now I just record tick volume as it happens on tick and date stamp it at that point in time. Then, insert this data into a dictionary object, using datetime as key (checking 

for duplicates before adding) I can then call previous time periods by date and match up corresponding times, syncing via new bar event.  This is still somewhat time based, but seems to be quite effective, versus just storing tick volume in an array via timer.


@sascha.dawe

sascha.dawe
25 Oct 2019, 22:43

Thanks for your reply, I am trying to collect tick volume data for one minute, then comparing the corresponding time tune When it changes to new bar,. The idea is to see if the volume has changed compared to the previous time period. This would be compared on a per second basis. I have discovered the exact problem you have stated about new bar not starting on time. Also, lastvalue tick volume can also can also run into new bar. I have compensated for this. Is there a general approach you could recommend instead?
@sascha.dawe

sascha.dawe
21 Oct 2019, 09:32

Thank you.
@sascha.dawe

sascha.dawe
26 Aug 2019, 13:53

Hi Panagiotis,

Thanks for taking the time to research this problem.

This thread solved my problem.

Much Appreciated, 

Sascha


@sascha.dawe

sascha.dawe
26 Apr 2019, 10:10

RE - Help with setting label or comment

Hi,

 

You could try something like this:

string LabelTrade = string.Format("EUR = {0} & USD = {1}", EURvalue, USDvalue);

Is this what you are looking for?

I don't think you can change the label on an existing position (Correct me if I am wrong), buy you could use this created string on a new position.

If you are looking to change add a description to an existing position, you could alter the position 'comment' field as opposed to 'label'.

Best Regards,

Sascha

 


@sascha.dawe