Topics
Replies

firemyst
17 Nov 2021, 13:15

You have error in the bolded code:

 

   if (Histogram boo 0 % prevHistogram < 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
            else if (Histogram < 0 % prevHistogram > 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
 

I *think* you want the following:

 

 

  if (Histogram > 0 && prevHistogram < 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
            else if (Histogram < 0 && prevHistogram > 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }

 


@firemyst

firemyst
28 Oct 2021, 10:21

RE: RE: RE: RE: RE: RE: RE: RE:

yuval.ein said:

My original single symbol cBot has dozens of private members (strings, integers, etc.). All those members were designed for a single symbol. Now that there are many symbols, each of them should have a different value per symbol. Is there an easy straight forward way to convert all the members from single to multi symbol?

 

Thanks

 

Yes.

 

Add [] onto the end of them to declare them as arrays.

int[]

double[]

etc etc

[0] is the first symbol's value, [1] is the second symbol's, so on and so forth. Hopefully after that, you won't have to make too many other changes to your code depending on how it's written.


@firemyst

firemyst
26 Oct 2021, 05:45

RE: RE: RE: RE: RE: RE:

yuval.ein said:

What if I want to use OnTick for more than one symbol?

 

Thanks

All you have to do is subscribe to the Tick event for each symbol you want.

This thread talks about it for indicators, but it's the same for cBots:

 

Example: Bars.Tick += YourOnTickEventMethod;


@firemyst

firemyst
25 Oct 2021, 15:55

RE: RE: RE: RE:

 

Hey 

I got your email and tried to reply but my reply bounced. 

Any other email address I can use to mail you?

 

 

Yes. If you look, that stupid email service provider puts in their own reply to email address. I'll send you another message with a different email in there.


@firemyst

firemyst
25 Oct 2021, 13:28

RE: RE:

charltonadams38 said:

firemyst said:

Okay, I'll bite. Do you have an email address where I can contact you?

Hi, my email address is charltonadams38@gmail.com.

 

Sent you an email and haven't received a reply, so wanted to make sure you've received it?


@firemyst

firemyst
25 Oct 2021, 13:27

RE:

xabbu said:

thanl you very much, @firemyst, for your kind reply.

can you or the cTrader support team help me to understand, how I can implement this or a similar logic for m1 into a Renko cBot?

Kindest regards and a great and successful week,

I do not use Renko charts, so won't be able to help you there.


@firemyst

firemyst
23 Oct 2021, 18:06

RE:

pvu84pvu said:

Need to get indicator values for another symbol-timeframe. But not all indicators have DataSeries or Bars parameter in definition.

OK:

MovingAverage(DataSeries source, int periods, MovingAverageType maType)

BollingerBands(DataSeries source, int periods, double standardDeviations, MovingAverageType maType)

AcceleratorOscillator(Bars bars)

MISSING:

Alligator(int jawsPeriods, int jawsShift, int teethPeriods, int teethShift, int lipsPeriods, int lipsShift)

AverageDirectionalMovementIndexRating(int periods)

CenterOfGravity(int length)

 

Am I missing something?

How can I get Alligator values for another symbol-timeframe?

To answer your first question, probably inexperience and lack of forward planning in their leadership team that develops built in indicators.

For instance, the Alligator is essentially 3 moving averages, so it's no more difficult for their indicator-team to add in a data-source to the Alligator indicator than it apparently is for the same team to add the "shift" parameter to their MovingAverage indicator (notice you can add "shift" to the Alligator, but not the MA?? Like that makes any sense?) .

It's API inconsistency at its finest.

 

 


@firemyst

firemyst
23 Oct 2021, 17:59

The following business logic should help with finding it on say a M1 chart:

 

1) get the index of the open time of the bar when the position was opened. Ex: Bars.OpenTimes.GetIndexByTime(position open time);

2) get the index of the bar in which the position was closed. Ex: Bars.OpenTimes.GetIndexByTime(position close time);

3) loop from start to finish, checking the high and low of every bar in between the open and close time indexes you obtained in steps 1 and 2 above


@firemyst

firemyst
22 Oct 2021, 04:03

Okay, I'll bite. Do you have an email address where I can contact you?


@firemyst

firemyst
22 Oct 2021, 03:30

RE:

amusleh said:

Hi,

Most probably we will support officially Visual Studio 2022 after cTrader 4.2 release.

Are you able to provide an ETA or timeline on this? For all we know, cTrader 4.2 could be out next month, or 6 months, or even 12 months from now.

And then since you say we have to wait until after that release, we might have to wait yet another 12 months.

Thank you.


@firemyst

firemyst
27 Sep 2021, 08:54

Use "Chart.DrawText" and put in your "level" parameter for the "double y" parameter.

Eg:

Chart.DrawText("line_2_text", "here is my text I want to draw", theBarIndex, level, Color.Red);


@firemyst

firemyst
24 Sep 2021, 03:41 ( Updated at: 21 Dec 2023, 09:22 )

RE:

ome9emmy said:

Good day CTrader developers can we get a breakeven button while using the manual strategy backtesting. And also multi chart mode to switch between two different timeframe. ????❤️

THe latter you already have:

Just click the different time frame to change the chart.

 

The former -- you don't explain what you want. OKay. You want a button labelled "break even". So what do you expect it to do? What do you want it to do and when?

You're very vague, and need to be more specific when posting questions/requests.


@firemyst

firemyst
24 Sep 2021, 03:37 ( Updated at: 21 Dec 2023, 09:22 )

RE:

vmtxd07 said:

Hi all.

I'm seeing the code in Automate of ctrader. I don't know how to get value of the Source after choose etc, Open or Close or High ...

I know DataSeries Source will return Source of bar will using as the data input.

Thanks !

        [Parameter("Source")]
        public DataSeries Source { get; set; }

 

 

What "value" are you trying to get?

1) The actual decimal value of the SMA? If so, then create your indicator similar to as follows:

Indicators.MovingAverage(DataSource source, int periods, MovingAverageType maType)

and get its value every time you need it.

 

2) the value of the type of source selected? Then you can use @Panagiotis' suggestion by creating your own enum:

 public enum MASource_Options
        {
            High,
            Low,
            Open,
            Close
        }

and using that as the parameter type:

 

 [Parameter("Source", DefaultValue = MASource_Options.Close)]
        public MASource_Options SMASource { get; set; }

 


@firemyst

firemyst
22 Sep 2021, 10:17

RE: RE: RE: RE: RE:

waym77 said:

firemyst said:

Have you tried passing in the MA objects in the "constructor" to your TradingPanel inner class?

You'll have to create the Constructor with the appropriate parameters.

 

Hi there, forgive me, I am not very familiar with constructor arguments.

Would it look something like below?

public TradingPanel(MovingAverage TrendMA, Robot robot, Symbol symbol, double defaultPrice, double defaultFrag, double defaultLots, double defaultRisk, double defaultStopLossPips, double defaultTakeProfitPips)
        {
            TrendMA = Indicators.MovingAverage(Bars.ClosePrices, TrendPeriods, MovingAverageType.Exponential);
            _robot = robot;
            _symbol = symbol;
            AddChild(CreateTradingPanel(defaultPrice, defaultFrag, defaultLots, defaultRisk, defaultStopLossPips, defaultTakeProfitPips));
        }

I understand I'll also have to create new parameters for values like TrendPeriods in this class.

Thanks,

For your constructor, you would just have something similar to the following:

 

//In your other outer class, create the MA object as you normally would in the OnStart method;
//then after all the MA's are created, put in your 
var tradingPanel = new TradingPanel(TrendMA, this, Symbol, ...);


//Now alter your TradingPanel class similar to the following.
public class TradingPanel : CustomControl
{

private MovingAverage _trendMA;

//All classes I believe have to have the default constructor
public TradingPanel() {}

public TrandingPanel(MovingAverage TrendMA, Robot r, Symbol s, ... )
{
    _trendMA = TrendMA;
    _robot = r;
    _symbol = s;
    // etc etc etc

}


}

 

If you can't get the above to work or it doesn't recognize the MovingAverage object declaration in the TradingPanel class, then that class probably can't reference the MovingAverage object, and you may have to ask @Panagiotis to lend his expert knowledge.


@firemyst

firemyst
22 Sep 2021, 04:41

RE:

riccardo.buttari said:

From my indicator, calling MarketData.GetSeries with a symbol other than the current one,
I get only the last 2000 most recent bars (even if I scroll the chart further back) and this does not allow me to perform backtests.
Is there a way to get more bars or set a start date?

 

Thanks

 

Try what's on this thread:

 


@firemyst

firemyst
22 Sep 2021, 04:39

RE:

hamsider said:

Hello, I try to to draw trend lines like from Day start to current index (0), Week start to current index (0) and Month start to current index (0). Any help how to get the index of Day start, Index of Week start and Index of Month Start.

Ref: 

Here the trend line is from session start to session end.

Thank you.

 

Look at this thread:

 


@firemyst

firemyst
22 Sep 2021, 04:38

RE:

PanagiotisCharalampous said:

Hi yaghouti,

At the moment commission information is not available in cTrader Automate API. Spread is not really relevant to this calculation since it is embedded in the actual price.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

 

What about this? Although you can only obtain it _after_ a position is opened:


@firemyst

firemyst
21 Sep 2021, 16:23

RE: RE: RE:

Have you tried passing in the MA objects in the "constructor" to your TradingPanel inner class?

You'll have to create the Constructor with the appropriate parameters.

 


@firemyst

firemyst
21 Sep 2021, 03:38

RE:

ctid4633759 said:

Hi, 

I am trying to create a simple calculation wherein a downtrend, a distance is measured as HighPrices.LastValue - Price, and in an uptrend the distance is Price - LowPrices.LastValue.

Without Math.Round, I get a very long decimal. With it, I get 0.

See attached code, any advice? Thanks.

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SLDisplay : Indicator
    {
        [Parameter("MA Type", Group = "MA", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Bottom)]
        public VerticalAlignment slvAlignment { get; set; }

        [Parameter("Horizontal Alignment", DefaultValue = HorizontalAlignment.Center)]
        public HorizontalAlignment slhAlignment { get; set; }

        private ChartStaticText details;
        private string _sl;

        MovingAverage FastMa;
        MovingAverage SlowMa;
        MovingAverage TrendMa;

        protected override void Initialize()
        {
            details = Chart.DrawStaticText("idtext_white", string.Empty, this.slvAlignment, this.slhAlignment, Color.White);
            FastMa = Indicators.MovingAverage(Bars.ClosePrices, 9, MaType);
            SlowMa = Indicators.MovingAverage(Bars.ClosePrices, 21, MaType);
            TrendMa = Indicators.MovingAverage(Bars.ClosePrices, 50, MaType);
        }

        public override void Calculate(int index)
        {
            _sl = GetSL();
            details.Text = "SL: " + _sl;
            details.Color = Color.White;
        }

        private string GetSL()
        {
            var trend = Bars.ClosePrices.LastValue > TrendMa.Result.LastValue ? true : false;
            var fast = FastMa.Result.LastValue > SlowMa.Result.LastValue ? true : false;
            var price = (Symbol.Ask + Symbol.Bid) / 2;
            var distance = 0.0;

            var buyorsell = trend && fast ? true : false;

            if (buyorsell)
            {
                distance = (price - Bars.LowPrices.LastValue) * Symbol.PipSize;
            }
            if (!buyorsell)
            {
                distance = (Bars.HighPrices.LastValue - price) * Symbol.PipSize;
            }

            if (distance < 0.1)
            {
                return "N/A";
            }
            else
                return Math.Round(distance, 1).ToString();
                //return distance.ToString();
        }
    }
}

 

One suggestion in your code. If you want your code to be dynamic and always round to the number of places based on the symbol you're watching, I would do:

Math.Round(distance, Symbol.Digits)

instead. So for example, if you're trading the EURUSD, it'll round to 4 digits; if trading any JPY pairs, it'll round to 2 digits; if trading the DOW or DAX, it'll round to 1 digit, etc etc.

That aside, you should read this on how to format decimal string numbers in C#:

 


@firemyst

firemyst
21 Sep 2021, 03:30

RE:

waym77 said:

Hi all, 

 

I'm having trouble using an indicator in a separate class from the Robot (Main) class.

 

In the Robot class, I have the parameters and declarations for using an EMA, but since that class is separate from the other public class in which I wish to use the EMA Result, I get an error saying ''Error CS0103: The name 'TrendMA' does not exist in the current context". 

 

I understand that this is because the EMA is local to the Main Robot class, though I'm having trouble calling the indicator into the class where I want to use it. 

 

The short of my question is then: how can I call and declare an indicator in a class that is not the Main Robot class?

Please excuse my lack of code sample, the source for this bot is long, although I can provide it on request.

 

Thanks,

In short, without seeing any sample code posted of yours:

1) you need to "reference" the class. In the cTrader Automate section when you view your bot's source code, click on the triple-dot menu to manage references and make sure it's included

2) reference your TrendMA indicator similar to the following:

TrendMA _ma = Indicators.GetIndicator<TrendMA>(the list of parameters required);

 


@firemyst