Nor does it seem to be returned when checking a TradeResult object for error messages (unless I'm doing that wrong).
Can you share the code you are using so that we can see what you are doing? The below should work
Print("Error: {0}", TradeResult.Error);
Best regards,
Panagiotgis
Below is some sample code you can run on a forex symbol like EURJPY to demonstrate the lack of information.
The output from the log is:
Note that it doesn't say, “Nothing to Change” in the error reported, the symbol name, or anything. Just says, “invalid request”, which to me makes no sense when someone's looking for the actual error message in log files. “invalid request” can happen for any number of reasons, and means we have to keep bothering our broker to find out what and why was an “invalid request”.
Code to reproduce:
using System;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TokyoSessionStrategy : Robot
{
private Position _p;
private int _tickCount;
protected override void OnStart()
{
_p = null;
_tickCount = 0;
}
protected override void OnTick()
{
TradeResult r;
if (_p == null)
{
r = ExecuteMarketOrder(TradeType.Buy, SymbolName, 1000, "TESTBOT");
if (!r.IsSuccessful)
{
Print("Order not successful. Please restart bot. Error message {0}", r.Error.Value.ToString());
}
else
{
_p = Positions.Find("TESTBOT");
}
}
Print("TICK COUNT {0}", _tickCount.ToString());
if (_tickCount % 5 == 0 && _p != null)
{
Print("Modifying order");
r = _p.ModifyStopLossPrice(_p.StopLoss.GetValueOrDefault());
if (!r.IsSuccessful)
{
Print("Order not successful. Error message:");
Print("1 {0}", r.Error);
Print("2 {0}", r.Error.Value.ToString());
}
}
_tickCount++;
}
protected override void OnStop()
{
if (_p != null)
{
_p.Close();
}
base.OnStop();
}
}
}
Balance/equity are not only affected by deposit/withdrawals.
You're initial post only referred to “balance”, not “equity”.
An account balance either increases in funds available, or decreases. Those could be caused by transfers, positions being closed, or something else. But at the end of the day, an account balance is either going to “increase” or “decrease”, either from funds being deposited into the account, or withdrawn from the account.
So genuinely asking, what else is “balance” affected by in your situation?
Why do you assume that a cBot is running when a deposit/withdrawal takes place?
I haven't assumed a cbot has to be running when a deposit/withdrawal takes place.
However, your initial post said you need to access the information via API. Code can only access an API when code is executed. Now, since your post is in the “calgo” forum, which is primarily for bots/indicators/plugins, even by Spotware's own definition: “cTrader Algo is an all-in-one solution that gives users the opportunity to use various automated trading tools including custom indicators, cBots and plugins.”
Couple that with the fact an API can only be access when code is executed, …. that's the reasoning. Whether it's a bot running, or even something simple like dragging/dropping an object on the screen, code has to be executed for an API to be accessed.
If it's for another reason not related to a bot/indicator/plugin, like you're creating your own trading interface or application, or calling a web service or something else, then perhaps you should have posted in either the “Fix API” or “Open API” forums?
Moreover, withdrawal and deposits are basic properties of an account. It shouldn't be necessary to convince anyone about this.
No disagreement about this. :-)
I would suggest putting these into the “Suggestions” forum if you want to see Spotware possibly implement them in the future.
Because I want to be able calculate balance/equity drawdown within certain time frames.
How do you calculate this without any information on the cash flow?
You check the account balance. Set up your own timer event, and check every x minutes/hours.
Or on every tick or like every 3rd tick that comes in.
And program your bot/indicator to only check within the time frames you want to check.
You have your current account balance. Next time you check, if it increase you know how much came in; if it decreases you know how much went out. That would be your cash flow.
So if your account balance is $10k, and in 3 ticks it's $10.5k, you know $500 came in. What's the difference between that and having a “Deposit event” that was triggered with $500?
//Class variable
double _previousAccountBalance = Account.Balance;
//in onTick or whenever, call a method to check your balance
CheckMyBalance();
//basic structure for method
private void CheckMyBalance()
{
if (Account.Balance > _previousAccountBalance)
{
///a deposit came in
//do what you need to
//taking into account whether or not a position was closed
}
else if (Account.Balance < _previousAccountBalance)
{
///a withdrawal happened
//do what you need to
//taking into account whether or not a position was closed
}
}
That will have your updated balance which you can use to calculate for risk management purposes, because you'll only be allowed to base your risk management on whatever's in your account anyway.
An example of an even easier method, which I use, is:
if (Symbol.MarketHours.IsOpened()) { // market is open, do what you want }else { //market is closed for the symbol. Do what you want }
Market hours are different to market sessions. Market hours are set by the broker. Market sessions are global.
Fair point. But the OP said when the market was “open” and didn't specifically mention “market sessions” (although the OP did say “inactive” just as they said “open”).
So since it was vague to me, I provided another alternative just in case that's what the OP meant.
PLease consider posting what you want to the “Suggestions” forum as this forum is for technical support and won't be looked at by Spotware for suggestions
First of all, you can choose what lines you want displayed on the chart:
Second, if you write your own code, just get the symbol's “ASK” price or “BID” price depending on what you want to display.
eg: Symbol.Ask
As the topic says I need Bid and Ask Candles
Then as I said, you'll have to write your own code. There is no option to display both bid and ask candles next to each other, or anywhere together, on a chart.
firemyst
22 Nov 2024, 02:11 ( Updated at: 22 Nov 2024, 05:59 )
RE: Order Execution Error : Nothing to change
PanagiotisCharalampous said:
Below is some sample code you can run on a forex symbol like EURJPY to demonstrate the lack of information.
The output from the log is:
Note that it doesn't say, “Nothing to Change” in the error reported, the symbol name, or anything. Just says, “invalid request”, which to me makes no sense when someone's looking for the actual error message in log files. “invalid request” can happen for any number of reasons, and means we have to keep bothering our broker to find out what and why was an “invalid request”.
Code to reproduce:
@firemyst