TenkanSen Price crossover

Created at 31 Aug 2015, 18:44
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
whis.gg's avatar

whis.gg

Joined 31.08.2015

TenkanSen Price crossover
31 Aug 2015, 18:44


Hello, I would like to make a bot based on Price and TenkanSen crossover. However I couldn't manage to get previous value of price and tenkan to fill the crossover formula: "price[1]>tenkan[1] && price[0]<tenkan[0]". Could someone write me an example how to get previous values on price and indicator (such as tenkanSen from IchimokuKinkoHyo)?


@whis.gg
Replies

Spotware
01 Sep 2015, 23:52

Dear Trader,

For an indicator:

The index parameter of the “Calculate” method, represents each bar, ranging from 0 up to the current (last) bar. So to achieve retrieving the previous value of an indicator you should use indicatorName.ResultSeriesName[index]. In your case it should be:

public override void Calculate(int index)
{...
indicatorName.ResultSeriesName[index]> IchimokuKinkoHyoindicator.TenkanSen[index] && indicatorName.ResultSeriesName[index-1]<chimokuKinkoHyoindicator.TenkanSen[index-1]
...}

For a cBot:

You will have to create a MarketSeries with Symbol and/or timeframe as parameters. Then retrieve the DataSeries from the MarketSeries on preferred values of historical trendbars (open, close, high, low). As last you count the number of elements the DataSeries contains. Then you will be able to simulate the Calculate method in you cBot the following code snippet illustrates it:

MarketSeries data = MarketData.GetSeries(TimeFrame.Hour);

DataSeries data2 = data.Close;

int count = data2.Count; ...

price[count]>tenkan[count] && price[count-1]

Additionally we recommend you to have a look at our API guides.


@Spotware

whis.gg
02 Sep 2015, 10:05

Thanks for your reply!


@whis.gg