Topics
Replies

firemyst
28 Aug 2024, 02:49

If you're writing the output from the bot itself, why not just write the bot's parameters as they currently are in the bot to the output file?

Why would you need to read the parameters of the saved cbotset file when the actual parameters in the bot could have been updated/changed without the cbotset file having been updated?


@firemyst

firemyst
27 Aug 2024, 06:39

RE: RE: I need a bot that closes all operations when the equity rises 20pips

robertocarlosyo said: 

firemyst said: 

Yes, it's possible. :-)

Do you know where I get it?

I didn't say there's already one out there.

However, you can code your own to do it. It's relatively straight forward and not too complex.


@firemyst

firemyst
27 Aug 2024, 00:53

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

PanagiotisCharalampous said: 

Hi firemyst,

Can we have the cBot that reproduces this problem?

Best regards,

Panagiotis

Any updates on this issue? 

I replaced the async call with the synchronous code below, and the issue still occurs for me: the bot instance is still marked as “running”, but it's not doing anything/logging, and/or crashes entirely with the error message above:

if (_p.Pips > MaxTrailingStopDistancePips + 2)
{
    //I tried replacing the async code with the following synchronous api call in the 
    //sample code I sent to Spotware, and the issue still occurs. 
    //Seems 1 instance of cTrader cannot handle 26 running instances of a cbot when using this call
    Print("Moving Stop Loss");
    ModifyPosition(_p,
        (_p.TradeType == TradeType.Buy ? s.Bid - (MaxTrailingStopDistancePips * s.PipSize) : s.Ask + (MaxTrailingStopDistancePips * s.PipSize)),
        _p.TakeProfit.GetValueOrDefault(),
        _p.HasTrailingStop
        );
        
    //ModifyPositionAsync(_p,  
    //    (_p.TradeType == TradeType.Buy ? s.Bid - (MaxTrailingStopDistancePips * s.PipSize) : s.Ask + (MaxTrailingStopDistancePips * s.PipSize)),
    //    _p.TakeProfit.GetValueOrDefault(),
    //    _p.HasTrailingStop,
    //    (TradeResult r) => {
            Print("Moved Stop Loss");
            _waitForAsyncTPToComplete = false;
    //    }
    //    );
    //_waitForAsyncTPToComplete = true;
}

@firemyst

firemyst
26 Aug 2024, 02:23

Yes, it's possible. :-)


@firemyst

firemyst
26 Aug 2024, 02:22

> “Can we use onBar() and onTick() at the same time?”

Yes.

Example where you don't need the OnBar method:

// define at class level
private int _currentIndex;
private int _previousIndex;

//set _currentIndex in OnStart
_currentIndex = _marketSeries.OpenTimes.Count;
_previousIndex = 0;

//Do the following in OnTick
if (_currentIndex != _previousIndex)
{
    //Call your OnBar Method
    YourCustomOnBarForBot([parameters if any]);

    //Update the previous index until it changes again
    _previousIndex = _currentIndex;
}

//if needed, continue with the ontick method
//Or, if you don't want to do anything else with the tick when 
//a new bar is formed, use an else clause
//else do the tick method when it's not the same tick a new bar is formed
else
{
}

@firemyst

firemyst
26 Aug 2024, 02:16

Thoughts are you need to add this to the “Suggestions” forum as Spotware doesn't come here looking for suggestions as this is for technical support.

 

If you really need it done, create your own bot that monitors your positions, and does the SL/TP accordingly as per your parameters.


@firemyst

firemyst
26 Aug 2024, 02:15

First, this needs to go in the “Suggestions” forum as Spotware doesn't look here for suggested improvements. This is for technical help.

 

Second, if it can't wait, I would write your own indicator that will do this for you. I agree cTrader's alerts are 3rd/4th class compared to other platforms out there like MT4 and ThinkTrader's. I don't think Spotware's priority at the moment is improving their alerting functionality as it hasn't changed much in the last 5-8 years. So yeah, probably best way to do this is write your own indicator that monitors prices for you and plays an alert sound meeting your requirements. 


@firemyst

firemyst
22 Aug 2024, 07:56 ( Updated at: 22 Aug 2024, 07:57 )

What do i do wrong?

You're using a Mac ;-)


@firemyst

firemyst
21 Aug 2024, 06:20

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

PanagiotisCharalampous said: 

Hi firemyst,

Can we have the cBot that reproduces this problem?

Best regards,

Panagiotis

Hi @PanagiotisCharalampous :

I've reproduced the issue again. It's in my log files:

I sent through a private YouTube video link to the Community Spotware email address referencing this thread so your team can watch the video and see exactly what's happening.

 

 


@firemyst

firemyst
20 Aug 2024, 04:55 ( Updated at: 20 Aug 2024, 05:13 )

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

PanagiotisCharalampous said: 

Hi firemyst,

Can we have the cBot that reproduces this problem?

Best regards,

Panagiotis

I have managed to create a cBot which caused this issue for me today. It doesn't print out the “Unexpectedly terminated” error, but the bot instances stop responding.

I'll email it through to the “community” email address shortly.

I had to let the bot run over the weekend and noticed certain symbols stopped ticking over today. 

My guess now is it's being caused by an async callback not working properly as when I added one into the code, that's when things broke. Eg, I stripped out all the code and started to gradually add things back in to see what would cause it to break.

I'll try and make notes of that in the code.

I discovered this issue by looking at the logs. I hav einformation printed out for every tick – some symbols like AUDUSD were still printing to the log today; others like AUDCHF stopped printing to the log yesterday. Both bot instances were running off the same bot code.


@firemyst

firemyst
20 Aug 2024, 01:19 ( Updated at: 20 Aug 2024, 04:33 )

Have you considered that there might not be any more history to be loaded, especially if you're not scrolling to the left on the charts? 

See this thread:

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

 


@firemyst

firemyst
20 Aug 2024, 01:09

Do as it says – install the latest version of ctrader. 

If you're using a broker's version of cTrader, they might not be updated to version 5.0.x yet. 

If the template file you have came from a version made in 5.x, it won't work in the broker versions that are still 4.x


@firemyst

firemyst
15 Aug 2024, 01:04 ( Updated at: 15 Aug 2024, 05:20 )

Stop making it hard on yourself.

Change your parameter “EMA Color” to a “Color” parameter and use that. 

Examples here: https://help.ctrader.com/ctrader-algo/guides/parameter-types/#cbot-examples

 


@firemyst

firemyst
13 Aug 2024, 00:06

Do you have time to change your default trade settings?

 


@firemyst

firemyst
13 Aug 2024, 00:01

You can't.

Emails aren't allowed to be sent from bots running in the cloud.

 


@firemyst

firemyst
12 Aug 2024, 05:34

RE: RE: Daily Limit on loss and Win

PanagiotisCharalampous said: 

firemyst said: 

There is a way to do it, but you have to code it into your bots. Here's an example:

//Get historical tradePosition p1 = args.Position;//Running Totals_runningTotalsPipsGainedLost += p1.Pips;_runningTotalsNetGainLoss += p1.NetProfit//Stop the bot if the running net gain/loss pips falls below our specified amountif (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow){	//stop bot	Stop();}//Stop the bot if the running net gain/loss total falls below our specified amountif (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow){	//stop bot	Stop();}

Note that this only works on each individual bot instance for each bot.

If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.

Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.

 

 

I assume that the trader wants to block trading for the entire account.

 

They don't make that clear, but their initial post does say “limit” as opposed to “block”


@firemyst

firemyst
11 Aug 2024, 11:43 ( Updated at: 11 Aug 2024, 15:29 )

There is a way to do it, but you have to code it into your bots. Here's an example:


//Get historical trade
Position p1 = args.Position;

//Running Totals
_runningTotalsPipsGainedLost += p1.Pips;
_runningTotalsNetGainLoss += p1.NetProfit

//Stop the bot if the running net gain/loss pips falls below our specified amount
if (_runningTotalsPipsGainedLost < StopBotWhenPipLossesFallBelow)
{
	//stop bot
	Stop();
}

//Stop the bot if the running net gain/loss total falls below our specified amount
if (_runningTotalsNetGainLoss < StopBotWhenLossesFallBelow)
{
	//stop bot
	Stop();
}

Note that this only works on each individual bot instance for each bot.

If you want the running totals to be across all instances of a particular bot, then you need to set static variables that are public that all bot code would have access to.

Have your bots check that value every time they start, and before entering any positions. If that global static amount is below a certain threshold, either stop your bot, or don't allow it to enter a new position.

 

 


@firemyst

firemyst
11 Aug 2024, 11:02 ( Updated at: 11 Aug 2024, 15:29 )

Your bot probably won't work as you want because if you read this page:

https://help.ctrader.com/ctrader-algo/synchronisation/requirements-for-cbots/#compile-time-references

http requests aren't sent when bots run in the cloud.

 


@firemyst

firemyst
08 Aug 2024, 01:44

Yes. 

2 options:

  1. configure 3 instances of the bot, and for each bot, select a different demo account
  2. launch 3 instances of cTrader with each cTrader set to a different account.

 


@firemyst