Topics
Replies

firemyst
27 Apr 2023, 04:56

One thing to try that's happened to me in the past, is:

  1. put some indicators on the chart (a moving average, bollinger bands, etc) Just use the default settings
  2. try putting a horizontal and/or vertical line drawing on your chart as well
  3. scroll your chart. Change timeframe and scroll the chart again.

if you scroll your chart and the indicators  / lines do not move, then it's a bug with the Intel GPU drivers. This is known and has happened to me in the past. Update the Intel GPU drivers, restart cTrader, and hopefully it'll go away (as it did for me).

 

The other time something similar happened to me is when Windows automatically updated my computer in the background, and it was waiting for a pending restart. Once I restarted, it worked fine. So maybe check that as well.

 

If neither of these suit you, hopefully @Spotware can lend some insight. Great that you posted the video.

 


@firemyst

firemyst
27 Apr 2023, 04:49

Sample code snippets to get the size of the previous candle:

private Bars bars;

// In your OnStart or Initialize method depending on whether cBot or indicator
bars = MarketData.GetBars(Chart.TimeFrame);


//In the Calculate, OnTick, or OnBar method depending on whether indicator or cBot and when you want to know the difference
//If you want the body size
double differenceInPips = Math.Abs(bars.OpenPrices.Last(1) - bars.ClosePrices.Last(1)) / Symbol.PipSize;

//If you want the entire candle. No Math.Abs function needed
double differenceInPips = (bars.HighPrices.Last(1) - bars.LowPrices.Last(1)) / Symbol.PipSize;

 

 

Check out code samples to see how to place the order you want:
https://help.ctrader.com/ctrader-automate/cbot-code-samples/

 


@firemyst

firemyst
26 Apr 2023, 03:41 ( Updated at: 21 Dec 2023, 09:23 )

I'm not sure why you think this is an issue?

If you look on topfx website, they don't have USDHKD listed as a currency pair they allow users to trade, so that error is expected:

 

 

If you want to trade USDHKD, it looks like you'll have to change brokers, or ask them if they can enable it for you.

Good luck.


@firemyst

firemyst
25 Apr 2023, 15:16

You may need to check if the SL or TP value is null along with changing the order of comparisons in the "if" statements.

 

if (distance >= BETrigger * Symbol.PipSize)
                {
                    if (position.TradeType == TradeType.Buy)
                    {
                        //you need to check if StopLoss is null first because if it is null, the position.Stoploss <= ... 
			//will fail because it can't compare a null against an actual value
                        if (position.StopLoss == null || position.StopLoss <= position.EntryPrice + (Symbol.PipSize * BEExtraPips))
                        {
                          //I personally would also change this call to the following 
                          //so you're covered with the TakeProfit as well                           
                          ModifyPosition(position, position.EntryPrice + (Symbol.PipSize * BEExtraPips), (position.TakeProfit == null ? null : position.TakeProfit.GetValueOrDefault()));
                        }
                    }
                    else
                    {
                        if (position.StopLoss == null || position.StopLoss >= position.EntryPrice - (Symbol.PipSize * BEExtraPips))
                        {  
                          ModifyPosition(position, entryPrice - (Symbol.PipSize * BEExtraPips), (position.TakeProfit == null ? null : position.TakeProfit.GetValueOrDefault()));
                        }
                    }
                }
            }
        }
        
    }
}

 


@firemyst

firemyst
25 Apr 2023, 09:30

Try cleaning cTrader's cache.

 

See the last post in this thread on how to do it:

 


@firemyst

firemyst
25 Apr 2023, 09:28

Why should they keep running?

 

cTrader is the 'host' running your bots.

 

If you shut down Microsoft Windows, does cTrader keep running?

If you shut down Microsoft Windows, do any of your open Windows applications (Microsoft Word, Google Chrome, etc) keep running?

No. Because Windows is the 'host' that's running them.

 

 

 

 

 


@firemyst

firemyst
25 Apr 2023, 09:22

RE:

alfonsojjg said:

Hi,

I want to calculate the number of positios opened in both directions, longs and shorts, anyone khows how to code it?

Thanks.

 

 


@firemyst

firemyst
25 Apr 2023, 09:20

When you do this:

valor = sma.Result.Last(0);

it calls the Calculate method in the indicator.

You have a print statement in that method in your indicator.


@firemyst

firemyst
23 Apr 2023, 06:56

The error message is what's wrong.

You need to add a reference to System.Management.dll to your Indicator project.

https://ctrader.com/api/guides/referencing_dll#:~:text=In%20order%20to%20add%20a,your%20cBot%20or%20Custom%20Indicator.

 

 

 

 

 


@firemyst

firemyst
22 Apr 2023, 09:50 ( Updated at: 21 Dec 2023, 09:23 )

Step 1 - Search forums:

 

Step 2, click result:

 

Step 3: implement solution as appropriate for what you want to do

 

:-)

 


@firemyst

firemyst
21 Apr 2023, 11:10

Try the solution here:

 


@firemyst

firemyst
21 Apr 2023, 11:09 ( Updated at: 21 Apr 2023, 11:11 )

What are you expecting to appear?

The Nasdaq is an index cfd.


@firemyst

firemyst
21 Apr 2023, 09:03

RE:

Spotware said:

Dear trader,

Unfortunately we were not able to reproduce this problem. Please provide us with the following information

  • Please share the logs of each application.
  • Please let us know which workspace you use in each application
  • After you share the above information here, send us troubleshooting from both machines the next time this happens. Add a link to this discussion in the description.

Best regards,

cTrader Team 

Hi everyone / @Spotware:

The issue appears to be resolved now.

What I had to do is the following:

1) Go into cTrader settings

2) General tab

3) click Reset local data to default

It took a little while to reload everything, but all the missing trades I was aware of are now showing on both my VPS and local laptop.

Thank you

 


@firemyst

firemyst
21 Apr 2023, 05:12

First of all, the error message says, "Access Denied". So have you tried granting your cBot full access?

Ex:

 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]

 

Second, if that doesn't work, and you've already added it as a "reference" to your solution in cTrader, then you'll probably have to use the DLL Import directive in C#.

And for that, I suggest you try using Google to find examples as there's plenty out there.

 

Blah blah blah :-)

 


@firemyst

firemyst
20 Apr 2023, 14:49

What do you do in your OnBar code? Can you post your code?

Does you bot use any indicators that have a volume parameter?

 


@firemyst

firemyst
20 Apr 2023, 05:33

In a nutshell you don't if you're using the built in cTrader API.

You should use HorizontalAlignment and VerticalAlignment properties and whether it's Chart.DrawStaticText or Chart.DrawText methods.

If you don't like those options, then you can create a Windows Panel object with Labels/Text and place that on the chart. I can't tell you how to do that offhand, but I'm sure there are examples to be found.


@firemyst

firemyst
20 Apr 2023, 05:29

First, you'll probably want to get the current index:

int lastIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes.LastValue)

Then you can loop over the last 5 indexes:

int low = Int32.MaxValue;

for (int x=lastIndex - 5; x <= lastIndex; x++)

{

  if (Bars.LowPrices[x] < low)

    low = Bars.LowPrices[x];

}

 

The above is all pseudo code so may not work exactly as is since I'm not in front of anything other than a tablet typing this.

If you want to find the index of another bar, assuming you're on a chart that's based on time (eg, not Renko or Range bars), then in the call to Bars.OpenTimes.GetIndexByTime, provide the time of the bar that you want.

Hope that helps?


@firemyst

firemyst
19 Apr 2023, 09:09

No idea why you posted this when you already can:

 

 

 


@firemyst

firemyst
19 Apr 2023, 09:06

 


@firemyst

firemyst
19 Apr 2023, 09:06

Then look in the cBot repository:

 

 

 


@firemyst