How to stop an Algo after profit reached!

Created at 31 Aug 2022, 02:16
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
OM

Omega

Joined 29.05.2016

How to stop an Algo after profit reached!
31 Aug 2022, 02:16


Hi fellas'

I have two algo's I use to trade...

First is an algo that trades a basket of currencies the second will close all positions when the account reaches it's profit target.

The issue I have is that the first algo that trades doesn't stop once the positions have been closed by the second algo if I'm not there to manually stop ctrader.

Is there a way to stop the trading algo after it has reached my profit target without my being there to do it manually?

 

Look forward to your ideas...

 

O


@Omega
Replies

firemyst
31 Aug 2022, 15:55

RE:

Omega said:

Hi fellas'

I have two algo's I use to trade...

First is an algo that trades a basket of currencies the second will close all positions when the account reaches it's profit target.

The issue I have is that the first algo that trades doesn't stop once the positions have been closed by the second algo if I'm not there to manually stop ctrader.

Is there a way to stop the trading algo after it has reached my profit target without my being there to do it manually?

 

Look forward to your ideas...

 

O

ALl you have to do is put this line of code in your cBot when you want it to stop:

                Stop();

So when the position is closed, in the running bot instance check to make sure the current bot instance is the one that had its position closed. If it was, tell it to "Stop()".

 


@firemyst

Omega
01 Sep 2022, 00:03

Hi Firemyst,

firemyst said:

Omega said:

Hi fellas'

I have two algo's I use to trade...

First is an algo that trades a basket of currencies the second will close all positions when the account reaches it's profit target.

The issue I have is that the first algo that trades doesn't stop once the positions have been closed by the second algo if I'm not there to manually stop ctrader.

Is there a way to stop the trading algo after it has reached my profit target without my being there to do it manually?

 

Look forward to your ideas...

 

O

ALl you have to do is put this line of code in your cBot when you want it to stop:

                Stop();

So when the position is closed, in the running bot instance check to make sure the current bot instance is the one that had its position closed. If it was, tell it to "Stop()".

 

Thanks for that...

I get the 'Stop(); line but I have an algo on each chart, it's the collective or basket of currencies that provide the profit overall so I'm thinking that it will need a separate algo for this?


@Omega

firemyst
01 Sep 2022, 04:38 ( Updated at: 01 Sep 2022, 04:39 )

RE: Hi Firemyst,

Omega said:

firemyst said:

Omega said:

Hi fellas'

I have two algo's I use to trade...

First is an algo that trades a basket of currencies the second will close all positions when the account reaches it's profit target.

The issue I have is that the first algo that trades doesn't stop once the positions have been closed by the second algo if I'm not there to manually stop ctrader.

Is there a way to stop the trading algo after it has reached my profit target without my being there to do it manually?

 

Look forward to your ideas...

 

O

ALl you have to do is put this line of code in your cBot when you want it to stop:

                Stop();

So when the position is closed, in the running bot instance check to make sure the current bot instance is the one that had its position closed. If it was, tell it to "Stop()".

 

Thanks for that...

I get the 'Stop(); line but I have an algo on each chart, it's the collective or basket of currencies that provide the profit overall so I'm thinking that it will need a separate algo for this?

Since you can't control one bot from another bot, there are at least 2 options I can think of off the top of my head that you can try:

1) (the easiest one) - create a public static variable in your bot code. That'll be visible across all bots. Call it something like:

public static bool StopAllBotInstances = false;

Make it a boolean. Have each bot check it during the onTick method. If it's ever set to true by one bot, call Stop(); Every bot should then stop with the next tick.

 

2) (not as easy) Create your own event handler called something like "OnProfitTargetReached" that does the same thing -- Stop() when the event is fired by any bot instance.


@firemyst

Omega
01 Sep 2022, 05:09

Thanks Firemyst,

firemyst said:

Omega said:

firemyst said:

Omega said:

Hi fellas'

I have two algo's I use to trade...

First is an algo that trades a basket of currencies the second will close all positions when the account reaches it's profit target.

The issue I have is that the first algo that trades doesn't stop once the positions have been closed by the second algo if I'm not there to manually stop ctrader.

Is there a way to stop the trading algo after it has reached my profit target without my being there to do it manually?

 

Look forward to your ideas...

 

O

ALl you have to do is put this line of code in your cBot when you want it to stop:

                Stop();

So when the position is closed, in the running bot instance check to make sure the current bot instance is the one that had its position closed. If it was, tell it to "Stop()".

 

Thanks for that...

I get the 'Stop(); line but I have an algo on each chart, it's the collective or basket of currencies that provide the profit overall so I'm thinking that it will need a separate algo for this?

Since you can't control one bot from another bot, there are at least 2 options I can think of off the top of my head that you can try:

1) (the easiest one) - create a public static variable in your bot code. That'll be visible across all bots. Call it something like:

public static bool StopAllBotInstances = false;

Make it a boolean. Have each bot check it during the onTick method. If it's ever set to true by one bot, call Stop(); Every bot should then stop with the next tick.

 

2) (not as easy) Create your own event handler called something like "OnProfitTargetReached" that does the same thing -- Stop() when the event is fired by any bot instance.

Thanks Firemyst,

 

I'll have a think about that logic and see where it takes me.

All the best to you...

O


@Omega