Topics
Replies

firemyst
05 Nov 2024, 06:09 ( Updated at: 05 Nov 2024, 08:02 )

Judging from your charts, are you located in the UK?

That “gap” appears to have happened when the markets start their “reset” window, which causes huge spreads.

Because of that, what you obviously need to do is check the spread on the symbol before doing anything.

//Check the spread
if (Symbol.Spread >= SomePredeterminedAmount)   
    Print ("Not doing anything! Spread greater than allowed!");
else
{   
    //Do what you normally would
}

 

The fact it's the spread can also be confirmed by looking at the “tick” chart for the same time - look how the spread suddenly at least quadrupples:


@firemyst

firemyst
05 Nov 2024, 05:46 ( Updated at: 05 Nov 2024, 08:03 )

For Commissions, you can look at these previous threads for guidance:

https://ctrader.com/forum/ctrader-algo/9495/

https://ctrader.com/forum/cbot-support/2395/

 

https://ctrader.com/forum/connect-api-support/37922/

 


@firemyst

firemyst
04 Nov 2024, 23:23

RE: ChartTrendLines don't get removed from OnDestroy() method when indicator removed from chart

AlgoCreators said: 

I think the OnDestroy function is never executed. There is no such feature in the indicators

I'm not sure where you've been, but OnDestroy() has been there since version 4.2:


@firemyst

firemyst
03 Nov 2024, 02:33 ( Updated at: 04 Nov 2024, 06:49 )

Do you have confirmation that the .algo file compiled successfully? If there was an error during compilation, it won't load.


@firemyst

firemyst
02 Nov 2024, 11:40 ( Updated at: 04 Nov 2024, 06:49 )

RE: RE: RE: RE: RE: Non -executing the OnDestroy() function

PanagiotisCharalampous said: 

AlgoCreators said: 

Spotware said: 

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?

When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines
These objects are interactive.
"IsInteractive = true;"
When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature.
I want to delete all the objects added to the chart when the indicator is deleted

Hi there,

Can you share the code you are using to delete the objects so that we can check?

Best regards,

Panagiotis

I posted example code here:

https://ctrader.com/forum/ctrader-algo/45312/

In the OnDestroy method, I set all the objects “IsInteractive” properties back to “false”, and the objects aren't removed from the chart.


@firemyst

firemyst
31 Oct 2024, 00:00

As an added step, you should also obfuscate your code before compiling it. THis way, if someone does manage to decrypt your code, it'll still be hard to figure out.

 

Visual Studio comes with a free tool as it includes a copy of PreEmptive Protection - Dotfuscator Community, free for personal use. (This free version was previously known as Dotfuscator Community Edition or Dotfuscator CE.)

 

To begin using Dotfuscator Community from Visual Studio, type dotfuscator into the Search Box (Ctrl+Q).

 

 


@firemyst

firemyst
30 Oct 2024, 23:36

RE: RE: Setting TP and SL in pips not working as expected

mmackay911 said: 

firemyst said: 

The “takeprofit” parameter in the execute market order is in Pips; you're supplying an actual price.

Replace “takeProfit” in the ExecuteMarketOrder with your parameter “TakeProfitPips”. 

OR what you need to do is convert “takeProfit” back to pips as a distance from the current candle close, which seems pointless in this scenario as you have it since TP is measured from the current “close” price when the order is placed. 

Thanks @firemyst, changing to TakeProfitPips worked a treat. Your explanation makes perfect sense. Much appreciated.

I wonder if the ExecuteMarketOrder used to be coded to expect the price, rather than pips, since ChatGPT seems to think that's how it works.

Set the pips, and then immediately call:

ModifyTakeProfitPrice()

to set the price if you want to set it by exact price instead of pips.


@firemyst

firemyst
30 Oct 2024, 06:44 ( Updated at: 30 Oct 2024, 09:56 )

RE: RE: Managing algo's from a mobile device

withnail3 said: 

firemyst said: 

Did you try googling for your answer?

This is the first result I got:

https://ctrader.com/forum/ctrader-mobile/43814/

 

Thanks, I think I tried googling a while back and didn't find much, but your link is the info I was looking for.
It's clear now, I'm using the ctrader app version from a prop firm, it doesn't show the algo option like in the example above.

 

I think it might only be available in the “Spotware” version of the app.


@firemyst

firemyst
29 Oct 2024, 06:55

Keep in mind that regardless of how Spotware/cTrader calculate the angle, the angle will vary depending on the chart's zoom level horizontally / vertically. 

It will also change as more bars appear to the right or if you scroll the chart back to the left as cTrader automatically scales the chart.

 


@firemyst

firemyst
28 Oct 2024, 23:48 ( Updated at: 29 Oct 2024, 06:25 )

Did you try googling for your answer?

This is the first result I got:

https://ctrader.com/forum/ctrader-mobile/43814/

 


@firemyst

firemyst
28 Oct 2024, 23:46

The “takeprofit” parameter in the execute market order is in Pips; you're supplying an actual price.

Replace “takeProfit” in the ExecuteMarketOrder with your parameter “TakeProfitPips”. 

OR what you need to do is convert “takeProfit” back to pips as a distance from the current candle close, which seems pointless in this scenario as you have it since TP is measured from the current “close” price when the order is placed. 


@firemyst

firemyst
27 Oct 2024, 08:53

You need to post this in the “Suggestions” forum since this is the technical support forum and Spotware won't look here for suggested improvements.


@firemyst

firemyst
27 Oct 2024, 08:51

Go scorched earth:

  1. copy your c# source code into a separate Notepad text file and save it separately.
  2. copy any other source code file affected in the solution into separate files for backup purposes
  3. delete everything from the folder, including the name of the bot/indicator itself
  4. Go into cTrader and create the new indicator/bot again from scratch
  5. open in Visual Studio
  6. Compile as is to make sure it works
  7. add any references you need to
  8. now open the file in visual studio
  9. copy and paste the source code from the backup Notepad file you created in step #1 into the .cs file
  10. try compiling again to see if it works

That should hopefully fix up or wipe out any “corruption” or otherwise bad metadata in the project you had initially created.

See if that works?


@firemyst

firemyst
24 Oct 2024, 01:22

Just glancing at your code, I noticed one way to improve it. 

The “GetTrend()” method is a waste of CPU cycles. If the trend doesn't match a “sell”, it's always going to return a “buy”. If this is actually what you want, then redo the code like follows to remove a conditional check:

private TradeType GetTrend()
{
	//Remove the first conditional check to save on CPU cycles and make your bot code
	//that few nano-seconds faster
	if (Bars.ClosePrices.Last(1) < ema200.Result.Last(1))
		return TradeType.Sell;
	else
		return TradeType.Buy;
}

@firemyst

firemyst
24 Oct 2024, 00:54

I'm not sure about a plugin situation, but you can save the toggle button states to a file, and when the file is updated have your other running cBots read/update their charts based on whatever values you have saved in the file.

 

Note that this method isn't possible if you're running bots in the cloud as I don't believe bots in the cloud can read/write files.

 

Keep us posted with the solution you implement.


@firemyst

firemyst
24 Oct 2024, 00:37

RE: RE: RE: RE: When a bot was "unexpectedly terminated", cTrader shows the bot as still running

PanagiotisCharalampous said: 

zossles said: 

PanagiotisCharalampous said: 

 

Hi firemyst,

We were able to reproduce this some days ago and we are working on a solution.

Best regards,

Panagiotis

 

It's still happening for us. Any ETA's on a fix? Another week? Month? 

We do not have an ETA unfortunately. It will be released in one of the following updates

 

Is this issues resolved in the 5.0.40 release? 

 


@firemyst

firemyst
24 Oct 2024, 00:35

Does this post need to be updated?

Title says, “5.0.40 Release Notes”

First sentence in post says, “cTrader Desktop 5.0.39


@firemyst

firemyst
23 Oct 2024, 00:39 ( Updated at: 23 Oct 2024, 04:59 )

RE: position_closed looping for all bot instances

J.Lo said: 

Still happening in 2024. i have multiple instances running. when a position closes and the position_closed event fires,  it triggers this method for all instances (although it does just close the actual trade)

I can tell because i receive the SMS's *freaked me out

In fact, i noticed this behaviour in Positions_Modified and Positions_Opened aswell

My fix 

private void Positions_Closed(PositionClosedEventArgs obj){    //step: weird bug - do not fire for symbols that are not the same - picked this up in my sms's    if(obj.Position.Symbol.Name.ToUpper() != Symbol.Name.ToUpper()) return;

 

It appears this is intended behavior because of the way the event is wired. It's wired this way because it's on the “Positions” collection, not the individual “Position”. The “positions” is all the positions, not just a singular one.

 

https://help.ctrader.com/ctrader-algo/references/Trading/Positions/Positions/#closed

 

It occurs every time a position is closed. So it doesn't matter if a position is closed from a bot, a stop loss, a take profit, or someone manually closing it. That's why there's the “args” parameter is supplied so you can filter the event based on the symbol from the “positions” collection. 

 

 


@firemyst

firemyst
17 Oct 2024, 01:45 ( Updated at: 17 Oct 2024, 04:57 )

The example code on this page needs to be updated as well. It's showing example code for “LastValue” under the “Last” property.

It has the same example (correctly) under the LastValue property.

 

https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/DataSeries/#last

TO be comprehensive, an updated example should show difference like using “.Last(0)” vs “.Last(1)”


@firemyst

firemyst
17 Oct 2024, 01:40 ( Updated at: 17 Oct 2024, 04:57 )

Depends on what you want.

You're getting the LastValue, which is value as of the moment it's taken in the current bar. As you know, values for the current bar can change depending on what the price does. 

So at the beginning of the bar for example, the top band could be one value, but then if price really skyrockets and the band expands, the top band could end up being another value by the close of the bar.

If that's what you want, fine.

Perhaps what you want is the value of the previous bar when price closed? With Bollinger Bands, that shouldn't change. So instead of getting the .LastValue, you need to get .Last(1).

 


@firemyst