Ichimoku cBot
09 Sep 2016, 14:01
Hi guys, I need help to make this cBot work.
I have Zero knowledge on coding thus I copy pasted this cBot to backtest my strategy(Ichimoku based).
I keep getting expected error on the last "}"
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 MidasIndex : Robot
{
[Parameter(DefaultValue = 9)]
public int periodFast { get; set; }
[Parameter(DefaultValue = 26)]
public int periodMedium { get; set; }
[Parameter(DefaultValue = 52)]
public int periodSlow { get; set; }
[Parameter(DefaultValue = 26)]
public int DisplacementCloud { get; set; }
[Parameter(DefaultValue = "MyLabel")]
public string MyLabel { get; set; }
[Parameter(DefaultValue = 10000)]
public int Volume { get; set; }
[Parameter("Stop Loss", DefaultValue = 25, MinValue = 0, MaxValue = 100)]
public int StopLossPips { get; set; }
[Parameter("Take Profit", DefaultValue = 20, MinValue = 0, MaxValue = 100)]
public int TakeProfitPips { get; set; }
protected override void OnStart()
{
ichimoku = Indicators.GetIndicator<IchimokuCloud>(periodFast, periodMedium, periodSlow, DisplacementCloud);
{
var closedAbove = MarketSeries.Close.Last(1) > ichimoku.SenkouSpanA.Last(1);
var openedInsideKumo = MarketSeries.Open.Last(1) <= ichimoku.SenkouSpanA.Last(1) && MarketSeries.Open.Last(1) >= ichimoku.SenkouSpanB.Last(1);
var distanceFromKumo = (MarketSeries.Close.LastValue - ichimoku.SenkouSpanA.LastValue) / Symbol.PipSize;
if (closedAbove && openedInsideKumo && distanceFromKumo <= 30)
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, MyLabel, StopLossPips, TakeProfitPips);
var closedBelow = MarketSeries.Close.Last(2) > ichimoku.SenkouSpanB.Last(2);
var openedInsideKumo = MarketSeries.Open.Last(2) <= ichimoku.SenkouSpanB.Last(2) && MarketSeries.Open.Last(2) >= ichimoku.SenkouSpanA.Last(2);
var distanceFromKumo = (MarketSeries.Close.LastValue - ichimoku.SenkouSpanB.LastValue) / Symbol.PipSize;
if (closedBelow && openedInsideKumo && distanceFromKumo <= 30)
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, MyLabel, StopLossPips, TakeProfitPips);
}
IchimokuKinkoHyo = ichimoku ;}
}
}
}
Replies
GDPR-24_203122
11 Sep 2016, 22:36
About Senkou A & B
Hi!
I often use the Crosshair tool to check indicator lines and stuff. It has a vertical and horizontal line. If you plan on using ichimoku in your bot, you should also consider, that the Kumo (the Cloud from senkou A&B) is drawn late (26 periods on default, I think) in the chart. That means that if you want to see, for example, if the price is above the Cloud at a certain point in time, you need to check the Senkou A & B from 26 periods past, not their last value.
croucrou
11 Sep 2016, 23:46
You are right! The indicator draws itself ahead and does not repaint. In this case the last part should be changed to:
var distanceFromUpKumo = (Symbol.Bid - ichimoku.SenkouSpanA.Last(26)) / Symbol.PipSize;
var distanceFromDownKumo = (ichimoku.SenkouSpanA.Last(26) - Symbol.Ask) / Symbol.PipSize;
if (positionsBuy.Length == 0 && positionsSell.Length == 0)
{
if (MarketSeries.Open.Last(1) <= ichimoku.SenkouSpanA.Last(27) && MarketSeries.Open.Last(1) > ichimoku.SenkouSpanB.Last(27))
{
if (MarketSeries.Close.Last(1) > ichimoku.SenkouSpanA.Last(27))
{
if (distanceFromUpKumo <= 30)
{
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Buy", StopLossPips, TakeProfitPips);
}
}
}
if (MarketSeries.Open.Last(1) >= ichimoku.SenkouSpanA.Last(27) && MarketSeries.Open.Last(1) < ichimoku.SenkouSpanB.Last(27))
{
if (MarketSeries.Close.Last(1) < ichimoku.SenkouSpanA.Last(27))
{
if (distanceFromDownKumo <= 30)
{
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sell", StopLossPips, TakeProfitPips);
}
}
}
}
The Crosshair tool is essential. I was printing the values and didn't notice, why do they differ from what is on the chart. Thanks!
@croucrou

croucrou
10 Sep 2016, 16:36
I would write it like this. I might be wrong, but it seems to me, that the indicator repaints.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MidasIndex : Robot { [Parameter(DefaultValue = 9)] public int periodFast { get; set; } [Parameter(DefaultValue = 26)] public int periodMedium { get; set; } [Parameter(DefaultValue = 52)] public int periodSlow { get; set; } [Parameter(DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Stop Loss", DefaultValue = 20)] public int StopLossPips { get; set; } [Parameter("Take Profit", DefaultValue = 25)] public int TakeProfitPips { get; set; } IchimokuKinkoHyo ichimoku; protected override void OnStart() { ichimoku = Indicators.IchimokuKinkoHyo(periodFast, periodMedium, periodSlow); } protected override void OnBar() { var positionsBuy = Positions.FindAll("Buy"); var positionsSell = Positions.FindAll("Sell"); var distanceFromUpKumo = (Symbol.Bid - ichimoku.SenkouSpanA.LastValue) / Symbol.PipSize; var distanceFromDownKumo = (ichimoku.SenkouSpanA.LastValue - Symbol.Ask) / Symbol.PipSize; if (positionsBuy.Length == 0 && positionsSell.Length == 0) { if (MarketSeries.Open.Last(1) <= ichimoku.SenkouSpanA.Last(1) && MarketSeries.Open.Last(1) > ichimoku.SenkouSpanB.Last(1)) { if (MarketSeries.Close.Last(1) > ichimoku.SenkouSpanA.Last(1)) { if (distanceFromUpKumo <= 30) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Buy", StopLossPips, TakeProfitPips); } } } if (MarketSeries.Open.Last(1) >= ichimoku.SenkouSpanA.Last(1) && MarketSeries.Open.Last(1) < ichimoku.SenkouSpanB.Last(1)) { if (MarketSeries.Close.Last(1) < ichimoku.SenkouSpanA.Last(1)) { if (distanceFromDownKumo <= 30) { ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sell", StopLossPips, TakeProfitPips); } } } } } } }@croucrou