Topics
Replies
firemyst
26 May 2023, 03:45
RE:
amanordarkwa said:
I need help...
I want to write a cbot that can make pending order in a range from the open price of timeframe example 100pips from open price of Day timeframe.
This order is basically going to be stop orders (buy stop and sell stop)
Anyone can help with code?
Sample code to help get you started:
if (Bars.ClosePrices.Last[0] >= Bars.OpenPrices.Last[0] + (Symbol.PipSize * 100))
{
//if the current close price is >= the current open price + 100 pips, place your order
}
@firemyst
firemyst
26 May 2023, 03:41
Getting the first balance of the week or month should be relatively straight forward. A "Brute force" way of doing it would be:
1) have a timer job that runs every x-hours (need a timer in case you're watching a market on the weekend that isn't open and no tick data is coming through to trigger either the "Calculate" or "OnTick" meth event handlers)
2) In the timer event, check that Time.DayOfWeek == DayOfWeek.Sunday. If so, grab the account balance and save it for use however you need to (eg, into a file, into a global variable, or whatever)
Another option is to have your code running 24/7, and every so often check if Time.DayOfWeek == DayOfWeek.Sunday. If so, you know it's the first day of the week, and grab the balance.
To do the beginning of the month, it's the same principle, except the comparison changes a bit, to something along the lines of:
if (Time.Day == 1)
{
}
@firemyst
firemyst
25 May 2023, 03:35
Why do people never search for or look at the cTrader code samples Spotware provides?
@firemyst
firemyst
25 May 2023, 03:27
No, you shouldn't have to do that.
If you're running multiple instances of your bot and they all take 20 seconds to complete, what could be happening is cTrader and the CPU are going back/forth between bot threads and not getting to it right away. If you are running multiple instances, instead try running 2 or 3 sessions of cTrader with only a few instances each.
If you're just running the one bot instance, are you able to provide any sample code that can reproduce the behavior? For all we know, you might have code that erases chart objects, and then redraws later, or something else.
@firemyst
firemyst
25 May 2023, 03:23
Yes, you're missing something -- the symbol of the chart you've captured.
If you would actually provide the symbol being watched and confirm your time zone (it's obscured, but looks like it may be UTC + 0?), that may encourage others to look at their charts, investigate, and perhaps give you feedback.
@firemyst
firemyst
24 May 2023, 16:06
RE:
pick said:
I don't believe you can set the default for the indicator, but you can access the users current offset:
protected override void Initialize() { TimeSpan t = this.Application.UserTimeOffset; Print("User time offset = " + t.TotalHours); this.Application.UserTimeOffsetChanged += Application_UserTimeOffsetChanged; } private void Application_UserTimeOffsetChanged(UserTimeOffsetChangedEventArgs obj) { TimeSpan t = this.Application.UserTimeOffset; Print("User time offset changed = " + t.TotalHours); }
From there, it's easy to just combine the utc time with the offset for user time.
Thank you for this. Appreciate your time! I'll give it a try. :-)
@firemyst
firemyst
24 May 2023, 09:14
RE:
PanagiotisChar said:
Hi firemyst,
Unfortunately this info is not available through the API.
Need help? Join us on Telegram
Need premium support? Trade with us
Thank you for the confirmation @PanagiotisChar . That's a bummer, but oh well... at least I didn't overlook something that's stupidly simple :-)
@firemyst
firemyst
24 May 2023, 04:49
RE:
bjarman16 said:
Anyone have any examples of how i can implement when my positions close, it pauses trading and onstarts again the following hour?
You need to be a little more specific.
Suppose a trade closes at 12:15:36pm
By "onstarts the following hour", do you mean:
1) on the actual hour? Next trade can occur starting at 1pm?
2) or at least 1 hour from the time of close. Eg,nothing is done until at least 1:15:36pm?
@firemyst
firemyst
23 May 2023, 16:48
RE: RE:
Nick24 said:
Yes, I agree.If Spotware wants to get on the same level as TradingView, ProRealTime, etc, and destroy Metatrader permanent, platform sync between every application is a must.
I don't know why they keep saying this is not possible while meanwhile TradingView and ProRealTime for instance are literally both having it.
I agree as well with what you said. Another example that's "kicking butt" is the mobile version of ThinkTrader from ThinkMarkets.
For regular time based bar charts, it's one of the best and easiest to use mobile platforms out there... I use it more than the cTrader mobile because even simple things like getting sorting history correct (issue raised here) appears to be problematic for Spotware on the mobile platform.
@firemyst
firemyst
22 May 2023, 10:14
RE: RE:
BJORNBERNAU said:
Thank you very much!This may well work,
It works for me as I use json files all the time to save parameters, status of bots, etc etc. :-)
As for adding it into cTrader by default (instead of having to program it through the API), I would post it to the "Suggestions" forum:
@firemyst
firemyst
22 May 2023, 03:29
You could try adjusting your code so that your bots and indicators read/write your parameters to a json file.
Since you test your stuff in indicators first, the only actual input parameters that would have to be kept up to date are those for the indicator.
When your indicator runs, just write your parameters out to the json file.
Then when you start your bots, read in the json file to set all the parameters you need to. What I mean by that is, for example, you won't have to save the ticker-symbol nor the timeframe in the json parameter file, because you'll obviously set your bot instance to use the particular symbol/forex pair and timeframe you want to run against.
However, other parameters, like an EMA period or BB Std Dev, you'll probably want those saved to the json file.
@firemyst
firemyst
22 May 2023, 03:22
Good on you for having separate Dev/Production environments :-)
To answer your question, just copy the resulting .algo files over from one machine to the other, and double-click to install.
There's nothing fancy about it. Copy however you want (network share, memory stick, even by attaching to an email and then downloading the attachment on your trading machine)
On your live trading machine, just copy the algo files into the:
1) C:\Users\ [your windows username] \Documents\cAlgo\Sources\Robots for your robots
2) C:\Users\ [your windows username] \Documents\cAlgo\Sources\Indicators for your custom indicators
@firemyst
firemyst
21 May 2023, 08:51
( Updated at: 21 Dec 2023, 09:23 )
Within cTrader itself I don't think so. You can change the time zone, but since days start/end on midnight, the period separator will still appear whenever midnight happens regardless of the time zone you set:
So your best best would probably be either:
1) look for a custom indicator (or write your own) that draws a period separator at your desired time
2) set your time zone such that when it's midnight in that time zone, it's 5pm NY time.
@firemyst
firemyst
19 May 2023, 03:48
( Updated at: 20 May 2023, 16:17 )
RE: RE: RE: RE: RE:
meeting.chegini said:
Dear friend, do you want to teach me how to split the nucleus of an atom?This is a simple question! If you know the solution, please guide me
How to split the nucleus of an atom: there's plenty of "how to's" on Google and YouTube already on how to do it.
@firemyst
firemyst
18 May 2023, 08:18
RE:
umadrat2012 said:
Hi guys,
I am getting the following error in my code and I cant seem to fix it
if (is_16_00 && Convert.ToBoolean(go_long))
{
double take_profit = Symbol.Ask + Symbol.PipSize * tp_value;
var result = ExecuteMarketOrder(TradeType.Buy, Symbol.Name, Symbol.NormalizeVolume(0.1), Symbol.Ask, 1, 0, take_profit, "buy");
if (result.IsSuccessful)
{
Print("Buy order placed");
}
else
{
Print("Buy order failed with error code: ", result.Error);
}
}
Errors
Symbol.Ask highlighted ,Cannot convert from double to bool
take_profit highlighted, Cannot convert double to string
"buy" highlighted, cannot convert from string to bool
You have the wrong parameters for your call to the ExecuteMarketOrder method.
For starters, no ExecuteMarketOrder API call takes a "double" (Symbol.Ask) as the 4th parameter.
@firemyst
firemyst
27 May 2023, 18:00 ( Updated at: 21 Dec 2023, 09:23 )
I have no idea what you mean because your English is a bit broken.
All the timeframes you have selected as a preference or preferred are shown along the top of cTrader:
And you can select any of your preferred time frames from the 3 dots which give you a dropdown of all the available time frames:
@firemyst