Replies

croucrou
08 Oct 2017, 17:46

It will become possible to increase the size of a position of change the position’s side using cAlgo.

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

croucrou
21 Sep 2017, 16:41

If you run your robot on the M1 timeframe, the OnBar() logic will execute every minute.

If you are asking about backtesting, you select the timeframe from the menu below the symbol.


@croucrou

croucrou
20 Sep 2017, 19:49

OnBar() executes every minute on the M1 timeframe.


@croucrou

croucrou
07 Sep 2017, 16:11

If it is on the 1 min chart, isn't that a bid/ask issue?


@croucrou

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
28 Aug 2017, 17:04

RE:

Make a "for" loop up to 20, to check if the moving average is smaller than the bar's high and higher than the bar's low at the same time.


@croucrou

croucrou
25 Aug 2017, 16:11

It's working now.

Thank you.


@croucrou

croucrou
25 Aug 2017, 02:25

It has been giving the same information for last couple of days.

Have you experienced the same?


@croucrou

croucrou
21 Aug 2017, 14:42

It has been answered several times:

/forum/calgo-reference-samples/543


@croucrou

croucrou
31 Jul 2017, 17:10

Thank you for responding.

The funcionality could be set up by an output option: "Display = true/false".


@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
29 Jun 2017, 16:24

But this series is read only.

How to create a series based on e.g. my calculations?


@croucrou

croucrou
24 Jun 2017, 12:21

I don't think you can change the label, but couldn't you do that with bools?


@croucrou

croucrou
17 Jun 2017, 01:11

Why wouldn't you specify "if"conditions for the situations?


@croucrou

croucrou
16 Jun 2017, 19:53

You mean, you want to be able to manually turn on or off the series, to be visible or invisible on the chart?

Make a separate bool parameter for each series.


@croucrou

croucrou
04 Jun 2017, 02:42

It shows only the info for the last period.

Also sometimes one info covers another and it's unreadable at all.


@croucrou

croucrou
03 Jun 2017, 01:52

You can draw a short dotted line of one dot. You could create an arrow yourself of a few short lines by a method with x, y parameters.


@croucrou

croucrou
03 Jun 2017, 01:31

Use "OnBar()" instead of "OnTick()".


@croucrou