Topics
Replies

firemyst
01 Sep 2020, 17:51

I don't know if there's an indicator for it, but you'll need C# code to find "peaks and troughs".

Doing a Google search will yield results for you.


@firemyst

firemyst
31 Aug 2020, 16:23

RE:

patrock333 said:

I was wondering if anyone knows how to pass data between two or more running cBots.

Eg. One cBot running on the AUDUSD symbol passing data to another cBot on NZDUSD to help in triggering an event.

 

Thanks.

Static variables would work wonders for you.

Static variables are shared across multiple instances of the same indicator on different charts, so hopefully they would also be shared between bot instances of the same bot.

However, they probably won't be shared between different bots.

It'll save the hassle and slowness of reading/writing files to/from the file system.


@firemyst

firemyst
31 Aug 2020, 15:56

RE:

jeanmarc.cds said:

Hello everybody.

 

I am looking for a good cTrader broker with a good spread on AUDSGD pair. ICmarkets seems very good but they dont accept Canadian citizens. Most of brokers I checked dont offer AUDSGD or have quite high spreads on this pair.

 

THANKS FOR YOUR HELP

AUDSGD and USDSGD are offered by Pepperstone:

They also use cTrader.

Not 100% sure about them accepting Canadians though.

 


@firemyst

firemyst
30 Aug 2020, 16:06

RE: RE: RE: RE: Example code for quick tip:

.

 


@firemyst

firemyst
30 Aug 2020, 14:55

RE: RE: Example code for quick tip:

voldemort said:

Only difference is I used Bars instead of MarketSeries. Will give this a go. Thanks :)

that should have been "Bars" and not MarketSeries.

I've updated the code in the example.

If it's still not working, it's something else with your code or what you're doing, so you'll need to post some sample code.


@firemyst

firemyst
30 Aug 2020, 12:54

What you need to do is:

1) get the position open time

2) create a timer object

3) when 15 minutes has passed on the timer object, trigger it to call a method. That method could be the close method, which closes your position.

Examples for the C# timer object:

https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer?view=netcore-3.1

and

https://stackoverflow.com/questions/12535722/what-is-the-best-way-to-implement-a-timer


@firemyst

firemyst
30 Aug 2020, 12:43

Example code for quick tip:

 public override void Calculate(int index)
        {
            int altIndex = index;

            altIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            //Reference any values from a different timeframe with the altIndex
            double median = (Bars.HighPrices[altIndex] + Bars.LowPrices[altIndex]) / 2;

	   Result[index] = median;
	}

 

Hope this helps :-)

 

 


@firemyst

firemyst
30 Aug 2020, 12:36

In Visual Studio:

  • Right Click on your project and select 'Add reference'

  • Select 'Assemblies->Framework' in 'Reference Manager' window.

  • Add select Microsoft.CSharp.dll and click on add

 

You might also try this link:

https://stackoverflow.com/questions/13566887/dynamic-in-the-immediate-window-causes-microsoft-csharp-runtimebinder-binder-i?lq=1

 


@firemyst

firemyst
30 Aug 2020, 12:30

Hi @Vitore:

When you report bugs like this, you should include screen shots or code samples which illustrate the issue.

It will help others see what's happening, and help Spotware diagnose the issue if in fact it is an issue.

 


@firemyst

firemyst
30 Aug 2020, 12:28

Have you looked at the online guides @Spotware have posted?

https://help.ctrader.com/ctrader-automate/guides/trading_api

 

As for me, I went the cTrader route because it uses C#, which to me is easier because I already knew it. :-)

MT5 will definitely have more support and more options available though because that seems to be the standard in the industry MetaTrader.

If you plan to do any other kind of programming other than for bots/indicators (eg, writing your own Windows applications or whatever), then you should learn C#; otherwise it's up to you.


@firemyst

firemyst
26 Aug 2020, 14:33

Here's an example how. You have to get the current date in your code:

if (_currentDate.DayOfWeek != DayOfWeek.Friday && _currentDate.DayOfWeek != DayOfWeek.Saturday && _currentDate.DayOfWeek != DayOfWeek.Sunday)
{

}

 


@firemyst

firemyst
26 Aug 2020, 14:28

Have you run this code in Visual Studio or put in "Print" statements to see if the actual calls to ModifiyPosition are called?

You have quite a bit of "IF" statements, so how do you know any of those are true to execute the modifyposition method?


@firemyst

firemyst
26 Aug 2020, 14:24

This is relatively easy.

See code example below. You'll obviously have to make adjustments for it to fit in your code.

 

//you need to set this up as a parameter
StopBotWhenLossesFallBelow


double _runningTotalsGainLoss;
string _positionLabel;

        private void Positions_Closed(PositionClosedEventArgs args)
        {
            //Only run this method if it's this instance that closed.
            Position p1 = args.Position;

            if (p1.SymbolName == Symbol.Name && p1.Label == _positionLabel)
            {
                    //Now get the historical trade stuff.
                    HistoricalTrade ht = History.FindLast(p1.Label, p1.SymbolName, p1.TradeType);

                        //Running Totals
                        _runningTotalsGainLoss += p1.NetProfit;
                        Print("PC20: Running total for \"{0}\": {1}", p1.Label, String.Format("{0:$#,###.00}", _runningTotalsGainLoss));
                        if (_runningTotalsGainLoss < StopBotWhenLossesFallBelow)
                        {
                            Print("WARNING! Running total {0} has fallen below StopBotWhenLossesFallBelow {1} threshold! Stopping bot for \"{2}\"!", String.Format("{0:$#,###.00}", _runningTotalsGainLoss), String.Format("{0:$#,###.00}", StopBotWhenLossesFallBelow), p1.Label);
							Stop();
                        }
            }

        }

 


@firemyst

firemyst
17 Aug 2020, 12:43

Serialize it to JSON, save the JSON to a text file.

Then when you restart and restart your bot/indicator, in the OnStart or Initialize methods, you can read the json back in and convert it back to a 2-dimensional array.

Example code:

//In the OnStart method:

            // read saved file into a string and deserialize JSON to a type
            RobotInfoClass ric = null;
            if (System.IO.File.Exists(_savedFilePath))
            {
                ric = JsonConvert.DeserializeObject<RobotInfoClass>(System.IO.File.ReadAllText(_savedFilePath));
                System.IO.File.Delete(_savedFilePath);  //clean up since we no longer need it
            }

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

//In the OnStop method:

using (System.IO.StreamWriter sw = new System.IO.StreamWriter(_savedFilePath))
                {
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        RobotInfoClass ric = new RobotInfoClass();
                        ric._positionEntryPricePoints = _positionEntryPricePoints;
                        ric._positionEntryPriceTimes = _positionEntryPriceTimes;
                        ric._breakEvenPoints = _breakEvenPoints;
                        ric._increasePositionSizePoints = _increasePositionSizePoints;
                        //blah blah blah
                        ric._savedTime = DateTime.Now;

                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Formatting = Formatting.Indented;
                        serializer.Serialize(writer, ric);
                    }
                }

 


@firemyst

firemyst
17 Aug 2020, 12:35

It can be found here:

 

https://ctrader.com/algos/indicators/show/555

 

Enjoy.


@firemyst

firemyst
17 Aug 2020, 12:21 ( Updated at: 21 Dec 2023, 09:22 )

HI Stephan:

I find this easiest to do is code up your reference DLL in the "documents \ calgo \ sources" folder.

When it compiles there:

Then in cTrader in "Automate", select the Indicator/bot you want, and from the 3 vertical dots, select the option to "Manage references":

Then you should find it under the "Libraries" side menu. If it's not there, click the "browse" button in the top right of the window and add it in.

Lastly, launch your visual studio project and viola, it'll be included.

 

I've had too many issues if I try and go the other way -- adding the reference from within VS without doing it through cTrader.

 

Hope this helps!


@firemyst

firemyst
15 Aug 2020, 17:05

RE:

luca.tocchi said:

hi I need to print "ok"

print ("ok");

when the price is 60 pips above the current price

thanks

 

Get Symbol.Bid or Symbol.Ask price (whichever one you want to measure from) and then add 60 pips:

Symbol.Bid + (60 * Symbol.PipSize)

Symbol.Ask + (60 * Symbol.Pipsize)


@firemyst

firemyst
15 Aug 2020, 17:03

RE:

tradermatrix said:

Hi
I have built a robot with several signals independent of each other, with a different label per signal.
for example :
  RobotID_A1
  RobotID_A2
  RobotID_A3
  RobotID_A4
so 4 positions are possible together
I would like to limit to 2 open positions (the robot chooses the 2 best signals depending on the market)
but how to proceed with different labels.
cordially.

Your question doesn't make sense and isn't clear.

What do you want to happen?


@firemyst

firemyst
15 Aug 2020, 14:07

RE: RE: Platform updates

Symposium said:

 

Firemyst... Are you serious?...... 15 Indicators on any chart is your issue!..... Not Spotware's..... They have added a delete button to the Indicators popup panel....

<Left click>, <Right click>....  Indicator Gone!.....  Makes removal of any unwanted Indicators simple. A great update to the Platform. The only other Platform (Retail) even on the same page as Ctrader is TradingView's

TWB

TWB: you missed the point. The number of indicators is irrelevant. It's the number of clicks users have to go through now for indicators cTrader doesn't allow you to click on to remove, that provides valuable information or functionality cTrader lacks.

Let's say you have just two indicators. Or better yet, let's just say one. Use the example one I linked to above.

Add it to your chart.

Now see how you can delete it without going through an indicator's menu.

I rest my case.

There are numerous indicators out there like this people use.

It now takes more time for users to accomplish the same action than previously.

That's not good UI design principles.

PS: if you think Trading View is the only other app, you obviously haven't looked at Pro Real Time or ThinkTrader. :-)

 


@firemyst

firemyst
14 Aug 2020, 12:09

RE:

PanagiotisCharalampous said:

Hi firemyst,

You can edit/delete an indicator if you just right click on it inside the chart.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi @Panagiotis:

As a follow up, you can't do this with every indicator, which makes it even worse.

For example, here's one it can't be done with:

https://ctrader.com/algos/indicators/show/2209

Add it to your chart, and see if you can "right-click" to edit the properties or delete it.

Now imagine you have that on your chart with a few other indicators like PSAR and BollingerBands.

You can't do anything with unless you go through double the amount of mouse clicks introduced in v3.8 as opposed to v3.7.

It's frustrating the end user experience.

 

 


@firemyst