I have emailed you the updated indicator code, in the end, I had to use the cTrader Localstorage API to save the values to your PC and read them from then cBot. The example code to access these values is shown below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
// https://help.ctrader.com/ctrader-automate/articles/for-developers/how-to-use-custom-indicators-in-cbots/
// https://help.ctrader.com/ctrader-automate/references/Localstorage/LocalStorage/
[Robot(AccessRights = AccessRights.None)]
public class MacdDivergenceExample : Robot
{
private MACDDivergence _macd;
[Parameter(DefaultValue = "Hello world!")]
public string Message { get; set; }
protected override void OnStart()
{
_macd = Indicators.GetIndicator<MACDDivergence>(26, 12, 9, true, true, false);
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnBar()
{
var divergenceUp = LocalStorage.GetString("DivergenceUp", LocalStorageScope.Device);
var divergenceDown = LocalStorage.GetString("DivergenceDown", LocalStorageScope.Device);
Print("divergenceUp: " + divergenceUp);
Print("divergenceDown: " + divergenceDown);
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
here are some useful links.
You can find the additional code in the indicator to save the values as:
LocalStorage.SetString("DivergenceUp", "false", LocalStorageScope.Device);
LocalStorage.SetString("DivergenceDown", "true", LocalStorageScope.Device);
You can edit the indicator to as you see for to get any values, you may also want to add:
- Classic Bullish
- Reverse Bullish
- Classic Bearish
- Reverse Bearish
Please note this does not work with a backtest.