Topics
Replies
firemyst
16 Aug 2023, 02:07
I have been using NYC Servers for a long time and have never had any issues with them.
My VPS has always been up (they have a 100% uptime guarantee) except when I reboot my server to install the latest Windows updates.
It handles MT4/5 and cTrader perfectly and has all SSD storage.
They are co-located next to either NY or London, where the major Forex markets are so there's minimal latency.
@firemyst
firemyst
13 Aug 2023, 11:32
RE: RE: Close onBar order execution too late
michaelgriffiths00 said:
Many thanks for the reply firemyst. I have tried the following
protected override void OnTick()
{
// Handle price updates here
// Put your core logic here
if (IncludeTrailingStop)
{
SetTrailingStop();
}
DateTime currentTickTime = Server.Time;
DateTime lastCandleCloseTime = Bars.OpenTimes.Last(1).AddMinutes(5);
TimeSpan timeDifference = currentTickTime - lastCandleCloseTime;
double millisecondsDifference = timeDifference.TotalMilliseconds;
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 :
https://help.ctrader.com/ctrader-automate/references/Timer/Timer/#namespace
@firemyst
firemyst
13 Aug 2023, 05:21
Don't see a screen capture attached?
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.
@firemyst
firemyst
13 Aug 2023, 05:13
RE: How to add TimeFrame parameter to SMA?
Dagfx said:
Also how I can show 1h-4h level on a lower timeframe like 5m.
Why don't you look at the examples Spotware provided?
https://help.ctrader.com/ctrader-automate/indicator-code-samples/#multiple-timeframes
@firemyst
firemyst
13 Aug 2023, 05:10
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
firemyst
10 Aug 2023, 00:31
-Catch the creation of the new brick
When the “OnBar” event happens.
Or write your own in the “OnTick” method:
_currentIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes.LastValue);
if (_currentIndex != _previousIndex)
{
//Call your own OnBar method
OnBarForBot();
_previousIndex = _currentIndex;
}
-Get the color of the last brick
Do you mean actual color? Or is what you really want to know whether the bar closed up or down?
I'll assume the latter since most bots/indicators don't care about actual colors - just check if the previous close price is > or < the previous open price.
if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1))
///bullish bar
else
///bearish bar
@firemyst
firemyst
08 Aug 2023, 06:19
RE: RE: placelimitorder success
luca.tocchi said:
firemyst said:
What do you mean by “activated”? DO you mean when the order is actually executed? If so, just check the trade result:
TradeResult r = PlaceStopOrder(TradeType.Buy, SymbolName, volumeInUnits, Symbol.Bid + 15);
if (r.IsSuccessful) {
////
}
I mean when the pending order turns into position.
Then do what I suggested. If the trade result is successful, you know you have a position.
@firemyst
firemyst
07 Aug 2023, 23:58
If there's losing trades, you may want to consider leaving it as it is so you have to manually restart it. This does two things:
- makes sure your account doesn't blow up if it keeps continuously losing more than 3 trades
- gives you a chance to review the trades and what's happening.
If you really want it to start again the next day, you can try this:
- reset the losing count to 0
- keep track of the time. When your new day starts, allow the bot to proceed again. Something like this:
if (!allowTrades && Server.Time > 9am)
{
allowTrades = true;
}
In your OnTick method:
if (allowTrades)
{
////rest of method
}
else
return;
and you'd have to update your code:
if (losercount == 3)
{
allowTrades = false;
Stop();
}
@firemyst
firemyst
07 Aug 2023, 00:13
You might get your wish if you post in the correct forum:
https://ctrader.com/forum/suggestions
@firemyst
firemyst
17 Aug 2023, 00:50
Yes, there is a reason; you obviously don't understand some aspects on how the markets work.
Here's two links to help you better understand:
https://quant.stackexchange.com/questions/38527/forex-why-does-spread-peak-at-2200-gmt#:~:text=22%20GMT%20is%205pm%20nyc,can%20close%20the%20day%20flat.
https://www.forex.academy/why-does-the-forex-get-weird-at-5pm-usd/
If you get huge spreads outside of 5-6pm New York time, it could be because there's a major news release that's affecting the pair you're trading.
To avoid being taken out by the sudden huge spreads, some traders may do the following:
You have to decide what's best for you and your trading.
@firemyst