Topics
Replies
itmfar
21 Nov 2017, 17:59
RE:
Panagiotis Charalampous said:
Hi itmfar,
No this is currently not possible in cTrader.
Best Regards,
Panagiotis
Thanks Panagiotis . what about the % open positions , in Ctrader under sell and buy there are red and green lines which indicate % of client account with open positions?
@itmfar
itmfar
15 Nov 2017, 11:04
RE:
Paul_Hayes said:
Hi,
Take a look at this helper, it is free.
https://clickalgo.com/ctrader-cbot-indicator-data-logger
Paul.
thank you Pual but is there any way to save file in indicator instead of Cbot?
@itmfar
itmfar
08 Nov 2017, 15:03
RE:
Panagiotis Charalampous said:
Hi itmfar,
With some more coding, you can develop something more proper, that could also take dates as input. But it will need somebody to devote time for this to developed. If i find some free time soon, then I might prepare something for you.
Best Regards,
Panagiotis
that's kind of you .
@itmfar
itmfar
08 Nov 2017, 13:25
RE:
Panagiotis Charalampous said:
Hi itmfar,
Thanks now it is more clear what you are trying to achieve. You can try the following approach
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } protected override void Initialize() { } public override void Calculate(int index) { if (IsLastBar) { ChartObjects.RemoveAllObjects(); for (int i = MarketSeries.Close.Count - 20; i < MarketSeries.Close.Count - 10; i++) ChartObjects.DrawVerticalLine("v" + i, i, Colors.White); } } } }Let me know if this works for you.
Best Regards,
Panagiotis
thanks it works perfectly . is there any sensible solution for limiting time? such as modifying special date to start (start only after September 2017 to December 2017) ,instead of my method?
@itmfar
itmfar
08 Nov 2017, 12:11
RE:
Panagiotis Charalampous said:
Hi irmfar,
It will repeat the last result since you are instructing the indicator to print only when it is at the last bar. You should change the condition as follows
public override void Calculate(int index) { if (!IsLastBar) Print(" print only once for each bar at the moment" + index); }Let me know if this helps.
Best Regards,
Panagiotis
it totally helps. thank you
@itmfar
itmfar
08 Nov 2017, 11:56
RE: RE: RE:
andi21 said:
itmfar said:
andi21 said:
Or more easy: just remember the incoming index parameter in the calculate method and if this index changed then it is a new bar (it is late so this easier solution came a little later than my previous answer ;) ).How we can save old index and comparing with new one? because as result of each tick both parameters in Calculate would be update and reffer to same index
You could do something like this:
public int lastCalculatedIdx = -1; public override void Calculate(int index) { bool gotANewIdxSoANewBar = index > lastCalculatedIdx; if (gotANewIdxSoANewBar) { lastCalculatedIdx = index; // Do some calculations } }thanks alot. it works
@itmfar
itmfar
08 Nov 2017, 11:27
( Updated at: 21 Dec 2023, 09:20 )
RE:
Panagiotis Charalampous said:
Hi itmfar,
I created an example based on your code and it seems to be working as expected. See code sample and screenshot below
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } private int secondGap; private int firstGap; protected override void Initialize() { secondGap = MarketSeries.Close.Count - 10; firstGap = MarketSeries.Close.Count - 20; } public override void Calculate(int index) { if (index > firstGap && index < secondGap) ChartObjects.DrawVerticalLine("v" + index, index, Colors.White); } } }Let me know if I misunderstood something.
Best Regards,
Panagiotis
thanks. it is ok. but it wont update if new bar comes up ,these 9 lines remain in their pervious positions but i need them to be drawn from 20 - 10 last bars at the moment.
@itmfar
itmfar
08 Nov 2017, 11:19
RE:
Panagiotis Charalampous said:
Hi itmfar,
Calculate function is invoked once for each bar and then for each tick for the last bar. The reason this happens is that for each tick the values for the last bar change therefore the indicator might need to be recalculated. If you want to skip recalculation for the last bar, you might consider using the IsLastBar property of the Indicator.
Best Regards,
Panagiotis
thanks for your response. i have changed my code:
public override void Calculate(int index)
{
if (IsLastBar)
Print(" print only once for each bar at the moment" + index);
}
but it still repeats last result
08/11/2017 12:47:27.789 | print only once for each bar at the moment2098
08/11/2017 12:47:27.914 | print only once for each bar at the moment2098
08/11/2017 12:47:33.102 | print only once for each bar at the moment2098
08/11/2017 12:47:33.399 | print only once for each bar at the moment2098
08/11/2017 12:47:33.774 | print only once for each bar at the moment2098
08/11/2017 12:47:34.071 | print only once for each bar at the moment2098
08/11/2017 12:47:34.321 | print only once for each bar at the moment2098
@itmfar
itmfar
08 Nov 2017, 09:46
RE:
hook_1000 said:
To late to reply but, if you still having this trouble, then use OpenTime for the current bar and save it in a variable. On every tick compare open time, if its changed, its your new bar.
Would you please explain how to save OpenTime in calculate() and save it? it is always last openTime for each tick
public int currentIndex;
public override void Calculate(int index)
{
currentIndex = MarketSeries.OpenTime.LastValue;
Print( " last " + MarketSeries.Open.LastValue);
}
@itmfar
itmfar
08 Nov 2017, 09:29
RE:
andi21 said:
Or more easy: just remember the incoming index parameter in the calculate method and if this index changed then it is a new bar (it is late so this easier solution came a little later than my previous answer ;) ).
How we can save old index and comparing with new one? because as result of each tick both parameters in Calculate would be update and reffer to same index
@itmfar
itmfar
22 Nov 2017, 09:21
RE:
Panagiotis Charalampous said:
Thanks for your response but it did not work, I have modified my Indicator
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewIndicator : Indicator
{
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
private MacdCrossOver _MACD;
public bool Test = false;
public int myIndex;
public bool myBuy;
protected override void Initialize()
{
_MACD = Indicators.MacdCrossOver(26, 12, 9);
myBuy = false;
}
public override void Calculate(int index)
{
if (_MACD.MACD[index] > _MACD.Signal[index])
{
myBuy = true;
}
myIndex = index;
if (index % 2 == 1)
Test = true;
}
}
}
and it is my Cbot
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
private NewIndicator newIndicator;
protected override void OnStart()
{
newIndicator = Indicators.GetIndicator<NewIndicator>();
}
protected override void OnTick()
{
var test = newIndicator.Test;
Print("test " + test);
var myindex = newIndicator.myIndex;
Print("my index " + myindex);
var mybuy = newIndicator.myBuy;
Print("buy " + mybuy);
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
now for each tick output is test false- index 0 - buy false.
@itmfar