Topics
Replies
ctid5752082
07 Mar 2024, 16:37
( Updated at: 07 Mar 2024, 16:39 )
RE: Correct 'StopLoss' execution.
PanagiotisCharalampous said:
Hi there,
You cannot define a stop loss giving a P&L value. The stop loss is always set at a specific price level and it is triggered when the price reaches that level, regardless the position's P&L. You can see the stop loss price level on your chart.
Best regards,
Panagiotis
Good morning,
Thank you for the reply.
I am not sure where the confusion in terminology is.
However, I have an answer to the question.
I ran some ‘backtests’ and determined the solution.
The answer is - a) Triggered at ‘GrossP&L’ = -$10 , ‘NetP&L’ = -$8.75
Whatever the confusion in terminology is, what I was trying to understand was -
If I can set a dollar amount (which the application allows) as the ‘StopLoss’, and ‘Swap’ has accumulated, then does that affect the ‘StopLoss’ calculation?
By examining ‘backtest’ results, I can see that the predetermined dollar amount assigned when placing ‘order’ is ‘respected’, and that the ‘swap amount’ is not affecting that number.
Hence, the ‘GrossP&L’/'NetP&L' calculations, reflecting the ‘Swap’ amount.
Also, while I understand the confusion in terminology, the ‘cTrader’ ‘Desktop’ application uses ‘Profit and loss’ in the descriptive text, when a cursor moves over the column, or when examining the ‘pop up’ ‘position’ details tab.
I wasn't referring to the ‘Account’ ‘P&L’, but the ‘position’ ‘P&L’ (as called by the ‘cTrader’ ‘Desktop’ application, itself).
I updated this post, so that others with any confusion, regarding this, might be illuminated.
Thank you for your time,
@ctid5752082
ctid5752082
06 Mar 2024, 14:16
( Updated at: 06 Mar 2024, 15:08 )
RE: Correct 'StopLoss' execution.
PanagiotisCharalampous said:
Hi there,
Stop loss is irrelevant to the P&L. It's triggered at the defined price level.
Best regards,
Panagiotis
Good morning,
Thanks for the reply.
But further -
Noting that each ‘open position’ has a ‘Gross’ and ‘Net’ value.
I don't know if the terminology is ‘P&L’ - the ‘pop up description’ on the ‘Positions’ tab, describes the columns as -
a) ‘Gross’ - ‘Profit and loss before swaps and commissions’
b) ‘Net’ - ‘Profit and loss including swaps and commissions’
If I can set the ‘StopLoss’ as a dollar amount, then wouldn't the ‘value’/(‘P&L’) define the trigger?
If I have a ‘StopLoss’ of -$10, and I have a ‘Swap’ amount of +$1.25, then which would happen? -
a) Triggered at ‘GrossP&L’ = -$10 , ‘NetP&L’ = -$8.75
b) Triggered at ‘GrossP&L’ = -$11.25 , ‘NetP&L’ = -$10
I am sorry if I am misunderstanding a concept, but I am not sure of what is meant by ‘defined price level’?
Thank you for your time,
@ctid5752082
ctid5752082
10 Feb 2023, 14:58
An update -
I installed the latest 'cTrader' 'Desktop' (4.6.3.13401), direct from the ctrader.com website.
I previously was using my broker 'cTrader' download (4.5.9). I didn't realize that I could use the 'non broker' 'cTrader'.
They always seem to be a couple of 'minor version' numbers back from the version numbering from 'cTrader' directly. (About 2 weeks behind?).
Because this solution worked, and the issue originally discussed in this thread is dealt with.
Otherwise, I have to wait for my broker to catch up with there releases.
Can you confirm that there is no issues with using the 'cTrader' 'Desktop' platform downloaded from ctrader.com directly, instead of using the download available from my broker website?
Can you confirm there is no issue with accounts, and trading?
Thank you for your time,
@ctid5752082
ctid5752082
10 Feb 2023, 14:53
An update -
I installed the latest 'cTrader' 'Desktop' (4.6.3.13401), direct from the ctrader.com website.
I previously was using my broker 'cTrader' download (4.5.9). I didn't realize that I could use the 'non broker' 'cTrader'.
Anyway, I now get an 'error' 'pop up' window, as follows -
#Exception #6E789BB3 in cTrader 4.6.3.13401
An error has occurred. The problem has been submitted to the cTrader team. We apologize for the inconvenience. Please restart cTrader.
If run through 'debugger' in 'VS2022', I get an 'Exception User-Unhandled' error, with the details -
cTrader.Automate.Host.Dispatcher.Exceptions.AutomateDispatcherAbortException
HResult=0x80131500
Message=Exception_WasThrown
Source=cTrader.Automate.Host
StackTrace:
at cTrader.Automate.Host.Dispatcher.AutomateTargetDispatcher.InvokeLoopCycle(AutomateTargetDispatcherLoopMethods methods)
at cTrader.Automate.Host.Dispatcher.AutomateTargetDispatcher.NestedLoop(AutomateTargetDispatcherLoopMethods methods, CancellationToken cancellationToken)
at cTrader.Automate.Host.Router.AutomateTargetRouter.Wait[TMessage](Predicate`1 predicate, AutomateTargetDispatcherLoopMethods dispatcherLoopMethods)
at cTrader.Automate.Host.Router.AutomateTargetRouter.Wait[TMessage](Predicate`1 predicate)
at cTrader.Automate.Host.Router.AutomateTargetRouter.SendAndWait[TMessage](IAutomateMessage message, Predicate`1 predicate)
at cTrader.Automate.Host.Router.AutomateTargetRouter.SendAndWait[TMessage](IAutomateMessage message)
at cTrader.Automate.Host.Runtime.Controllers.Symbol.SmallSymbolSubscriptionController.TrySubscribe(SymbolName symbolName, Nullable`1& symbolQuoteDto)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.TrySubscribeSymbol(SymbolName symbolName)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.TrySubscribeSymbol(SymbolName symbolName, ISmallSymbol& smallSymbol, Nullable`1& errorCode)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.GetSymbol(SymbolName symbolName)
at cTrader.Automate.Host.Runtime.Api.Asset.SmallAssetConverter.<GetOrCreateExchanger>b__12_0(SymbolName n)
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at cTrader.Automate.Host.Runtime.Api.Asset.SmallExchangerFactory.Create(String from, IEnumerable`1 symbols)
at cTrader.Automate.Host.Runtime.Api.Asset.SmallAssetConverter.GetOrCreateExchanger(String from, String to)
at cTrader.Automate.Host.Runtime.Api.Asset.SmallAssetConverter.ConvertToDeposit(Decimal value, String fromAssetName)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.UpdateSymbolQuoteToDepositConversionRate(ISmallSymbol smallSymbol)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.OnBeforeSymbolTick(SymbolQuoteDto symbolQuoteDto)
at cTrader.Automate.Host.Runtime.Controllers.Symbol.SmallSymbolSubscriptionController.cTrader.Automate.Domain.Shared.Messaging.IAutomateMessageHandler<cTrader.Automate.Domain.Shared.SymbolApi.SymbolQuoteTickMessage>.Handle(SymbolQuoteTickMessage message)
at cTrader.Automate.Host.Dispatcher.AutomateTargetDispatcher.TryInvokeThreadSafeAction()
at cTrader.Automate.Host.Dispatcher.AutomateTargetDispatcher.InvokeLoopCycle(AutomateTargetDispatcherLoopMethods methods)
at cTrader.Automate.Host.Dispatcher.AutomateTargetDispatcher.NestedLoop(AutomateTargetDispatcherLoopMethods methods, CancellationToken cancellationToken)
at cTrader.Automate.Host.Router.AutomateTargetRouter.Wait[TMessage](Predicate`1 predicate, AutomateTargetDispatcherLoopMethods dispatcherLoopMethods)
at cTrader.Automate.Host.Router.AutomateTargetRouter.Wait[TMessage](Predicate`1 predicate)
at cTrader.Automate.Host.Router.AutomateTargetRouter.SendAndWait[TMessage](IAutomateMessage message, Predicate`1 predicate)
at cTrader.Automate.Host.Router.AutomateTargetRouter.SendAndWait[TMessage](IAutomateMessage message)
at cTrader.Automate.Host.Runtime.Controllers.Symbol.SmallSymbolSubscriptionController.SubscribeAvailable(SymbolName[] symbolNames)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.TrySubscribeSymbols(HashSet`1 symbolNames)
at cTrader.Automate.Host.Runtime.Api.Symbol.SmallSymbols.GetSymbols(SymbolName[] symbolNames)
at cTrader.Automate.Adapters.SymbolApi.SymbolsAdapter.GetSymbols(String[] symbolNames)
at cAlgo.Robots.sdfdsfdsf.OnStart() in C:\Users\xyz\Documents\cAlgo\Sources\Robots\sdfdsfdsf\sdfdsfdsf\sdfdsfdsf.cs:line 24
at cTrader.Automate.Adapters.RobotWrapper.OnStart()
at cTrader.Automate.Host.Runtime.Instances.SmallRobotInstance.<.ctor>b__6_2()
at cTrader.Automate.Host.Runtime.AlgoExecutor.SmallAlgoCodeExecutorExtensions.<>c.<.cctor>b__3_0(Action a)
at cTrader.Automate.Domain.Shared.Dispatcher.DispatcherAction.DispatcherActionImpl`1.Invoke()
at cTrader.Automate.Host.Runtime.AlgoExecutor.SmallAlgoCodeExecutor.ExecuteInternal(IDispatcherAction& action, Boolean raiseFrameEvent)
This exception was originally thrown at this call stack:
[External Code]
cAlgo.Robots.sdfdsfdsf.OnStart() in sdfdsfdsf.cs
[External Code]
I don't know if that helps with understanding the situation.
Thank you for your time,
@ctid5752082
ctid5752082
10 Feb 2023, 13:41
PanagiotisChar said:
Hi there,
Better share a complete cBot code so that we can try to reproduce.
Need help? Join us on Telegram
Need premium support? Trade with us
Thank you for your reply.
Here is some example code -
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;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class sdfdsfdsf : Robot
{
protected override void OnStart()
{
System.Diagnostics.Debugger.Launch();
string[] xSymbolsA;
cAlgo.API.Internals.Symbol[] xSymbolsX;
xSymbolsA = (this.Symbols.ToArray());
xSymbolsX = (this.Symbols.GetSymbols(xSymbolsA));
xSymbolsX = (xSymbolsX);
this.Stop();
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
The code either times out, or produces a bunch of 'Log' 'Error' messages similar to -
"10/02/2023 11:40:37.568 | Failed to get symbol 'USDCHF': Symbol not found or has no quotes."
This happens for pretty much all symbols.
Thank you for your time,
@ctid5752082
ctid5752082
10 Feb 2023, 13:34
( Updated at: 10 Feb 2023, 13:37 )
PanagiotisChar said:
Hi there,
Convert method is only available in 4.6.
Thank you for your reply.
I understand the answer.
However -
- why does it compile?
- why does 'VS2022' 'autosuggest' have the method listed?
For example -
If I was to code 'this.whatever();' (where there is NO 'user defined' method called 'whatever'), there would be a compile error stating -
Error CS1061 'projectExample' does not contain a definition for 'whatever' and no accessible extension method 'whatever' accepting a first argument of type 'projectExample' could be found (are you missing a using directive or an assembly reference?)
This is the error 'VS2022' would produce.
Conversely, the 'auto suggest' also has no idea of any method for 'whatever()'.
However (back to 'Double cAlgo.API.Asset.Convert(cAlgo.API.Asset, Double)')-
- why does it compile?
- why does 'VS2022' 'autosuggest' have the method listed?
Why does 'cTrader 4.5.9' know about 'Double cAlgo.API.Asset.Convert(cAlgo.API.Asset, Double)', if it is not exist until 'cTrader 4.6'?
That doesn't make any sense.
I accept the answer that 'Convert method is only available in 4.6.'. That is fine.
However -
- why does it compile?
- why does 'VS2022' 'autosuggest' have the method listed?
Thank you for your time,
@ctid5752082
ctid5752082
03 May 2024, 15:21 ( Updated at: 03 May 2024, 16:22 )
RE: EventHandler - ProtoOAGetPositionUnrealizedPnLRes
PanagiotisCharalampous said:
Good morning,
Thank you for the reply.
I realized that the sample wasn't up to date, so I updated the ‘ProtoBuf’ libraries.
I substituted the generated ‘c#’ files and rebuilt the ‘OpenAPI’ libraries.
That was noted in the question.
Also, I am not running samples code.
I used the code to generate ‘OpenAPI’ libraries for my own code.
However -
a) ‘this.xDisposablesX.Add(this.xClientX.OfType<ProtoOAGetPositionUnrealizedPnLRes>().Subscribe(OnPositionPnL));’
Also, the code generates a 'ProtoOAGetPositionUnrealizedPnLReq' message request successfully.
Hence, the ‘ProtoOAGetPositionUnrealizedPnLRes’ message response.
Why wouldn't it process ‘ProtoOAGetPositionUnrealizedPnLRes’ messages correctly.
Why would the code compile, run and receive messages, based on 'ProtoOAGetPositionUnrealizedPnLReq', but it can't process 'ProtoOAGetPositionUnrealizedPnLRes' messages?
Also, if I ‘run stop’ the code, and use ‘intermediate’ window -
? ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom(message.Payload)
{ "ctidTraderAccountId": "xxxxxxxx", "positionUnrealizedPnL": [ { … } ], "moneyDigits": 2 }
CtidTraderAccountId: xxxxxxxx
HasCtidTraderAccountId: true
HasMoneyDigits: true
HasPayloadType: false
MoneyDigits: 2
PayloadType: ProtoOaGetPositionUnrealizedPnlRes
PositionUnrealizedPnL: {[ { … } ]}
_hasBits0: 6
_unknownFields: null
ctidTraderAccountId_: xxxxxxxx
moneyDigits_: 2
payloadType_: 0
Google.Protobuf.IMessage.Descriptor: {Google.Protobuf.Reflection.MessageDescriptor}
positionUnrealizedPnL_: {[ { … } ]}
Note the field -
‘PayloadType: ProtoOaGetPositionUnrealizedPnlRes’
Is this correct? The spelling is wrong.
‘ProtoOaGetPositionUnrealizedPnlRes’
Shouldn't it be ‘ProtoOAGetPositionUnrealizedPnLRes’?
Is that why the message handling is failing to detect the message, despite the ‘protoBuf’ libraries being ‘up to date’, and the code compiling (proving that the relevant references to libraries, etc) is correct?
Also, note the ability to use the function ‘ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom(message.Payload)’
If the code isn't up to date, then why can I access ‘ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom()’
Thank you for your time,
@ctid5752082