How to make cBot setting Take Profit when pushing button in Indicator
How to make cBot setting Take Profit when pushing button in Indicator
21 Aug 2024, 17:44
Hello,
If I have this button in the indicator, when I click it can the cBot set take profit?
I just use this simple example, all buy positions.
I Managed the references in the cBot next to the build button.. and checked the indicator there.
Indicator code:
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class SetTP : Indicator
{
public static event Action OnSetTakeProfit;
private Button TPBuysButton;
protected override void Initialize()
{
TPBuysButton = new Button
{
Text = "Set TP Buys",
Width = 100,
Height = 20,
BackgroundColor = Color.Chocolate,
ForegroundColor = Color.White,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
};
TPBuysButton.Click += OnTPBuysButtonClick;
Chart.AddControl(TPBuysButton);
}
private void OnTPBuysButtonClick(ButtonClickEventArgs obj)
{
OnSetTakeProfit?.Invoke();
}
public override void Calculate(int index)
{
}
}
}
cBot code:
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class SetTPBot : Robot
{
protected override void OnStart()
{
SetTP.OnSetTakeProfit += SetTakeProfitForBuys;
}
private void SetTakeProfitForBuys()
{
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Buy)
{
double takeProfitPrice = position.EntryPrice + 50 * Symbol.PipSize;
position.ModifyTakeProfitPrice(takeProfitPrice);
}
}
}
}
}
Thanks in advance.
TommyFFX
Replies
TommyFFX
22 Aug 2024, 11:52
RE: How to make cBot setting Take Profit when pushing button in Indicator
PanagiotisCharalampous said:
Hi there,
Why don't you just set the take profit from the indicator?
Best regards,
Panagiotis
Because Indicators can not open, close or modify positions/orders ..
And I need some stuff to communicate in the indicator with a cBot then.
I need a way to modify positions (TP) and close positions witch is not possible with Indicator.
I would like to have an Indicator on each symbol I Trade and use it's logic and only have 1 cBot open in the Automate section.
So each indicator can communicate for the actions it can't do like modifying or closing positions when neccessary.
TommyFFX
@TommyFFX
PanagiotisCharalampous
22 Aug 2024, 14:39
RE: RE: How to make cBot setting Take Profit when pushing button in Indicator
TommyFFX said:
PanagiotisCharalampous said:
Hi there,
Why don't you just set the take profit from the indicator?
Best regards,
Panagiotis
Because Indicators can not open, close or modify positions/orders ..
And I need some stuff to communicate in the indicator with a cBot then.
I need a way to modify positions (TP) and close positions witch is not possible with Indicator.
I would like to have an Indicator on each symbol I Trade and use it's logic and only have 1 cBot open in the Automate section.
So each indicator can communicate for the actions it can't do like modifying or closing positions when neccessary.
TommyFFX
Since version 5.0 they can, so make your life easier and just trade through the indicator :)
@PanagiotisCharalampous
TommyFFX
22 Aug 2024, 21:42
( Updated at: 22 Aug 2024, 22:22 )
RE: RE: RE: How to make cBot setting Take Profit when pushing button in Indicator
PanagiotisCharalampous said:
TommyFFX said:
PanagiotisCharalampous said:
Hi there,
Why don't you just set the take profit from the indicator?
Best regards,
Panagiotis
Because Indicators can not open, close or modify positions/orders ..
And I need some stuff to communicate in the indicator with a cBot then.
I need a way to modify positions (TP) and close positions witch is not possible with Indicator.
I would like to have an Indicator on each symbol I Trade and use it's logic and only have 1 cBot open in the Automate section.
So each indicator can communicate for the actions it can't do like modifying or closing positions when neccessary.
TommyFFX
Since version 5.0 they can, so make your life easier and just trade through the indicator :)
Hi PanagiotisCharalampous
Thank you for your feedback. I was using previous version of broker.
At first it didn't work.. Now I figured out that an Indicator that is not created in version 5.0 doesn't work.
Then I created a new Indicator in 5.0 and it worked.
So when having old Indicators you need to paste it into new ones in 5.0 if you want it to work ..
But it would be usefull to know how to communicate with a cBot.
I'm developing management software. So like MagicKeys for instance. They have a bot and indicator..
Because I'm facing the next obstacle when timeframe is changing I lose my objects or globals, while a cBot is not..
MagicKeys has somewhere a method to communicate cause they have the indicator and the cbot..
Best Regards
TommyFFX
@TommyFFX
PanagiotisCharalampous
23 Aug 2024, 06:55
RE: RE: RE: RE: How to make cBot setting Take Profit when pushing button in Indicator
TommyFFX said:
PanagiotisCharalampous said:
TommyFFX said:
PanagiotisCharalampous said:
Hi there,
Why don't you just set the take profit from the indicator?
Best regards,
Panagiotis
Because Indicators can not open, close or modify positions/orders ..
And I need some stuff to communicate in the indicator with a cBot then.
I need a way to modify positions (TP) and close positions witch is not possible with Indicator.
I would like to have an Indicator on each symbol I Trade and use it's logic and only have 1 cBot open in the Automate section.
So each indicator can communicate for the actions it can't do like modifying or closing positions when neccessary.
TommyFFX
Since version 5.0 they can, so make your life easier and just trade through the indicator :)
Hi PanagiotisCharalampous
Thank you for your feedback. I was using previous version of broker.
At first it didn't work.. Now I figured out that an Indicator that is not created in version 5.0 doesn't work.
Then I created a new Indicator in 5.0 and it worked.
So when having old Indicators you need to paste it into new ones in 5.0 if you want it to work ..
But it would be usefull to know how to communicate with a cBot.
I'm developing management software. So like MagicKeys for instance. They have a bot and indicator..
Because I'm facing the next obstacle when timeframe is changing I lose my objects or globals, while a cBot is not..
MagicKeys has somewhere a method to communicate cause they have the indicator and the cbot..
Best Regards
TommyFFX
There are several ways to achieve communication between a cBot and an Indicator e.g. you can use files or named pipes.
Best regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
22 Aug 2024, 05:15
Hi there,
Why don't you just set the take profit from the indicator?
Best regards,
Panagiotis
@PanagiotisCharalampous