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();
}
double tolerance = 50; // Define a tolerance in milliseconds
if (Math.Abs(millisecondsDifference - 300000) <= tolerance) { // This tick is likely the first tick after the close of the previous candle // You can use this information for your logic ManagePositions(); } Print("The number of ms's is {0}", millisecondsDifference);
}
However, as the number of milliseconds for each candle is not always exactly 300,000, it's very difficult to gauge what the close price of the candle will be
Not what I meant. :-)
The way I'm suggesting, you don't use your onTick or OnBar methods.
You create your own SEPARATE event handler method that's called every 5 minutes once you start the timer ticking.
It's in that new event method you will perform your logic, as you know it will reliably happen close to every 5 minutes.
Example:
using System;
using System.Timers;
//First, set up your timer
Timer t = new Timer(TimeSpan.FromMinutes(5).TotalMilliseconds); // Set the time (5 mins in this case)
t.AutoReset = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(your_method);
//You'll have to figure out the logic to start it exactly when you want
t.Start();
// This method is called every 5 mins
private static void your_method(object sender, ElapsedEventArgs e)
{
ManagePositions();
}
That's using the native C# timers, but hopefully you get my point.
cAlgo has it's own timer example, but make sure to read the notes they put in at the top of the code :
Also, what are the colors of your candles? Hopefully not the same color as your background?
Lastly, in the past there have been issues with charts not updating when there's a bug in the Intel Graphics display driver. You may have to update to teh latest, or roll back depending where you're at.
Your requirements are tricky because unless you're keeping track of time yourself and have a timer-method to check the time when a bar should be closing, there's no way to tell if a bar has closed or not until the next tick comes in.
For instance, a tick could come in on the current M1 candle at 12:59:55pm; the next tick might not come in until 1:00:05pm - difference of ten seconds. And regardless of time, that next tick could jump up down by several pips from the last value depending on what's happening in the market.
If you had a separate event method being called on say, every second, then your bot should execute the method at 1:00:00pm, in which can you can make the judgment call in your code to open a position.
Another alternative is once your threshold is crossed, you can wait to open a position once price is a pip, 2 pips, or x-pips above the threshold before waiting for the candle to close and next candle to open.
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.
@firemyst