Replies

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

croucrou
10 Sep 2016, 16:02

Of course I should have written:

/ Symbol.PipSize

and not:

* Symbol.PipSize

Couldn't edit here.


@croucrou

croucrou
05 Sep 2016, 01:07

You could verify the heiken up/down condition within the indicator and output it as bool.

Honestly, I would use int, where 1 would be for up, -1 for down and 0 is for doji candle.


@croucrou

croucrou
04 Sep 2016, 22:23

Shouldn't it be:

Print("LatestHAClose:", _heikenAshi.haClose.Last(1));
Print("LatestHAOpen:", _heikenAshi.haOpen.Last(1));

instead of:

Print("LatestHAClose:", _heikenAshi.haClose[1]);
Print("LatestHAOpen:", _heikenAshi.haOpen[1]);

@croucrou

croucrou
04 Sep 2016, 16:05

Aren't you missing this part:

var index = m.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

 


@croucrou

croucrou
02 Sep 2016, 02:52

 Forget the previous one. See this:

var position= Positions.Find("label");

Math.Abs(targetPrice - position.EntryPrice) * Symbol.PipSize * Symbol.PipValue * position.Volume - Symbol.Spread - position.Commisions - positions.Swap

@croucrou

croucrou
01 Sep 2016, 23:59

var position= Positions.Find("label");

(targetPrice - position.EntryPrice) * Symbol.PipValue * position.Volume - Symbol.Spread - position.Commisions - positions.Swap

 


@croucrou

croucrou
01 Sep 2016, 15:10

Hello, change every "private" to "public" within the indicator.


@croucrou

croucrou
31 Aug 2016, 14:00

Thanks for responding. 

Inspired by first reply, to have only one position open at a time OnTick(), I now open position with:

var myPositions = Positions.FindAll("Label");

if (myPositions.Length == 0)  //to enter
return

if (myPositions.Length >= 1)  //to exit
return

I don't know, if this is the best solution, but it works!

I did not check the "count" method, but I guess it needs an additional "using" reference and seems to be too complicated, doesn't it.


@croucrou

croucrou
20 Aug 2016, 19:15 ( Updated at: 21 Dec 2023, 09:20 )

Okay, but can't you just do it like:


@croucrou

croucrou
19 Aug 2016, 16:48

Spotware?


@croucrou

croucrou
19 Aug 2016, 16:40

You mean indicator. Might be, if you really need it.


@croucrou

croucrou
14 Aug 2016, 14:05

I don't know, but isn't this related to the question I have asked here:

/forum/cbot-support/10059


@croucrou

croucrou
13 Aug 2016, 17:26

Yes, but the question is of a general nature. It is not dependent on a particular code.

How to use the OnTick() method and not to open unlimited number of positions at that tick.

This seems to be a common issue and could be platform regulated and not require coding, actually.


@croucrou

croucrou
13 Aug 2016, 01:01

Hello and thank you for responding.

The "open close" method wouldn't work, as the orders open in the same moment unforunately.

The second way is looking promissing. Possibly this has been the answer. I will be looking into it.

I also found this link referring to MetaTrader and have been hoping for a solution like this:

http://www.fxpro.co.uk/help-section/faq/fxpro-quant/why-does-my-expert-advisor-keep-opening-multiple-positions


@croucrou

croucrou
09 Aug 2016, 17:45

I.e. if the indicator had two lines, I would like only one to be displayed by default and the other would be optional.


@croucrou

croucrou
06 Aug 2016, 16:47

I am sorry, I was thinking about the output.

Would that be possible to set it to unchecked by default?


@croucrou

croucrou
06 Aug 2016, 15:24

There is no GetIndexByExactTime in the Guide. Why did you use it?

To access another timeframe of the same asset, GetIndexByTime is enough.

I believe GetIndexByExactTime becomes useful, when you refer to another symbol, which might have different time sessions.


@croucrou

croucrou
06 Aug 2016, 13:25

Your question has been about aggregating pips and not the position size, hasn't it?

If you asked about aggregated profit/loss, it's even easier to do.

Just in the 2. point, use Positon.NetProfit (or .GrossProfit) instead of the calculation.


@croucrou