Topics
Replies
croucrou
01 Sep 2017, 01:27
I would do it like:
MovingAverage myEma; int x; double ema(int index) { return myEma.Result.Last(index); } protected override void OnStart() { myEma = Indicators.MovingAverage(MarketSeries.Close, 20, MovingAverageType.Exponential); } protected override void OnBar() { x = 10; for (int i = 1; i <= x; i++) { if (ema(i) >= MarketSeries.Low.Last(i) && ema(i) <= MarketSeries.High.Last(i)) break; else if (i == x && !(ema(i) >= MarketSeries.Low.Last(i) && ema(i) <= MarketSeries.High.Last(i))) Print("The price haven't touched EMA for the last {0} bars", i); } }
Notice that OnBar logic is executed with the start of new bar, so it doesn't take the action on the current bar into account.
If you want to include the current bar into the check, you might want to use OnTick.
@croucrou
croucrou
21 Aug 2017, 14:42
It has been answered several times:
/forum/calgo-reference-samples/543
@croucrou
croucrou
30 Jul 2017, 14:12
Like this?
[Parameter("Initial Starting Balance ($)", DefaultValue = 5000)] public double Initial StartingBalance { get; set; } [Parameter("Profit Target ($)", DefaultValue = 500)] public double ProfitTarget { get; set; } double _myEquity; double StartingBalance; protected override void OnStart() { _myEquity = Account.Equity; StartingBalance = InitialStartingBalance; } Protected override void OnTick() { if (Account.Equity >= (StartingBalance + ProfitTarget)) { foreach (var position in Positions) { ClosePosition(position); } StartingBalance = StartingBalance + ProfitTarget; } }
@croucrou
croucrou
14 Jul 2017, 21:46
RE:
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class InsideBarPatternRecognition : Indicator { [Output("Up Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)] public IndicatorDataSeries UpPoint { get; set; } [Output("Down Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)] public IndicatorDataSeries DownPoint { get; set; } public override void Calculate(int index) { var motherCandleHigh = MarketSeries.High.Last(1); var motherCandleLow = MarketSeries.Low.Last(1); var motherCandleOpen = MarketSeries.Open.Last(1); var motherCandleClose = MarketSeries.Close.Last(1); var childCandleHigh = MarketSeries.High.Last(2); var childCandleLow = MarketSeries.Low.Last(2); var childCandleOpen = MarketSeries.Open.Last(2); var childCandleClose = MarketSeries.Close.Last(2); if (childCandleHigh < motherCandleHigh && childCandleLow > motherCandleLow && Math.Abs(motherCandleOpen - motherCandleClose) > Math.Abs(childCandleOpen - childCandleClose)) DrawPoint(index); } // Draws a point next to the parent bar private void DrawPoint(int index) { UpPoint[index - 2] = MarketSeries.High[index - 2] + 0.0005; DownPoint[index - 2] = MarketSeries.Low[index - 2] - 0.0005; } } }
@croucrou
croucrou
07 Jul 2017, 22:43
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true)] public class CandleSize : Indicator { public override void Calculate(int index) { double candleSize = Math.Abs(MarketSeries.Low[index] - MarketSeries.High[index]); double candleSizePips = Math.Round(candleSize / Symbol.PipSize, 3); ChartObjects.DrawText( index.ToString(), candleSizePips.ToString(), // object name and text index, MarketSeries.High[index], // location VerticalAlignment.Top, HorizontalAlignment.Center); } } }
@croucrou
croucrou
08 Oct 2017, 17:46
Could you please explain, what does it mean exactly. Will it be possible to modify volume of a position during backtesting?
Are you able to say when could the update be possibly expected?
Thank you.
@croucrou