Topics
Replies

firemyst
23 May 2022, 12:42 ( Updated at: 24 May 2022, 03:36 )

RE: RE: RE: RE: Discontinuous outputs

genappsforex said:

firemyst said:

Because both

((double)index)/3 == index/3

is false and

((double)index)/4 == index/4

is false.

So it always has a value in Result1 and not Result2 because Switch is always > 0:

if(Switch>0) Result1[index] = Bars[index].High;

Sorry to tell you but you're wrong.
Just run the indicator code i've posted and see for yourself.

 

Perhaps you have some Windows or .Net updates that haven't taken affect yet in cTrader? Reboot?

 


@firemyst

firemyst
22 May 2022, 13:36

RE: RE: Discontinuous outputs

genappsforex said:

amusleh said:

Hi,

The lines are discontinuous:

 

Discontinuous outputs can have empty or NAN values, and those NAN values will not be displayed on the chart.

Well that was my understanding also.
So Why does not my little progam above generate discontinuous Lines?

Because both

((double)index)/3 == index/3

is false and

((double)index)/4 == index/4

is false.

So it always has a value in Result1 and not Result2 because Switch is always > 0:

if(Switch>0) Result1[index] = Bars[index].High;

@firemyst

firemyst
30 Apr 2022, 19:47

RE:

shaahin69 said:

Hi, 

 

I am trying to implement break even when order is in profit. 

Say if I have positions open with 15 contracts, I wish to close 10 contracts only once position pips is greater than 2 and move the SL to break even. Then I want to specify a new TP for the amount of 5 pips.

I have found an example related to break even in cTrader cBot examples, however, I am still unsure how to take profit partially as well as setting a new TP.

Is following correct? 

 

var TP = 2;

if (position.Pips > TP)

{
ClosePosition(position, 10); // close 10 contracts 

var newTP = ??? // how do I set new TP for 5 pips from current price?

ModifyPosition(position, roundedBreakEvenLevel, newTP);

}

double newTP = (position.TradeType == TradeType.Buy ? Symbol.Ask + (5 * Symbol.PipSize) : Symbol.Bid - (5 * Symbol.PipSize));


@firemyst

firemyst
30 Apr 2022, 19:44

@Spotware?

Thank you.


@firemyst

firemyst
26 Apr 2022, 10:16

RE:

amusleh said:

Hi,

I did understood your point, what I was trying to explain was there is no way to accurately know when a tick will result in formation of a new bar.

Regarding your issue, you can do something like this:

 

Okay. Cool. Thanks for that and your sample code. I haven't looked at the sample code, but had another question -- with cTrader shouldn't it (or is it already) programmed up to open a new bar regardless of whether or not a tick comes through?

It it takes the timing of a tick to actually open a new bar, then hypothetically bars could open up halfway through their time period, or even not at all.

If it is set to open a new bar regardless of whether a tick or not happens, then the example I provided seems to illustrate a bug where ticks happen before the bar is actually opened.

Thank you.


@firemyst

firemyst
25 Apr 2022, 10:38

RE: RE:

instylereality2 said:

firemyst said:

I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.

Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.

Yeah, I was feeling that this would be the case. A confirmation is needed on this for sure.

Any idea about how this could be achieved? Or isn't possible at all to have a live price checking mechanism in OnTick() that would be combined with OnStart() to complete a continues checking cycle??

Thank you! 

Why do you even need to wait in OnStart until something happens?

Just set a flag to false, and when it occurs in OnTick, set the flag to true.

Then check the flag in OnTick and when it's true, go through another branch of code.


@firemyst

firemyst
25 Apr 2022, 09:15

I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.

Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.


@firemyst

firemyst
25 Apr 2022, 09:12

RE:

budda_dan2020 said:

Hi,

is the IAccount.StopoutLevel in % or just a proportion?

E.g. if my account has a stop out level as 30%, is the value of IAccountStopOutLevel 30 or 0.3?

 

kind Regards

Why not just print it out to see for yourself?

Eg:

Print("Stop out level: {0}", IAccount.StopoutLevel);

and then check the log tab to see what it says.


@firemyst

firemyst
25 Apr 2022, 09:11

Yes.

In your code set a boolean flag to indicate that you've done your modification on the position. For example, "alreadyModifiedPosition = true;"

Every time you go through your code, only enter into the part that does the position modification if the flag is set to false.

Eg:

if (!alreadyModifiedPosition)

{

   /// do your position modification

   alreadyModifiedPosition = true;

}

 

Then you just have to figure out the logic when you reset alreadyModifiedPosition back to false. Every time you start your bot? When the position is closed? Something else?

Good luck! :-)


@firemyst

firemyst
22 Apr 2022, 04:20 ( Updated at: 21 Dec 2023, 09:22 )

RE:

amusleh said:

Hi,

There is no way to know when  a tick results on opening of a new bar, you can use a timer to count the remaining time of a bar but that works only for time based bars not for Tick, Renko, and range bars, you have to know the time period of a time frame bar as there is no way for now to know how much is a time based time frame bar time period programmatically.

I recommend you to change the way you designed your bot, instead of using the timer, as it would be not 100% accurate.

cBots OnTick method is called before OnBar, and by a single thread, so they will never be called concurrently.

These types of issues are more related to the way you design your Bot than API limitations.

I don't think you fully understand what I'm trying to describe or I'm not being clear enough.

I do not use a timer in the algorithm. The timings you see in the log statements are from the "Log" tab in cTrader.

I use the "OnTick" and "OnBar" methods with a boolean flag. The code is structured as per my first post.

The bot checked to increase the position size. Since it hadn't already done so that bar, it increased by 0.1 lots, and then set the flag "_enteredPositionThisBar" to true so the bot would not enter another position in the current bar.

That was on the tick called just before the OnBar, but the clock had already ticked over to the next minute, so it should have occurred during the 21.00.00 bar and not the bar opened at 20.59.00.

Then the next bar is opened, and since the flag "_enteredPositionThisBar" was set to false in the "OnBar" method, the bot immediately increased the position size again during the 21.00.00 bar as you can see from the screen capture. Note I do NOT use any asynchronous calls when placing orders.

20/04/2022 20:51:39.729 | cBot "BugBot" was started successfully for NAS100, m1.

20/04/2022 20:51:54.348 | OnTick

:
20/04/2022 21:00:00.775 | OnTick --> it increased the size here, adding 0.1 lots. "_enteredPositionThisBar" set to true.
20/04/2022 21:00:00.909 | OnBar     --> "_enteredPositionThisBar" set to false.
20/04/2022 21:01:00.313 | OnTick --> it increased the size again here by 0.1 lots and reset the flag the true.   
20/04/2022 21:00:00.418 | OnTick
 

So because the "OnBar" even occurs _after_ the first tick event in that new bar, it opens a position twice during the same bar when technically it shouldn't since the new bar hadn't been opened yet. With the log above and screen captures below, do you see what I'm saying?

Since boolean flags won't work since tick events for a new bar's timeframe occur _before_ the "OnBar" event actually occurs, and we can't use the Bars.OpenTimes.Count to check if the number of bars have increased (because on the first tick in the new M1 bar, the new bar hasn't been formed yet), would you be able to provide sample code to get around this issue?

Here's what happened. Note the deal map and compare against the logs. cTrader shows BOTH orders being displayed in the same bar even though the first one happened during the tick event _before_ the "OnBar" event:

Thank you.

 


@firemyst

firemyst
20 Apr 2022, 10:27

RE:

amusleh said:

Hi,

cTrader can load different number of data on your chart, there is no fixed number of bars.

You shouldn't rely on bar index numbers to be same across different machines, use bar open times instead.

Thank you for your response and confirmation.


@firemyst

firemyst
20 Apr 2022, 04:03 ( Updated at: 21 Dec 2023, 09:22 )

Any updates @Spotware?

Hello @Spotware / @Panagiotis / @Amusleh,

Following up as haven't seen a response in regards to this.

This is AUDCAD pair on Daily timeframe. First capture below is from my local laptop in UTC+8 time; second capture is from my VPS located in New York, but set to UTC + 8 time.

Since this is the DAILY timeframe and both charts are freshly loaded (eg, cTrader just started and no scrolling has been done), I would expect bar numbers and current indexes to be the same on both charts; however as you can see, they are way off. The indicator code used is in my original post.

This tells me that cTrader initially loads different amounts of chart data depending on what machine it's running on? Are you able to confirm this?

Otherwise, why would one daily chart for AUDCAD be up to bar number 1498 and the other be up to 1654 when both charts are freshly loaded on the same day in UTC time without any historical scrolling having been done?

Thank you.

 

Capture from local laptop:

Capture from VPS on same day a few minutes apart:


@firemyst

firemyst
05 Apr 2022, 09:09

> Hi, I would like to run this bot on different instances, but I couldnt do it. I tried label and symbol too.

 

What do you mean?

To run multiple instances of a bot, just add more "instances" under the bot and choose the symbol you want to run it against.

Example:

In teh above, one instance will run on EURUSD H1 timeframe, the other bot will run under the US30 symbol.


@firemyst

firemyst
05 Apr 2022, 09:04

Copy what?

Trades?

Code?

Set ups?

Charting templates?

Indicators?

EA's?

You'd probably get more answers if your request wasn't so vague.

 


@firemyst

firemyst
29 Mar 2022, 11:28

RE:

amusleh said:

Hi,

It does work, but it depends on the email service you are using, some services doesn't allow old SMTP authentication anymore like Gmail as it causes security issues.

I tested it on my own email server and it works fine.

cTrader automate API just provide a wrapper over .NET SMTP API to make it easier.

 

 

So it definitely works with gmail? I can set up a test gmail account, keep the same indicator code (except changing the email addresses as appropriate), and all should work "as is"?

Also, what do you mean by "old smtp authentication"? All the links I found, and posted in my original post, explain how to set up SMTP authentication with the parameters required by cTrader.

Thank you.


@firemyst

firemyst
20 Mar 2022, 05:02

Obviously it could depending on what your cBot does.

For instance - latency. Does your cBot continuously make big network calls sending and/or receiving huge amounts of data across the network? If so, then duh... obviously it could affect latency.

Your cBot could be 1Gig in size, but in terms of performance, size doesn't matter ;-) Again, it's what's inside the code that counts. If your cBot is heavily CPU intensive, then duh again... obviously it could affect performance depending on your VPS's configuration (Eg, do you have 2 cores? 4 cores? 8 cores?)

So without posting details of your cBot, there's no "one size fits all answer" to your question.


@firemyst

firemyst
18 Mar 2022, 09:00

RE:

amusleh said:

Hi,

The bar index should work fine, if it's not then it's a bug.

Can you tell me which broker you are using? which Renko chart? I will try to reproduce it.

 

Great. You have the code and screen capture above.

 

Broker is Pepperstone.

Renko chart is Re5.

Chart is NAS100. Date/time on the screen capture. But just in case, time in UTC + 8 is Mar 17th from 04:43 - 04:54

 

Thank you.


@firemyst

firemyst
12 Mar 2022, 12:29

No, it's not as of the last time I asked @Panagiotis.

Perhaps either he or someone from @Spotware can indicate if it's even in the timeline as a feature to be added to the API?

 

 


@firemyst

firemyst
10 Mar 2022, 15:01

THis happened with the latest driver update today from Intel. I've had to roll it back.

I've submitted a report to @Spotware through the ctrl-shift-alt-T so Spotware can confirm if it is another bug in the Intel driver or not.

It affects both my Pepperstone and IC Markets cTrader platforms.


@firemyst

firemyst
22 Feb 2022, 13:28 ( Updated at: 22 Feb 2022, 13:31 )

RE: RE: RE: RE:

BJORNBERNAU said:

Thank you! Well, I tried it. This does not change it. The code is now the following 

 

protected override void OnBar()
        {

            double a = S2.sell_ONE.Last(0);
            a = S2.liq_ONE.Last(0);

            double b = S2.liq_ONE.Last(0);
            b = S2.liq_ONE.Last(0);


            if (!double.IsNaN(S2.sell_ONE.Last(0)) == true)
            {
                Print("SELL    ", Bars.Count, "      ", S2.sell_ONE);
            }

            if (!double.IsNaN(S2.liq_ONE.Last(0)) == true)
            {
                Print("LIQ    ", Bars.Count, "      ", S2.liq_ONE);
            }

        }

 

Resulting in this data stream - a block-wise procurement of SELL and LIQ. 

 

  double b = S2.liq_ONE.Last(0);
            b = S2.liq_ONE.Last(0);

WHY ARE YOU DOING THIS?! Not only are you assigning the same value to "b" twice, but you're also declaring a new variable, of which there's no need to declare a new "double b".

As I said, who cares if "a" gets overwritten with a new value?? -- you don't care about the value, and you never use it again. Don't take up extra computing resources by declaring another "double" that's not going to be used anywhere and that you're just assigning the same value to it twice in a row.

As for your overall print statements, it is working now. Your original issue was it kept printing "LastValue: NaN". It no longer does that. That issue is resolved.

If there's other logic issues in your indicator code, you'll have to figure those out or ask for help from others. :-)

 


@firemyst