firemyst
27 Aug 2023, 15:22
( Updated at: 27 Aug 2023, 15:23 )
I think your logic in both loops is wrong because you're changing the average price every time you do the loop.
That is, look at #1. When you have 10 positions open and the averagePrice (in pips) is < -10, you modify one position.
Then you do another loop and calculate the average again. The average will change because you've already modified one position.
Same with #2. The average will change each time when you close a position.
What you should do is calculate the average once with all the current positions, and then do you loop. This way, the average won't change on each loop iteration.
For example:
double averagePrice = Positions.Average(x => x.Pips);
if (averagePrice > 11){
foreach (var position in Positions)
{
ClosePositionAsync(position);
}
}
and still get values that differ between the .Last(1) outputs and the Market Snapshot tool today as shown below:
Times are UTC + 8
I would expect the output from ma1.Result.Last(1) to be the same, or at least within mathematical rounding distance of the displayed value on the chart.
In the case of the 4 EMA, calgo returns a value that differs by 20% of a pip. This difference certainly shouldn't be acceptable.
Everything you've done seems legit to me. The OnException probably isn't being called because it might not be anything to do with your code, but rather a bug in cTrader itself.
There are two more things you can try:
put individual try/catch blocks around each assignment statement in your OnStart method to see if that does anything in terms of catching something. I doubt it, but you never know.
2. look in your Windows Event view logs for the big red ERROR indication. There might be a clue in there on what's happened. Either way, it would be great to post that information too because that will also help @Spotware @cTraderTeam in investigating/fixing the issue if it is indeed a bug with cTrader itself.
firemyst
20 Aug 2023, 13:06
( Updated at: 21 Dec 2023, 09:23 )
Report the issue to Spotware through cTrader:
You should also provide more information than you have here if you can. For instance, go into your Windows Event Logs, find the errors, and copy/paste that information and post it as well.
The volume parameter is second, right after SymbolName, still no order placed when running the cBot.
This code is just an example so that I can discover the real problem, because none of the platform's native cBots are working, I tested several and none of them placed orders when executed.
Also, in addition to printing to the log, if you want a text file, you can use C#'s ability to write to text files, csv files (so you can later import into Excel if you want), or even json or xml formatted files.
Does that mean you were not able to reproduce the problem or, you didn't even try to?
You can always compare Account.Margin with its calculated value (by applying its formula), through prints, whenever a position is opened/closed.
I guess there's no big science behind it.
Why would anyone have tried when you didn't show what was wrong (through screen captures) or explain how such values were wrong?
Basically, if you can't take the time to explain/show the details, nobody is going to waste their time trying to find an alleged needle-in-a-haystack that nobody else seems to have reported.
Just have your bot check all your positions 1 per hour, every 4 hours, every 15 minutes, or however often you want for any positions open more than 5 days.
//pseudo code
DateTime currentTime = DateTime.Now;
foreach (Position p in Positions)
{
if (p.EntryTime < (currentTime - (5 days)) )
p.Close();
}
firemyst
27 Aug 2023, 15:22 ( Updated at: 27 Aug 2023, 15:23 )
I think your logic in both loops is wrong because you're changing the average price every time you do the loop.
That is, look at #1. When you have 10 positions open and the averagePrice (in pips) is < -10, you modify one position.
Then you do another loop and calculate the average again. The average will change because you've already modified one position.
Same with #2. The average will change each time when you close a position.
What you should do is calculate the average once with all the current positions, and then do you loop. This way, the average won't change on each loop iteration.
For example:
@firemyst