Topics
Replies
chenshy27
03 Sep 2024, 10:55
RE: badvolumn
PanagiotisCharalampous said:
Hi there,
Please share your cBot code so that we can understand what it is doing.
Best regards,
Panagiotis
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class GridTradingBot : Robot
{
private const double EurUsdTakeProfit = 2.5; // EUR/USD 盈利2.5美金时平仓
private const double UsdChfTakeProfit = 2.27; // USD/CHF 盈利2.27美金时平仓
private const double EurUsdLossThreshold = 2.5; // EUR/USD 亏损2.5美金时加仓
private const double UsdChfLossThreshold = 2.27; // USD/CHF 亏损2.27美金时加仓
private const double LotSize = 0.01; // 初始手数
private const double MaxLotSize = 0.1; // 最大手数
private Symbol _eurUsd;
private Symbol _usdChf;
protected override void OnStart()
{
// 获取符号信息
_eurUsd = Symbols.GetSymbol("EURUSD");
_usdChf = Symbols.GetSymbol("USDCHF");
// 启动时开仓 EUR/USD 和 USD/CHF 多单
OpenPosition(_eurUsd, TradeType.Buy);
OpenPosition(_usdChf, TradeType.Buy);
}
protected override void OnTick()
{
ManagePositions(_eurUsd, EurUsdTakeProfit, EurUsdLossThreshold);
ManagePositions(_usdChf, UsdChfTakeProfit, UsdChfLossThreshold);
}
private void OpenPosition(Symbol symbol, TradeType tradeType, double volume = LotSize)
{
ExecuteMarketOrder(tradeType, symbol.Name, volume, "GridTradingBot");
}
private void ManagePositions(Symbol symbol, double takeProfit, double lossThreshold)
{
var positions = Positions.FindAll("GridTradingBot", symbol.Name);
foreach (var position in positions)
{
// 如果单个仓位的利润达到设定的盈利目标,平仓并重新开仓
if (position.NetProfit >= takeProfit)
{
ClosePosition(position);
OpenPosition(symbol, position.TradeType, LotSize);
}
}
// 如果总亏损超过设定的亏损阈值且手数未达到上限,加仓
double totalVolume = positions.Sum(p => p.VolumeInUnits);
double totalProfit = positions.Sum(p => p.NetProfit);
if (totalProfit <= -lossThreshold && totalVolume < MaxLotSize * 100000)
{
OpenPosition(symbol, TradeType.Buy, LotSize);
}
}
}
}
@chenshy27
chenshy27
02 Sep 2024, 10:53
RE: RE: I still can't find my cbot
PanagiotisCharalampous said:
chenshy27 said:
As shown in the image, my cbot is called “stop10”, but I can't find it in the dropdown list as you mentioned! So where can I find the log of my cbot???
Hi there,
The first screenshot comes from the Trade section, the second comes from the Algo section. If you will run the cBot in the algo section, you will not see the logs in the Trade section but in the Algo section.
I don't know why I am unable to load the content of the page you mentioned on the Windows app. There is no issue on the mobile app, and I'm using the same Wi-Fi. Could you please advise if there is a solution? Thanks a lot!
@chenshy27
chenshy27
01 Sep 2024, 12:45
I still can't find my cbot
As shown in the image, my cbot is called “stop10”, but I can't find it in the dropdown list as you mentioned! So where can I find the log of my cbot???
@chenshy27
chenshy27
01 Sep 2024, 12:41
RE: RE: I can't find my cbot
PanagiotisCharalampous said:
chenshy27 said:
Thanks for your response, but I can't find my cBot in the location you mentioned. As shown in the image, my cBot is called “stop4”, but it's not in the algo section.
This is because the displayed logs are for the moving average. Choose your cBot in the relevant dropdown list
As shown in the image, my cbot is called “stop10”,but it's not in the dropdown list you mentioned! So where can I find the log of my cbot???
@chenshy27
chenshy27
30 Aug 2024, 06:27
( Updated at: 30 Aug 2024, 12:53 )
I can't find my cbot
Thanks for your response, but I can't find my cBot in the location you mentioned. As shown in the image, my cBot is called “stop4”, but it's not in the algo section.
@chenshy27
chenshy27
03 Sep 2024, 10:56
RE: badvolumn
PanagiotisCharalampous said:
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class GridTradingBot : Robot
{
private const double EurUsdTakeProfit = 2.5; // EUR/USD 盈利2.5美金时平仓
private const double UsdChfTakeProfit = 2.27; // USD/CHF 盈利2.27美金时平仓
private const double EurUsdLossThreshold = 2.5; // EUR/USD 亏损2.5美金时加仓
private const double UsdChfLossThreshold = 2.27; // USD/CHF 亏损2.27美金时加仓
private const double LotSize = 0.01; // 初始手数
private const double MaxLotSize = 0.1; // 最大手数
private Symbol _eurUsd;
private Symbol _usdChf;
protected override void OnStart()
{
// 获取符号信息
_eurUsd = Symbols.GetSymbol("EURUSD");
_usdChf = Symbols.GetSymbol("USDCHF");
// 启动时开仓 EUR/USD 和 USD/CHF 多单
OpenPosition(_eurUsd, TradeType.Buy);
OpenPosition(_usdChf, TradeType.Buy);
}
protected override void OnTick()
{
ManagePositions(_eurUsd, EurUsdTakeProfit, EurUsdLossThreshold);
ManagePositions(_usdChf, UsdChfTakeProfit, UsdChfLossThreshold);
}
private void OpenPosition(Symbol symbol, TradeType tradeType, double volume = LotSize)
{
ExecuteMarketOrder(tradeType, symbol.Name, volume, "GridTradingBot");
}
private void ManagePositions(Symbol symbol, double takeProfit, double lossThreshold)
{
var positions = Positions.FindAll("GridTradingBot", symbol.Name);
foreach (var position in positions)
{
// 如果单个仓位的利润达到设定的盈利目标,平仓并重新开仓
if (position.NetProfit >= takeProfit)
{
ClosePosition(position);
OpenPosition(symbol, position.TradeType, LotSize);
}
}
// 如果总亏损超过设定的亏损阈值且手数未达到上限,加仓
double totalVolume = positions.Sum(p => p.VolumeInUnits);
double totalProfit = positions.Sum(p => p.NetProfit);
if (totalProfit <= -lossThreshold && totalVolume < MaxLotSize * 100000)
{
OpenPosition(symbol, TradeType.Buy, LotSize);
}
}
}
}
@chenshy27