Topics
Replies

firemyst
14 Oct 2023, 15:34

To get the index of the bar where the latest position was opened:

Position p; //get your position information

//then get the index:

int barIndex = Bars.OpenTimes.GetIndexByTime(p.EntryTime);
 


@firemyst

firemyst
14 Oct 2023, 12:52

Numerous people.

 

You can start with @PanagiotisChar


@firemyst

firemyst
07 Oct 2023, 13:28 ( Updated at: 08 Oct 2023, 06:03 )

I suspect the cTrader team would only include support for .Net 8 and skip over the odd numbers. 

As a product manager, why build in support for a product that Microsoft has said will only have a short term life span of just over a year?

.Net 8.0 will have long term support, and thus should have a life span until at least Nov 2026.

https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-and-net-core

 


@firemyst

firemyst
02 Oct 2023, 08:04

Take the date of the opening time of the bar before, and the first bar after.

 

then find the difference between the two, divide by 2, and add that to the opening time of the bar before the midpoint.

 

Ex:

open time to bar before is Sept 15, 6pm

open time of bar after is Sept 15, 8pm

Difference between them is 2 hours

2 / 2 == 1

6pm + 1 == 7pm.

 


@firemyst

firemyst
17 Sep 2023, 12:09

That's a paid indicator, so ask the person you bought it from.

My first guess is:

  1. oscillator lookback period is how many periods back it looks for divergence on an oscillator
  2. Lookback period is how many periods it looks back for divergence on the main chart

 


@firemyst

firemyst
16 Sep 2023, 14:58

Yes. 

Add one onto your chart like any other indicator.


@firemyst

firemyst
11 Sep 2023, 18:35

Another option you have is the following:

  1. hard code a date in your indicator/bot that's a day or two in the future
  2. check the date in your code against the Server.Time object
  3. if the server's time is > the time you have hard-coded in your code, have your code do nothing. 

Example for a starting point. You'll obviously have to tweak it to fit your needs:

                    if (Server.TimeInUtc > new DateTime(2023, 9, 13))
                       return;
 

Since the cAlgo files are encrypted, nobody should hypothetically be able to crack and adjust your code; and they shouldn't be able to backwards adjust the Server's time either to bypass your time constraint because if they can, Spotware would have a gaping security hole there. 


@firemyst

firemyst
11 Sep 2023, 18:27

//For longs
if (Bars.LowPrices.Last(0) > yourPosition.EntryPrice)
{
    int newStopLoss = Bars.LowPrices.Last(0);
    TradeResult r = yourPosition.ModifyStopLossPrice(newStopLoss);
    if (r.IsSuccessful)
      ...
    else
        ...
}

@firemyst

firemyst
11 Sep 2023, 18:21

When an exception happens, write out the values of any variables you want to a text file; then next time you start your bot, read the values in from the text file if it exists.

the text file can be saved as JSON data, CSV, or any other formats that you want to work with.


@firemyst

firemyst
30 Aug 2023, 07:59

You'd have a better chance of a response if you post more of your code that reproduces the problem.


@firemyst

firemyst
27 Aug 2023, 15:26

You need to do something like this:

                    ChartText ct = Chart.DrawText("FB_Signal" + index, textFB, index, yFB, colorFB);
                    ct.VerticalAlignment = VerticalAlignment.Center;
                    ct.HorizontalAlignment = HorizontalAlignment.Left;

Play wit the Vertical and Horizontal alignments.


@firemyst

firemyst
27 Aug 2023, 15:22 ( Updated at: 27 Aug 2023, 15:23 )

I think your logic in both loops is wrong because you're changing the average price every time you do the loop.

That is, look at #1. When you have 10 positions open and the averagePrice (in pips) is < -10, you modify one position.

Then you do another loop and calculate the average again. The average will change because you've already modified one position. 

Same with #2. The average will change each time when you close a position.

What you should do is calculate the average once with all the current positions, and then do you loop. This way, the average won't change on each loop iteration.

For example:

double averagePrice = Positions.Average(x => x.Pips);
if (averagePrice > 11){    
    foreach (var position in Positions)    
    {            
        ClosePositionAsync(position);     
    }
}

@firemyst

firemyst
26 Aug 2023, 19:37 ( Updated at: 27 Aug 2023, 05:33 )

You've posted this in the wrong forum.

You need to post suggestions in the “Suggestions” forum:

https://ctrader.com/forum/suggestions

 


@firemyst

firemyst
23 Aug 2023, 02:06 ( Updated at: 24 Aug 2023, 05:01 )

You need to post this in the correct forum:

https://ctrader.com/forum/suggestions

 


@firemyst

firemyst
22 Aug 2023, 11:27 ( Updated at: 21 Dec 2023, 09:23 )

@Spotware, any ideas or updates? Able to reproduce?

I tried again today on the Ger40 Renko 5 chart.

I changed the above code from:

double ma1LastResult = Math.Round(ma1.Result.Last(1), Symbol.Digits);
            double ma2LastResult = Math.Round(ma2.Result.Last(1), Symbol.Digits);

to:

double ma1LastResult = Math.Round(ma1.Result.Last(1), 2);
            double ma2LastResult = Math.Round(ma2.Result.Last(1), 2);

and still get values that differ between the .Last(1) outputs and the Market Snapshot tool today as shown below:

Times are UTC + 8

 

I would expect the output from ma1.Result.Last(1) to be the same, or at least within mathematical rounding distance of the displayed value on the chart. 

In the case of the 4 EMA, calgo returns a value that differs by 20% of a pip. This difference certainly shouldn't be acceptable.

Thank you.


@firemyst

firemyst
21 Aug 2023, 23:22

Do the following that's posted in this thread:

https://ctrader.com/forum/calgo-support/41644

 


@firemyst

firemyst
21 Aug 2023, 01:41

Everything you've done seems legit to me. The OnException probably isn't being called because it might not be anything to do with your code, but rather a bug in cTrader itself.

There are two more things you can try:

  1. put individual try/catch blocks around each assignment statement in your OnStart method to see if that does anything in terms of catching something. I doubt it, but you never know. 

Example:

protected override void OnStart()
{
    try {
        emaBars = MarketData.GetBars(EmaTimeFrame);
    }
    catch (Exception e) {
        print ("EXCEPTION 1! {0}", e.ToString());
    }
    try {
        ema = Indicators.HullMovingAverage(emaBars.OpenPrices, EmaPeriods);
    }
    catch (Exception e) {
        print ("EXCEPTION 2! {0}", e.ToString());
    }
    
    //etc etc
}

 

2. look in your Windows Event view logs for the big red ERROR indication. There might be a clue in there on what's happened. Either way, it would be great to post that information too because that will also help @Spotware @cTraderTeam in investigating/fixing the issue if it is indeed a bug with cTrader itself.

 

 


@firemyst

firemyst
20 Aug 2023, 13:18

This is another good indicator:

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

 


@firemyst

firemyst
20 Aug 2023, 13:17

Why would they do it? You've posted in the “suggestions” forum - this isn't the place to report technical issues.

You need to post in one of the other forums.


@firemyst

firemyst
20 Aug 2023, 13:08

You need to post this in the “Suggestions” forum.


@firemyst