Topics
Replies

firemyst
10 Mar 2024, 03:01

How come you don't print the values for :

  1. CurrentTime
  2. ParseTime(Time1).AddMinutes(-TimeDurationMinutes)
  3. ParseTime(Time1).AddMinutes(TimeDurationMinutes)
  4. and all the values for Time2-7

You don't know what those actual values are. You may think you know what they are, but you should print them out in your log so you know what they actually are.

For instance, you're getting the server time. Do you know what time zone the cTrader server is in? ANd then you're adding hours to that. Have you confirmed through print statements what the actual server time is that you're code is looking at?

If so, prove it :-)

Put it in the output logs.

Also, your “TimeDurationMinutes” is by default set to 5; yet you only want plus/minus 2 minutes. How do we know what value you have the parameter set at when you run your bot?

Again, print this to log.

 


@firemyst

firemyst
10 Mar 2024, 02:49

Question 1: the SL should trail at the distance it is the moment the ModifyTrailingStop is executed on the server. Note that because of rapid market movements this could change between when the bot executes the command to when the server actually receives and implements it. 

 

Question 2: you position.ModifyTrailingStop(false) and i) either way for the price to move to the distance you want, or ii) move the SL yourself to the desired distance. Then you can re-enable the trailing stop.

Or another way is while trailing stop is true, you move the trailing stop either forward/backward to the distance you want by doing position.ModifyStopLossPrice or position.ModifyStopLossPips

 


@firemyst

firemyst
08 Mar 2024, 01:58

Try creating a new copy of the bot in cTrader Automate.

Paste the code in cTrader automate.

Once it's in there, then click to open Visual Studio, compile it, and try running the bot.


@firemyst

firemyst
08 Mar 2024, 01:50

RE: Smaller stop loss than expected

PanagiotisCharalampous said: 

Hi there,

SL and TP should be set in pips. You seem to pass absolute prices instead.

Best regards,

Panagiotis

Where does he set the SL as a price instead of pips? 

The variable “SL” is set as a parameter and when he opens a position, that's what he passes:

ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, "Frann", SL, TP);

“SL” isn't changed in the code he's provided.

Also, the “TP” is never set in the code he posted either.

 


@firemyst

firemyst
08 Mar 2024, 01:49

RE: Smaller stop loss than expected

PanagiotisCharalampous said: 

Hi there,

SL and TP should be set in pips. You seem to pass absolute prices instead.

Best regards,

Panagiotis

Where does he set the SL as a price instead of pips? 

The variable “SL” is set as a parameter and when he opens a position, that's what he passes:

ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, "Frann", SL, TP);

“SL” isn't changed in the code he's provided.

Also, the “TP” is never set in the code posted either.

 


@firemyst

firemyst
08 Mar 2024, 01:45

RE: RE: C bot problem

flappiyt said: 

PanagiotisCharalampous said: 

Hi there,

Please provide more information about your problem. What do you mean when you say “I noticed that it's opening positions, but I can't see them”?

Best regards,

Panagiotis

Hi Panagiotis

I can hear positions being opened, and I can see it in the top right corner. However, I noticed in the trading history that positions are being opened for approximately 0.001 seconds and are immediately closed.

Then you're probably opening the position with either the SL or TP within the security's spread.


@firemyst

firemyst
07 Mar 2024, 07:22 ( Updated at: 07 Mar 2024, 07:29 )

RE: RE: cTrader "pip scale" constantly goes flukey, and nowhere near being correct

PanagiotisCharalampous said: 

firemyst said: 

Hello Team @Spotware / @PanagiotisCharalampous

Any further updates on a fix for this issue?

Thank you

Hi firemyst,

We had no luck reproducing this issue therefore we cannot fix it at the moment.

Best regards,

Panagiotis

It's still happening - affecting the pip spread by a factor of 10. IN this screen capture, I've used the “crosshair” tool to measure the same distance from top → bottom of the chart's scale. You can see the scale says 100 pips while the crosshair says 10 pips.

 

What I'm doing now is uninstalling Spotware's cTrader Desktop 4.8.30, deleting the folders “Spotware” and “Spotware_Systems_Ltd” from appdata\local folders, and will try another install to see if that corrects the issue.


@firemyst

firemyst
06 Mar 2024, 09:58 ( Updated at: 06 Mar 2024, 14:00 )

Of course it's doing that. That's exactly what you told it to do.

Look at your logic. For starters:

 if (bodySize < 10 * Symbol.PipSize)
                    {   //Why are you setting the SL from the close price here
                        stopLoss = close - SL * Symbol.PipSize;
                    }
                    else
                    {   //and setting the SL from the open price here?
                        stopLoss = open - SL * Symbol.PipSize;
                    }
 //if the overall bar is "bullish", don't you want them both calculated from the open price?

@firemyst

firemyst
06 Mar 2024, 09:54 ( Updated at: 06 Mar 2024, 14:00 )

Duplicate. See this thread:

 

https://ctrader.com/forum/indicator-support/43045

 

 


@firemyst

firemyst
05 Mar 2024, 07:54

RE: RE: Run code Once Per new bar

mihlali700 said: 

firemyst said: 

It's not running on every tick; it's running every bar. The index you're printing confirms it.

When you first load a chart in cTrader, it loads previous bars, and runs through the calculations on those, and that's exactly what's happening here, unless it gets to the latest bar.

Sort the log by the date/time DESCENDING instead of ASCENDING and you'll see with the most recent data it only executes once per bar.

So its going through the entire index once per bar ? 
What if I just want data from the latest index and only starting from that index ? Like I want to print the value of the indicator but only for the latest bar 

No, it's not going through all the indexes once per bar. As I said, when you first start cTrader, it loads up all the previous bars because it has to. Otherwise,e there's no way to display previous chart data is there?

If you only want data from the latest index going forward, then in your Initialize method, get the latest index:

int latestIndex = Bars.OpenTimes.Count - 1

Then in your calculate method check if index ≥ latestIndex before doing anything.


@firemyst

firemyst
05 Mar 2024, 03:11 ( Updated at: 05 Mar 2024, 06:44 )

It's not running on every tick; it's running every bar. The index you're printing confirms it.

When you first load a chart in cTrader, it loads previous bars, and runs through the calculations on those, and that's exactly what's happening here, unless it gets to the latest bar.

Sort the log by the date/time DESCENDING instead of ASCENDING and you'll see with the most recent data it only executes once per bar.


@firemyst

firemyst
05 Mar 2024, 03:06 ( Updated at: 05 Mar 2024, 06:44 )

RE: RE: RE: Is it better to call the indicator or write the indicator yourself?

PanagiotisCharalampous said: 

 

In principle no, as long as the implementations are identical. However, since there are always specifics in each case, this needs to be checked on a case by case basis.

Out of curiosity, are the native built in cTrader indicators written in .Net as well? Or another language like C++


@firemyst

firemyst
05 Mar 2024, 03:00 ( Updated at: 05 Mar 2024, 06:44 )

foreach (Position p in Positions)
{
    if (p.SymbolName == "whatever symbol you want to close")
        ClosePosition(p);
}

@firemyst

firemyst
05 Mar 2024, 02:57 ( Updated at: 05 Mar 2024, 06:44 )

Try reading Spotware's documentation and Google:

https://help.ctrader.com/ctrader-automate/compiling/#parameters

 

 


@firemyst

firemyst
03 Mar 2024, 03:30

RE: Is it better to call the indicator or write the indicator yourself?

PanagiotisCharalampous said: 

Hi there,

Unfortunately I cannot understand the question and I guess many other readers. Could you please rephrase and provide some examples of what you are doing?

Best regards,

Panagiotis

I think what the OP is asking is if he's writing either a bot or a custom indicator that references a common indicator like the EMA, does the code execute faster if he references the native indicator in cTrader, or codes his own EMA within the custom indicator/bot he's writing. 

Since nano-seconds can make a difference, he's essentially wonder if anyone's done any bench marks to see which way is faster.

That's how I read it.


@firemyst

firemyst
25 Feb 2024, 12:39

RE: RE: Historical Data for Range charts

roan.is said: 

firemyst said: 

This is probably dependent on your broker. 

Why not open your cTrader, put on a big range like 100 pips per bar, and see how far back it goes?

Thanks for your reply.  Unfortunately, I don't have access to cTrader at the moment (no computer), hence my question. But I'll certainly do a check as soon as I can. 

When you change bar sizes, just keep scrolling left to bring in more historical data. See how far the rabbit hole goes.


@firemyst

firemyst
25 Feb 2024, 12:23

This is probably dependent on your broker. 

Why not open your cTrader, put on a big range like 100 pips per bar, and see how far back it goes?


@firemyst

firemyst
22 Feb 2024, 02:24 ( Updated at: 22 Feb 2024, 07:46 )

Duplicate. Original one is here:

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

 


@firemyst

firemyst
21 Feb 2024, 11:45

RE: Protect orders/positions against manual modifications

ncel01 said: 

Unintentional manual modifications.

Semantics. Unintentional by you or someone else. Either way, with how the charts are structured and the location of controls, it takes a lot to do something ‘unintentional’ while looking at the charts with a position you're in – someone has to physically move, point, and click a mouse button, especially if you've removed all the hot key shortcuts. That's a lot for being unintentional while trading on a live account.

And besides moving the SL/TP, I don't know what else you could easily reverse/reset if something ‘unintentional’ is done.

 


@firemyst

firemyst
21 Feb 2024, 08:30

RE: RE: Protect orders/positions against manual modifications

ncel01 said: 

firemyst said: 

Yes it can. You'll have to implement checks. There's no way currently to prevent a user from manually modify an order (SL/TP), but you can always keep track of the last value your bot moved it too and then revert back to those values if they were updated.

 

Other modifications like increasing/decreasing the position size and such will be a bit more tricky because you'll first have to start by asking yourself… if someone manually decreased your position size, would you really want to increase it back to where it was?

 

That's exactly about check and revert as I mentioned above.

I think the most effective way was to have an option on cTrader settings for the active account. 

Allow manual trading for the account? Y/N

In addition, this would also save all the effort to code an (not so effective) alternative.

The first question to possibly ask is if you're trading via automation, who would be adjusting the trades manually? If it's not you, and you're running the bots, then maybe the easiest approach would just be to ask whoever else has access to actually not trade anything. 


@firemyst