Topics
Forum Topics not found
Replies
amusleh
07 Jun 2022, 09:22
RE: RE:
YC1186 said:
amusleh said:
Hi,
No, there is no available data to know how a position is closed, you can check the position close reason inside position closed event but it only gives you information on what caused the position to close, not by who.
Regarding adding comment or label, yes it's possible, both comment and label are available for Positions and orders, you can set comment for a position either by using create new position window on cTrader or with automate API, labels are only available for API.
Also i'm pretty sure there's some way to know how a position has been closed.. It should be very simple programatically to know if it's been closed manually or by a bot..
Hi,
There is no API feature for getting such data.
You can create a thread on suggestions section for this feature.
@amusleh
amusleh
06 Jun 2022, 08:21
RE: Any Australian brokers yet?
ctid2514471 said:
Are any Australian brokers offering Desktop 4.2 as yet?
The Australian brokers just say "We offer cTrader" - But they don't specify which version.The improvements here sound awesome, as a few of the improvements address issues that made me give up on my algorithmic trading ideas.
Hi,
All cTrader brokers will be updated to latest version eventually, we are rolling out version 4.2 slowly for all brokers.
@amusleh
amusleh
06 Jun 2022, 08:14
Hi,
Try this:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ModifyStopLossTakeProfitExample : Robot
{
private String label = "ModTP";
private bool variable = false;
protected override void OnTick()
{
var position = Positions.Find(label, SymbolName, TradeType.Buy);
if (position == null)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.QuantityToVolumeInUnits(1), label, 2, 2, "Comment", false);
variable = true;
}
if (variable == true)
{
double stopLoss, takeProfit;
if (position.TradeType == TradeType.Buy)
{
stopLoss = position.EntryPrice - (3 * Symbol.PipSize);
takeProfit = position.EntryPrice + (3 * Symbol.PipSize);
}
else
{
stopLoss = position.EntryPrice + (3 * Symbol.PipSize);
takeProfit = position.EntryPrice - (3 * Symbol.PipSize);
}
ModifyPosition(position, stopLoss, takeProfit);
}
}
}
}
If your position is closed immediately after modification then it means the amount of stop loss or take profit you set was very small.
@amusleh
amusleh
06 Jun 2022, 08:08
( Updated at: 21 Dec 2023, 09:22 )
Hi,
I just tested your first indicator on Spotware cTrader beta 4.2.7 and it works fine:
Your second indicator doesn't work on both cTrader 4.1 and 4.2, it crashes with same exact error on both versions, so it's not cTrader issue, something is wrong with your indicator.
And please use editor code snippet for posting code.
@amusleh
amusleh
03 Jun 2022, 08:09
RE: RE: RE:
Hi,
m4trader4 said:
Why dint the usdjpy trade got close?
Because the chart was not a USDJPY chart.
I tested again and here is the result:
The cBot code I used:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using NATS.Client;
using System.Threading;
using System.Reflection;
using System.IO;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.FullAccess)]
public class NatsTestV1 : Robot
{
private string GlobalSymbolName;
#region nats
public IAsyncSubscription GlobalSchedulersub;
public IAsyncSubscription GlobalBroadCastsub;
public IConnection GlobalNormalConnection;
public IConnection GlobalBroadCastConnection;
public static string GlobalScheduleSubscribeMsg;
public static string GlobalSubscribeBroadcastMsg;
public static string GlobalPublishAlertSubject;
public static string GlobalSchedulerMessageWriteFile;
#endregion nats
public void ReadBroadCastmsg(string subjj)
{
Options opts = ConnectionFactory.GetDefaultOptions();
Options.ReconnectForever = 1;
opts.Url = Defaults.Url;
opts.Verbose = true;
opts.AllowReconnect = true;
GlobalBroadCastConnection = new ConnectionFactory().CreateConnection(opts);
GlobalBroadCastsub = GlobalBroadCastConnection.SubscribeAsync(subjj);
GlobalBroadCastsub.MessageHandler += BroadCastsub_MessageHandler;
GlobalBroadCastsub.Start();
}
private void BroadCastsub_MessageHandler(object sender, MsgHandlerEventArgs e)
{
var msg = Encoding.UTF8.GetString(e.Message.Data);
Print("NatsMessage : " + DateTime.UtcNow.ToString("HH:mm:ss:fff") + ":" + e.Message.Subject + ":" + msg);
//var SchedulerMessage = msg.Split(',');
var SchedulerMessage = msg.Split(new char[]
{
','
});
if (SchedulerMessage[0].Equals("Renko0", StringComparison.CurrentCultureIgnoreCase) && SchedulerMessage[1].Equals("CloseTrade", StringComparison.CurrentCultureIgnoreCase) && !string.IsNullOrWhiteSpace(SchedulerMessage[2]))
{
// BeginInvokeOnMainThread(() =>
try
{
ReadBroadCastCloseTrade(GlobalSchedulerMessageWriteFile, SchedulerMessage);
}
catch (Exception ex)
{
Print("exep close trade=" + ex.Message);
}
//);
}
}
public void ReadBroadCastCloseTrade(string SchMsgFile, string[] SchedulerMessage)
{
//String SchedulerMessageStatusWrite = "";
//string SchedulerMessageStatusDisplay = "";
//SchedulerMessageStatusDisplay = DateTime.UtcNow.ToString("HH:mm:ss") + ":" + SchedulerMessage[0] + ":" + SchedulerMessage[1];
//SchedulerMessageStatusWrite += SchedulerMessageStatusDisplay;
BeginInvokeOnMainThread(() =>
{
var positionsCBS = Positions.ToArray();
foreach (var psnCBS in positionsCBS)
{
Print("BuySell Positon= " + psnCBS.SymbolName);
if (SchedulerMessage[2].Equals("All", StringComparison.CurrentCultureIgnoreCase) || psnCBS.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal))
{
ClosePositionAsync(psnCBS, CallBackClosePositionAsync);
Print($"Position Closed {psnCBS.SymbolName}");
}
}
});
//var positionsCBS = Positions.FindAll("", Symbol.Name);
//File.WriteAllText(GlobalSchedulerMessageWriteFile + Symbol.Name + SchedulerMessage[0] + SchedulerMessage[1] + DateTime.UtcNow.ToString("ddMMyyyyHHmmssfff") + ".csv", Symbol.Name + SchedulerMessageStatusWrite);
}
private void CallBackClosePositionAsync(TradeResult tradeResult)
{
if (!tradeResult.IsSuccessful)
{
ClosePositionAsync(tradeResult.Position, CallBackClosePositionAsync);
}
}
protected override void OnStart()
{
GlobalSymbolName = Symbol.Name;
var SubscribeBroadcastMsg = string.Format("Nats_{0}_{1}_{2}", Account.Number, SymbolName, TimeFrame);
Print(SubscribeBroadcastMsg);
ReadBroadCastmsg(SubscribeBroadcastMsg);
}
protected override void OnStop()
{
Print("on stop executed");
GlobalBroadCastConnection.Close();
Print("Connection Closed =" + GlobalBroadCastConnection.IsClosed());
}
}
}
You have to use different connection names for each of your cBot instances, otherwise it will cause conflict and you will not be able to close the connection properly which result on timeout error.
I consider this thread closed, as it's now getting out of cTrader Automate API scope.
@amusleh
amusleh
01 Jun 2022, 15:05
( Updated at: 21 Dec 2023, 09:22 )
RE: RE: RE: RE: RE: RE: RE: RE:
abondi said:
The new version does not make any difference, it still displays the set EMA of the tick size used by the indicator.
e.g. in my case it shows the 20 EMA of the underlying 10 tick chart instead of the 20 EMA of the set 70 ticks in the indicator.
I can reproduce this on every computer I have lying around, with any broker version of cTrader.
Not sure why it does work for you
Hi,
I just tested, and it works fine (70 ticks custom chart based on 10 ticks chart):
The brown line is 20 EMA attached to 10 tick close, which is the actual chart, and the blue line is 20 EMA attached to custom tick chart close output.
Are you sure you are using the latest version? remove the indicator from your cTrader and download the new version, then install it.
@amusleh
amusleh
01 Jun 2022, 12:54
RE: RE: RE: RE: RE: RE:
abondi said:
I tried on cTrader installs of different brokers, same issue.
Luckily a 140 EMA of the underlying 10 Tick chart equals a 20 EMA of a 70 tick chart so I can use that.
But the problem with your script has not been resolved.
Hopefully you will make the interval configurable sooner than later so these issues will be resolved
Hi,
We released a new version of Custom Tick Chart indicator today, please test and let us know if it works or not.
@amusleh
amusleh
07 Jun 2022, 09:27
Hi,
It should show both client ID and secret when you click on the credentials "view" button.
I just checked your application and it does show both, can you tell me on which web browser you tried?
@amusleh