Topics
Replies
Spotware
16 Jul 2014, 11:33
If you refer to the quality of generated ticks we have great news for you. We are preparing tick data backtesting to be released. By using tick data backtesting you will be able to test your cBots with historical spreads. Furthermore, in tick data backtesting Bid and Ask prices come asynchronously with millisecond precision.
@Spotware
Spotware
15 Jul 2014, 10:02
Thank you for your suggestion. We will consider it. Additionally you can post your idea to vote.spotware.com.
@Spotware
Spotware
15 Jul 2014, 09:35
RE:
jobenb said:
Hi cTrader Team
I have a suggestion which will help the trader community immensely. Could you please add functionality that you can set the risk $ amount instead of the volume when placing an order and by dragging the stop loss from the order entry point you then adjust the volume so that you always risk the amount set as the available risk capital? If precise values are not possible then maybe using a Min Risk and Max Risk range and then a matching volume that match the closest within that range...
This will help a lot with setting Risk and Reward when placing an order.
Thank you!!!
Thanks for your suggestion, it will be taken under consideration.
@Spotware
Spotware
14 Jul 2014, 13:00
RE: RE:
It would be great if BeginInvokeOnMainThread() passes execution instantly to the main thread instead of waiting for the next Timer tick to occur.
BeginInvokeOnMainThread method will execute action instantly if there is no any handler executing by main thread and there is no handlers in the queue. Otherwise it will be put in the queue.
@Spotware
Spotware
14 Jul 2014, 10:21
( Updated at: 21 Dec 2023, 09:20 )
Next OnTimer invocation will be scheduled after current OnTimer invocation will be finished. Please have a look at the following example:
Are there any solution to pass "work objects" (Open/Close/Modify position) from arbitrary thread to "main" thread?
You can put code that works with API objects to actions queue and invoke actions from it in OnTimer handler. In such case actions will be invoked in main thread. Example:
using System; using System.Collections.Concurrent; using System.Linq; using System.Threading; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MultiThreadexample : Robot { private readonly ConcurrentQueue<Action> _actionsQueue = new ConcurrentQueue<Action>(); protected override void OnStart() { Timer.Start(new TimeSpan(1));//start timer with minimal interval var thread = new Thread(SeparateThreadHandler); thread.Start(); } private void SeparateThreadHandler() { try { //perform some actions in separate thread: Thread.Sleep(10000); //scedule action to be invoked in main thread: _actionsQueue.Enqueue(() => { //the following code will be invoked in main thread: var position = Positions.FirstOrDefault(p => p.TradeType == TradeType.Buy); if (position != null) ModifyPosition(position, Symbol.Bid - 10 * Symbol.PipSize, position.TakeProfit); }); } catch (Exception) { //you must always catch exceptions from separate thread } } protected override void OnTimer() { Action action; while (_actionsQueue.TryDequeue(out action)) { action(); } } } }
We plan to add method BeginInvokeOnMainThread in the future. It will simplify the above example.
@Spotware
Spotware
11 Jul 2014, 16:45
RE:
Hi AlexanderRC.
1) can I call Timer.Start() from non-main cBot thread?
No, it's not thread safe
2) Can I call Timer.Start with some "zero" value for the Timer to be invoked as soon as possible?
No, it will stop timer instead, otherwise it would mean smth like infinite calls of OnTimer method. In case you want to call OnTimer as soon as possible pass interval equal to one millisecond
private void ExecuteOnTimerASAP() { Timer.Start(TimeSpan.FromMilliseconds(1)); } protected override void OnTimer() { Timer.Stop(); //your code }
3) Can I call safely call Timer.Stop() from within OnTimer()?
Yes, you can safely call Stop() in OnTimer()
@Spotware
Spotware
11 Jul 2014, 09:21
Please make sure that WP indicator writes data to the corresponding indexes. In order to do that you can add Print statements to WP indicator. Output similar to the following could help you:
... Result[8543] = 1.2345 Result[8544] = 1.2567
Then you can change Print statement in your top level indicator:
Print("WP[{0}]: {1}", lastIndex, WP.Result[lastIndex]);
@Spotware
Spotware
17 Jul 2014, 10:03
Do you still observe the issue?
@Spotware