Topics
Replies

firemyst
17 Sep 2020, 07:48

RE:

luca.tocchi said:

hi my bot should modify the stop loss (using ModifyOrder) when it reaches the stop loss minus 0.2 pips
how can I do?
 

thanks

//for long positions

if ((Symbol.Bid - CurrentStopLossValue) / Symbol.PipSize <= 0.2)

{

    //price is within 0.2 pips of SL

   p.ModifiyStopLossPips //or p.ModifyStopLossPrice depending on what you want to do

}


@firemyst

firemyst
16 Sep 2020, 14:05 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

xammo said:

Hi Firemyst

...
(1 CPU/1GB RAM) for ctrader which doesn’t give me much confidence as it simply won’t run on those specs but yeh the standard looks ok but even 2CPU/4GB RAM will only just get cTrader running but can choke if a few cBots running especially more so as time passes and cTrader eats into RAM/CPU for inexplicable reasons only cleared by a restart of the VPS

No worries on the advice.

I can say I currently have that 2CPU/4GB package deal from NYC Servers and it runs cTrader great for me.

On the VPS, I actually run TWO copies of cTrader at the same time running the same bot. However, I have 26 instances of the bot running (13 instances running between each running copy of cTrader).

Here's a capture of the performance stats (these two cTraders have been running the bots for over 24 hours straight now):

So as you can see, with 4GB and 2CPUS, the VPS isn't hurting at all. Everything is very responsive, and I can even run other programs on there at the same time (like Google Chrome and such).

There are 2 big tricks to running cBots under cTrader so memory isn't consumed:

1) when starting the bots, don't click on each bot instance to load the chart. That causes cTrader to suck up more memory. Just click the play button and that's it.

2) don't write many Print statements. When they will up the log, cTrader really sucks up memory. Instead create some sort of log mode switch so you only print statements when you absolutely have to.

:-)


@firemyst

firemyst
15 Sep 2020, 13:27

RE:

ctid2568413 said:

@firemyst, this might be what I am missing. Which part of the code is it to be defined?

 

@PanagiotisCharalampous, possibly the above will solve it.

I can't tell where because I don't have your code, but you should do it wherever you check the conditions.

For example:

//check the symbol and time frame are the same as what's on the current chart this indicator is attached to.

if (Bars.TimeFrame == Chart.TimeFrame && Symbol.Name == Bars.SymbolName)
{
    //You know both the symbol and timeframe match, so this is where you do what you need to.
}
else
{
    //this is some other symbol name / timeframe combo
}

 


@firemyst

firemyst
15 Sep 2020, 07:07

Are you sending up the alert based on Symbol and not Symbol/Timeframe combination?

 


@firemyst

firemyst
15 Sep 2020, 06:04

Hi @MaxT:

“Is it possible to run two (or more!) cTrader installations logged into the same account on separate servers running the same cBots?”

Yes in that I have bots running on a VPS and while they are running, I have also had them running on my local home desktop machine connected to the internet.I've even done it with same instance pairs and same time frame.

I can't say anything in regards to syncing with OneDrive as I wouldn't do that:

1) it can cause lots of network lag

2) OneDrive isn't 100% guaranteed uptime

3) if you're running on more than one computer, syncing to the same OneDrive, who knows what kind of file bashing/hashing/coordination has to go on, how long that takes, and if the delay is significant, can certainly halt cTrader if it doesn't get enough network bandwidth or fast enough speeds when writing to the local disk.

What I do is just drag/drop the c:\Documents\cAlgo|cTrader folders over to a local backup drive. Takes maybe 5 minutes to copy (if that).

 

The other thing you might consider doing is switching VPS providers. I currently have an account with NYC Servers, and they have been fantastic.

If you sign up through the above link, they offer special discounted rates for numerous brokers such as Pepperstone, IC Markets, and others.

Just scroll down the page to the section "VPS Service By Broker", select your broker, and go for the special rate. For example, as of this post, you can get a standard VPS:

  • Runs 4-6 accounts
  • 2 CPU cores
  • 4GB ram
  • 40GB SSD storage
  • 100% uptime guarantee

for 1/2 price if you're with either Pepperstone or IC Markets. That's more than enough to run both cTrader and MT4/MT5 EA's.

Make sure you scroll down to the bottom of the NYC Servers page though to the "VPS Service By Broker" section to get the special rates.

Most people miss that.

Good luck.

 


@firemyst

firemyst
15 Sep 2020, 04:41 ( Updated at: 21 Dec 2023, 09:22 )

RE:

ftmo91598958384 said:

Hello, I am having trouble increase my lot size on XAGUSD above 500. Every time I attempt to increase the lot size, the box is shaded red unless its below 500. Does anyone know how to fix this as I have missed a few trades today cause of this problem.

 

Thank you

Are you going over your margin levels? I don't see them on the screen. If you're increasing your size and it takes you above your allowed margin level, you won't be allowed to.


@firemyst

firemyst
09 Sep 2020, 15:29

RE:

PanagiotisCharalampous said:

Hi firemyst,

You cannot clear the logs via the API, only manually.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks @Panagiotis.

Are there any future plans you're aware of to allow this?

 


@firemyst

firemyst
09 Sep 2020, 06:18

RE: RE: RE:

luca.tocchi said:

firemyst said:

luca.tocchi said:

how do i check the direction of the moving averages in real time and if they go high i go buy if they go low i sell?

Thanks a lot

You get the current value of the MA and can compare it to the previous value to see if it's increasing or decreasing.

//example pseudo-code
if (ma.Result.Last(0) > ma.Result.Last(1))
    //open long position 
else if (ma.Result.Last(0) < ma.Result.Last(1))
    //open short position
else
   //the ma values are equal. What do you want to do?

 

Yes sure

but I have to check 3 moving averages, if all 3 are up go buy, if all 3 are down go sell

but if at least one of these averages goes in the opposite direction, the program must wait for all three to go in the same direction

I would be grateful if you could help me

Then do the same thing for the 3 moving averages:

//example pseudo-code

if (ma1.Result.Last(0) > ma1.Result.Last(1)
    && ma2.Result.Last(0) > ma2.Result.Last(1)
    && ma3.Result.Last(0) > ma3.Result.Last(1))
    //open long position 

else if (ma1.Result.Last(0) < ma1.Result.Last(1)
    && ma2.Result.Last(0) < ma2.Result.Last(1)
    && ma3.Result.Last(0) < ma3.Result.Last(1))
    //open short position

else
   //the ma averages are all not going in the same direction. What do you want to do?

 


@firemyst

firemyst
07 Sep 2020, 05:41

RE:

ctid2033788 said:

1. When I call the Position.ModifyStopLossPips(stopLossPips), the stop loss for the Position should be updated to the value passed into the method but it is not?

Currently, If I pass in -2 for a buy position, the stop loss is set to 2 pips above Entry Price.

If I pass in 2 for a buy position, the stop loss is set to 2 pips below Entry Price.

This seems to be backwards.

 

Also

2. If I pass in 2 for a sell position, the call returns a TradeResult object that has a failure with the message InvalidStopLossAndTakeProfit.

What would be causing that?

1) It might not be updated for any number of reasons. For example, what if the SL is moved to be within the symbol's spread? What if you're trying to move the SL by a very small or invalid amount?

-2 vs 2 might seem backwards, but that's how it works.

 

2) Again, where are you placing your SL in relation to the current bid/ask price? Or from it's last location? Have you noted what the old value was, what the old value is you want to move it to, and looked at the charts to see if it is valid? If you're in a sell, are you trying to move the SL below the bid price? If you're in a buy, are you trying to move the SL above the ask price?

You need to post code if you still can't figure it out.


@firemyst

firemyst
05 Sep 2020, 16:01

That's what cTrader does by default.

If it's not, then:

1) you might be running cTrader on multiple computers using the same workspace, and thus the "last one to save wins", meaning it could be overwriting your bot instances.

2) Try uninstalling and reinstalling cTrader.

3) Tag @Panagiotis as he can help you resolve the issue if the above two points don't.


@firemyst

firemyst
05 Sep 2020, 15:59

Easy code, but I would look in the "cbots" section on algorithms as I'm sure there's already numerous similar ones programmed.


@firemyst

firemyst
05 Sep 2020, 15:53

Yes.

Create a class inside your cBot with all the properties/values you want to save.

Serialize it to json and save it to a text file.

Or if you want it in excel, write to a CSV file and then manually import into excel.

 


@firemyst

firemyst
05 Sep 2020, 15:51 ( Updated at: 23 Jan 2024, 13:16 )

RE: New creation, Prophetie for a +200% return over 2 years.

brasjulianescobar said:

Hey everyone, check out my new creation on [https://ctrader.com/algos/cbots/show/2316].

If you have any suggestion, please comment! :)

 

Thank you, happy trading!

 

How about posting a link that actually works? :-)


@firemyst

firemyst
05 Sep 2020, 15:49

RE:

surangawije77 said:

Hi I need to convert this MA fill indicator  (MA ribbon)  built for MT4 into ctrader. can anybody help me pls

 

Are you able to post a screen capture of what the end result should look like?


@firemyst

firemyst
04 Sep 2020, 09:48 ( Updated at: 21 Dec 2023, 09:22 )

RE:

ghazisameer said:

Please explain how I can delete custom indicators from CTrader indicator list. My list of indicators in the Custom list is getting way too big.

 

In cTrader v 3.x: go into the automate tab on the left side, switch to "indicators" instead of "bots", find the indicator you want to delete, and then delete it.

 


@firemyst

firemyst
04 Sep 2020, 09:43 ( Updated at: 21 Dec 2023, 09:22 )

RE:

DelTrader said:

Good night,

How can i mark the chart where breakeven is? (Imagining the price will continue goes up)
There is order of loss (Sell) and two of profit (Buy).
In the possibility of adding another order, the current breakeven update this Symbol, eg EURUSD.

Im sorry for my English!

Thank you so much

When you calculate the break-even point, use Chart.DrawHorizontalLine to draw a line across the chart.


@firemyst

firemyst
04 Sep 2020, 09:39

RE:

myinvestmentsfx said:

Hi Guys,

I just want to establish whether or not its normal to wait 10 seconds+ to collect Mutli Symbol, Multi Timeframe information from the MarketData.GetSeries API.

See code below used as an example (Apologies code still a bit messy), once I enter the loop, to get past the first task in the loop can take up to 10 seconds.

I understand that latency, bandwidth and computing power all play a roll in the overall speed the code will execute.  But from my testing it points to Multi Symbol, Multi Timeframe API's that's a little slow.  If spotware can have a look it will be greatly appriciated.

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        ////////////////////////////////////////////////////////////////////////////////
        ///                        USER PARAMETERS                                   ///
        ////////////////////////////////////////////////////////////////////////////////
        protected override void Initialize()
        {
            PAIR_ANALYSIS();
        }

        public override void Calculate(int index)
        {
        }

        private void PAIR_ANALYSIS()
        {
            ////////////////////////////////////////////////////////////////////////////////
            ///             CHECK PAIR UP FOR TODAY & CHECK ATR REACHED                  ///
            ////////////////////////////////////////////////////////////////////////////////

            var start_time = Server.Time;
            double hposition = 1;

            List<Symbol> _all_symbol_codes = new List<Symbol>();
            List<MarketSeries> _all_symbol_daily = new List<MarketSeries>();
            List<MarketSeries> _all_symbol_5min = new List<MarketSeries>();
            List<AverageTrueRange> _all_symbol_atr_daily_indicator = new List<AverageTrueRange>();
            List<double> _all_atr_daily_results = new List<double>();
            List<double> _all_daily_last_opens = new List<double>();
            List<double> _all_5min_last_opens = new List<double>();
            List<double> _all_daily_last_highs = new List<double>();
            List<double> _all_daily_last_lows = new List<double>();
            List<double> _all_daily_high_minus_daily_atr = new List<double>();
            List<double> _all_daily_low_add_daily_atr = new List<double>();
            List<string> _all_price_up_down = new List<string>();
            List<string> _atr_reached_not_reached = new List<string>();
            List<string> _all_symbol_names = new List<string>();

            _all_symbol_codes.InsertRange(_all_symbol_codes.Count, new Symbol[] 
            {
                MarketData.GetSymbol("EURUSD"),
                MarketData.GetSymbol("GBPUSD"),
                MarketData.GetSymbol("USDCHF"),
                MarketData.GetSymbol("USDJPY"),
                MarketData.GetSymbol("USDCAD"),
                MarketData.GetSymbol("AUDUSD"),
                MarketData.GetSymbol("GBPJPY"),
                MarketData.GetSymbol("EURJPY"),
                MarketData.GetSymbol("NZDUSD"),
                MarketData.GetSymbol("AUDJPY")

            });
            for (int index = 0; index < _all_symbol_codes.Count; index++)
            {
                var Step_1 = Server.Time;
                Print("The Server Time Start Loop: {0}", Step_1 - start_time);
                _all_symbol_daily.Add(MarketData.GetSeries(_all_symbol_codes[index], TimeFrame.Daily));
                var Step_2 = Server.Time;
                Print("The Server Get MarketData For Daily Timeframe Step 1: {0}", Step_2 - start_time);

                _all_symbol_5min.Add(MarketData.GetSeries(_all_symbol_codes[index], TimeFrame.Minute5));
                _all_symbol_atr_daily_indicator.Add(Indicators.AverageTrueRange(_all_symbol_daily[index], 5, MovingAverageType.Exponential));
                _all_atr_daily_results.Add(_all_symbol_atr_daily_indicator[index].Result.LastValue);
                _all_daily_last_opens.Add(_all_symbol_daily[index].Open.Last(0));
                _all_daily_last_highs.Add(_all_symbol_daily[index].High.Last(0));
                _all_daily_last_lows.Add(_all_symbol_daily[index].Low.Last(0));
                _all_daily_high_minus_daily_atr.Add(_all_daily_last_highs[index] - _all_atr_daily_results[index]);
                _all_daily_low_add_daily_atr.Add(_all_daily_last_lows[index] + _all_atr_daily_results[index]);
                _all_5min_last_opens.Add(_all_symbol_5min[index].Open.Last(0));
                hposition -= 0.1;

                if (_all_daily_last_opens[index] > _all_5min_last_opens[index])
                {
                    _all_price_up_down.Add(_all_symbol_codes[index] + " | " + "Down");

                }
                else
                {
                    _all_price_up_down.Add(_all_symbol_codes[index] + " | " + "Up");
                }

                if ((_all_daily_last_highs[index] > _all_daily_low_add_daily_atr[index]) || (_all_daily_last_lows[index] < _all_daily_high_minus_daily_atr[index]))
                {
                    _atr_reached_not_reached.Add("ATR Reached");
                }
                else
                {
                    _atr_reached_not_reached.Add("ATR --NOT-- Reached");
                }
            }
            string _all_price_up_down_results = string.Join("\n", _all_price_up_down);
            string _all_atr_reached_not_reached = string.Join("\n", _atr_reached_not_reached);

            ChartObjects.DrawText("UP or Down", _all_price_up_down_results, StaticPosition.TopLeft, Colors.Blue);
            ChartObjects.DrawText("ATR", _all_atr_reached_not_reached, StaticPosition.TopCenter, Colors.Green);

            _all_symbol_daily.Clear();
            _all_symbol_5min.Clear();
            _all_symbol_atr_daily_indicator.Clear();
            _all_atr_daily_results.Clear();
            _all_daily_last_opens.Clear();
            _all_daily_last_highs.Clear();
            _all_daily_last_lows.Clear();
            _all_daily_high_minus_daily_atr.Clear();
            _all_daily_low_add_daily_atr.Clear();
            _all_5min_last_opens.Clear();
            _all_price_up_down.Clear();
            _atr_reached_not_reached.Clear();
        }
    }
}

Kind Regards,

 

It could depending on your connection and the response time of the cTrader servers.

What you might consider doing is using "MarketData.GetBarsAsync" instead. So then you can process each atr and show it as its data comes in. Otherwise, you have to wait until everything is received before data is shown.


@firemyst

firemyst
04 Sep 2020, 09:37

RE:

kdcp999 said:

I am trying ti figureout how to initialise multipl MACDCrossover Indicators for differen timeframes?

Because the MacdCrossover indicator takes a DataSeries which doesn't seem to be created based on any given time frame how do you acheive this?
 

      DataSeries _data_series = Robot.CreateDataSeries();
   
       MacdCrossOver_indicator = Robot.Indicators.MacdCrossOver(
         _data_series,
         LongCyclePeriod,
         ShortCyclePeriod,
         SignalPeriod
      )
       

//no time frame indication here.




How does the MACDCrossover know that you want  a 4hour macdcrossover indictor as apoosed to a 2 hour MacdCrossover indicator?

Any help would be muchaprreciated.

David

It knows based on the data series you pass into it.

Instead of creating a data series, you need to pass it one.

Example:

MarketData.GetBars(Bars.TimeFrame, Symbol.Name).ClosePrices

 


@firemyst

firemyst
04 Sep 2020, 09:07 ( Updated at: 21 Dec 2023, 09:22 )

RE:

WienAT said:

Dear all,

I am testing one bot and there is one thing that is not really clear to me:

I open position with following command: 

ExecuteMarketOrder(TradeType.Buy, position.SymbolName, volume, "Buy");

Since there is no option that I execute trade with already setted SL price and TP price (i do not want to set number of pips for TP and SL) I am doing following:

                            Positions[Positions.Count - 1].ModifyStopLossPrice(entrypositionprice);
                            Positions[Positions.Count - 1].ModifyTakeProfitPrice(takeprofitprice);

In this case both SL price and TP price are correctly moved. I see also in debugger Visual Studio:

But if I check my console in Ctrader i see following:

What could be wrong?

 

Regards

What could be wrong if you could have multiple positions open, which I can see from your bottom screen capture you do.

How do you know what position is in "Positions[Positions.Count - 1]"?

When you increase a position size, or open a new position, the position of your "Buy" position could change in the Positions object.

So you need to check the name of the position at "Positions[Positions.Count - 1]" or you need to search the Positions object for your specific label "Buy".

Example:

Position myPosition = Positions.Find("Buy", Symbol.Name);

 

 


@firemyst

firemyst
04 Sep 2020, 09:03

RE:

Mr4x said:

Hi,

I have what I think is a fairly simple request but cannot for the life of me figure it out.

I am basically looking to have an expression built in to my bot that allows me to execute only buy trades when market is above moving average, and only sell trades when market is below a defined moving average. There is no requirement to close any open trades when crossing the MA or anything like that.

I have tried building one using the code in the Sample Trend cBot included with cTrader but the problem is it will still only let me place one trade in either direction when moving average is crossed. It also uses a fast and slow moving average, which is irrelevant to me as I only need 1 moving average

So for example:

 

if CurrentMovingAverage <= DefinedMovingAverage

ProcessSell();

if CurrentMovingAverage >= DefinedMovingAverage

ProcessBuy();

 

I can provide more code if required for context / troubleshooting.

Many thanks,

Mr4x

You need to say:

//In your OnTick or OnBar event for bots depending on whether you want to check every tick or every bar

if (Bars.ClosePrices.Last(0) > MovingAverage.Result.Last(0))
{
   //the code to execute when price is above the moving average
}
else if (Bars.ClosePrices.Last(0) < MovingAverage.Result.Last(0))
{
    //the code to execute when price is below the moving average
}
else
{
   //what you want to do, if anything, when the MA == the currency closing/tick price.
   //rare event, but could happen so have to account for it!
}

 


@firemyst