Topics
Replies
firemyst
21 Apr 2020, 12:01
RE:
PanagiotisCharalampous said:
Hi firemyst,
Indeed History provides the information of closed deals only and you need to filter by position id. Deals associated with open positions are not available in History.
Best Regards,
Panagiotis
Great! Good to know.
So my question is how am I able to get all the "Deal" information while the position is open?
I would like to draw lines on the chart and do other calculations based on those with my bots.
Thank you,
@firemyst
firemyst
21 Apr 2020, 11:23
RE:
PanagiotisCharalampous said:
Hi firemyst,
Deal information is available through History. Each entry represents a deal.
Best Regards,
Panagiotis
@Panagiotis:
See my original post. I tried that:
Similarly:
HistoricalTrade ht = History.FindLast(String.Empty, Symbol.Name)
only provides the overall information, not each modification.
That only brings back the overall trade, it doesn't appear to bring back every entry price/time along the way. The labels on my trades are empty.
Then I tried:
HistoricalTrade[] ht = History.FindAll(String.Empty, _s.Name, _p.TradeType);
but that doesn't seem to supply historical information on a trade until the overall position closes.
I want all the deal/trade information while the positions are still opened.
Am I missing something?
Thank you.
@firemyst
firemyst
09 Apr 2020, 09:14
( Updated at: 21 Dec 2023, 09:21 )
RE: RE: RE:
calgodemo said:
firemyst said:
calgodemo said:
Hey all,
At the bottom of the ctrader window where it shows 'Current Time', the time, then the timezone, my time is incorrect.
I have everything set to UTC-5 (NY, East coast - the same as my local system time which also says UTC-5), however the time itself is an hour behind, or in my case Central Standard Time.
Is it not updating for daylight savings? if my bot/indicator codes use the same timeframe will this affect execution at all?
Many thanks!
CaD
Can you post a screen capture please showing the time differences?
As of this posting, it is nearly 2am in NYC, yet my ctrader instance is trying to tell me it's still winter.
Thanks!
CaD
It's doing the same for me. I'm currently located in Perth Australia (UTC + 8), and I know the US East Coast is 12 hours behind. So it's 2:12pm here Thursday, meaning it's now 2:12am your time Thursday morning.
When I set my cTrader to UTC - 5, it's incorrect for me as well showing:
This is for @Panagiotis and Team @Spotware to respond to as to why it's happening.
@firemyst
firemyst
08 Apr 2020, 17:25
RE:
Tj11 said:
You could use the construction :
public TimeSpan timePassed;
protected override void OnTimer()
{
timePassed = timePassed + Timer.Interval;//example seconds
if (timePassed.Seconds > 10)
{
}
}
Good start of a work around. However, the biggest drawback is the timer event would have to be set to go off at the smallest common interval.
For instance, if you want an event to happen every 5 seconds and 30 seconds, you have to set the timer event to either 1 or 5 seconds; if you set it at 2, 3, 4, or something else, one of those 5/30 second events will be 'late'.
Similarly, if you want an event to happen every 30 seconds and another at 4 minutes (240 seconds), you have to set the timer event to occur at 1, 5, 10, 15, or 30 second intervals.
The next thing is change the ">" to ">="
:-)
@firemyst
firemyst
05 Apr 2020, 09:52
RE:
velu130486 said:
Dear All,
I got the below code for drawing Fibonacci lines into the chart from this forum. This Indicator will help me to draw the Fibonacci automatically based on last 100 Candle High Low, however I required your support to modify the coding to draw the Fibonacci lines based on last 100 - X candles (say 15).
Also this code does not draw the Fibonacci Extension levels, please help me to draw the same automatically
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; using System.Collections.Generic; { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Autofibo : Indicator { [Parameter("Look Back Period ", DefaultValue = 100)] public int lookback { get; set; } [Parameter("Series Timeframe")] public TimeFrame tf { get; set; } private MarketSeries series1; protected override void Initialize() { // Initialize and create nested indicators series1 = MarketData.GetSeries(tf); OnTimer(); Timer.Start(60); } protected override void OnTimer() { // Initialize and create nested indicators //find index var hidate = Time.Date; var lodate = Time.Date; var superhi = MarketSeries.Close.LastValue; var superlo = MarketSeries.Close.LastValue; var highval = series1.High; var loval = series1.Low; for (var i = 0; i < lookback; i++) { //find hi if (highval.Last(i) > superhi) { superhi = highval.Last(i); hidate = series1.OpenTime.Last(i); } //findlo if (loval.Last(i) < superlo) { superlo = loval.Last(i); lodate = series1.OpenTime.Last(i); } var bull = (hidate > lodate) ? true : false; var datechosen = (bull) ? lodate : hidate; //set value of line List<double> level = new List<double> { 0.0, 23.6, 38.0, 50.0, 61.8, 100 }; var now = MarketSeries.OpenTime.LastValue; var distance = superhi - superlo; //drawline foreach (var lev in level) { var dev = lev / 100 * distance; var val = (bull) ? superhi - dev : superlo + dev; ChartObjects.DrawLine(lev + "%", datechosen, val, now, val, (bull) ? Colors.Red : Colors.Blue, 1, LineStyle.Solid); ChartObjects.DrawText(lev + "% text", lev + "%", MarketSeries.OpenTime.Count + 1, val + 0.5 * Symbol.PipSize, VerticalAlignment.Center, HorizontalAlignment.Right, (bull) ? Colors.Red : Colors.Blue); } } } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... } } }
For this issue:
"I required your support to modify the coding to draw the Fibonacci lines based on last 100 - X candles (say 15)."
Just change the value in the look back.
Eg, in your example, you want to draw 100 - 15 == 85 lookback, then set the lookback value to 85 so it'll only be based on the last 85. If you want it to only do the last 15, then set the lookback parameter to 15.
There isn't any code modification required for that.
@firemyst
firemyst
05 Apr 2020, 09:45
RE:
calgodemo said:
Hey all,
At the bottom of the ctrader window where it shows 'Current Time', the time, then the timezone, my time is incorrect.
I have everything set to UTC-5 (NY, East coast - the same as my local system time which also says UTC-5), however the time itself is an hour behind, or in my case Central Standard Time.
Is it not updating for daylight savings? if my bot/indicator codes use the same timeframe will this affect execution at all?
Many thanks!
CaD
Can you post a screen capture please showing the time differences?
@firemyst
firemyst
01 Apr 2020, 14:11
RE:
irmscher9 said:
Hi there ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "myLabel", 8, 10, 2, "comment", true);After "myLabel" there are 3 numbers.
- What is 8?
- What is 10?
- And what is 2?
- Is "comment" necessary? Because cTrader gives me an error when I remove it.
Thank you
It's in the API documentation:
ExecuteMarketOrder method you have, the parameters are the trade type, the symbol and the volume. The additional optional parameters are label, stop loss, take profit, slippage and the comment, ans whether or not it has a trailing stop.
"Comment" isn't necessary, but the parameter itself is required in this case. If you don't want a comment, set it to an empty string or null.
@firemyst
firemyst
29 Mar 2020, 16:31
RE: RE: RE:
luca.tocchi said:
firemyst ha detto:
luca.tocchi ha detto:
pot la parte del codice in grassetto?
il programma controlla lo spread, se lo spread è maggiore di max spred deve è aggiunta un ispere e controlla altrimenti deve.
aiutatemi vi prego
....
casuale privato - nuovo Random();
protected
override void OnStart() -
_stochastic - Indicators.StochasticOscillator(K_Period,
Slow_K, D_Period, maType);
spread di var - Symbol.Ask - Symbol.Bid; while (spread > MaxSpread) -
Stampa("Spread suck, go in other asset");
Stampa([casuale. Simboli di SuoNeri(Conta)]);
deve aprire un altro punto e che la di spread> verifica sia falsa o stampa:
("Spread Ok");è questo il mio problema
....
Lo farei in modo non altro'.
Qualcosa lungo le linee di:
bool spreadOK = false; double spread = 0; int numberOfSymbols = Symbols.Count int numberOfSymbolsChecked = 0; while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols) { Symbol s = Symbols[random.Next(Symbols.Count)]; spread = s.Ask - s.Bid; if (spread <= MaxSpread) spreadOk = true; numberOfSymbolsChecked += 1; } if (!spreadOk) Print("Could not find any valid symbols with a good spread.");
I did it. But it gives me this error: Error CS0029: Could not implicitly convert type 'string' to 'cAlgo.API.Internals.Symbol'.
what's the problem?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class spread : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
[Parameter("Max Spread", DefaultValue = 1, MinValue = -5.0)]
public double MaxSpread { get; set; }
private Random random = new Random();
protected override void OnStart()
{
bool spreadOk = false;
double spread = 0;
int numberOfSymbols = Symbols.Count;
int numberOfSymbolsChecked = 0;
while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
Symbol s = Symbols[random.Next(Symbols.Count)];
spread = s.Ask - s.Bid;
if (spread <= MaxSpread)
spreadOk = true;
numberOfSymbolsChecked += 1;
}
if (!spreadOk)
Print("Could not find any valid symbols with a good spread.");
}
}
}
The problem is the line:
Symbol s = Symbols[random.Next(Symbols.Count)];
That lines doesn't return a Symbol object, but a string that's the name of the symbol.
You will need to use
Symbols.GetSymbol
to convert the string name to an actual Symbol object.
So first change the line to:
string symbolName = Symbols[random.Next(Symbols.Count)];
and then you need to add in and complete the line:
Symbol s = Symbols.GetSymbol....
@firemyst
firemyst
29 Mar 2020, 16:17
Yes.
You should be able to compute it as long as you know how to write the code to compute it. Keep in mind though it will be limited by cTrader's processing power, and you'll have to account for events like every tick. For instance, trading on a fast moving market like the US30 (Dow Jones), the computations might not always finish between each tick, so you'll have to set up event handlers instead of doing it in the Calculate (indicator) or OnTick (bots) methods.
@firemyst
firemyst
28 Mar 2020, 11:16
RE:
luca.tocchi said:
can anyone insert the part of code in bold?
the program checks the spread, if the spread is greater than max spred then it must add a random symbol and check otherwise it must continue.
please help me
....
private Random random = new Random();
protected override void OnStart()
{
_stochastic = Indicators.StochasticOscillator(K_Period, Slow_K, D_Period, maType);
var spread = Symbol.Ask - Symbol.Bid;
while (spread > MaxSpread)
{
Print("Spread suck, go in other asset");
Print(Symbols[random.Next(Symbols.Count)]);
//must open another symbol and verify that the condition of spread> maxspread is true or false
}
Print("Spread Ok");is this my problem
....
I would do it a completely different way.
Something along the lines of:
bool spreadOK = false;
double spread = 0;
int numberOfSymbols = Symbols.Count
int numberOfSymbolsChecked = 0;
while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
Symbol s = Symbols[random.Next(Symbols.Count)];
spread = s.Ask - s.Bid;
if (spread <= MaxSpread)
spreadOk = true;
numberOfSymbolsChecked += 1;
}
if (!spreadOk)
Print("Could not find any valid symbols with a good spread.");
@firemyst
firemyst
28 Mar 2020, 11:05
RE:
vice said:
Hello,
@PanagiotisCharalampous
if I should test sth. for you just send me a PM or write me an E-Mail.
Thx for the support.
Best regards
Please keep us posted on the outcome.
Would also like to know if there will be a future setting in cTrader so we can have it use up to 80-90% of our CPU while running normally.
Thanks!
@firemyst
firemyst
28 Mar 2020, 10:55
RE:
5026484 said:
Hey guys,
I'm using a indicator with a higher timeframe.
Initialize
_laguerreFilter = MarketData.GetSeries(LaguerreTimeFrame); // up to 2h---
_alf = Indicators.GetIndicator<AdaptiveLaguerreFilter>(_laguerreFilter, LaguerrePeriod);
To access in a lower timeframe the right value of the higher timeframe indicator I tried this
public override void Calculate(int index)
{
Result[index] = _rsi.Result[index];
int alfIndex = _alf.Result.Count - 1;
if (!double.IsNaN(_alf.Buy[alfIndex]))
{
ChartObjects.DrawText("info", "Laguerre Buy", StaticPosition.TopRight, Colors.Green);
DirectionBuy[index] = 50;
_bullish = true;
_bearish = false;
}
else if (!double.IsNaN(_alf.Sell[alfIndex]))
{
ChartObjects.DrawText("info", "Laguerre Sell", StaticPosition.TopRight, Colors.Red);
DirectionSell[index] = 50;
_bullish = false;
_bearish = true;
}I get always the same "Buy" of the indicator. Using it separately on a chart it shows the right changing values between Buy and Sell.
Hope the problem is exactly enough explained so that you can help me?
Cheers Markus
I'm not sure I fully understand, but from what I gather, you have two statements:
_laguerreFilter = MarketData.GetSeries(LaguerreTimeFrame); // up to 2h---
_alf = Indicators.GetIndicator<AdaptiveLaguerreFilter>(_laguerreFilter, LaguerrePeriod);
The first "_laguerreFilter" gets a timeframe; the second "_alf" gets a Period.
TimeFrames are not the same as a Period.
TimeFrames are what chart time frames you're looking at: H2, H4, M5, M1, etc.
Periods are how many candles/bars you're looking at: the last 5 bars, the last 13 bars, etc, of the current timeframe.
Otherwise I don't understand what your issue is. :-(
@firemyst
firemyst
21 Mar 2020, 15:06
RE:
tb135qet13 said:
any document or programming guide on cAlgo framework, I'm trying to code my strategy. but I found some data on how to place order during writing code i'm facing some errors, i appreciate if any can help me providing programming basics any pdf book.
https://ctrader.com/api/reference/
@firemyst
firemyst
21 Apr 2020, 12:29
RE:
PanagiotisCharalampous said:
Oh that's awesome! Thank you @Panagiotis!
Thanks for the code sample!
I'll give it a try and see what I can do. Assume no news is good news. :-)
@firemyst