Replies

ac15x
24 Jul 2020, 15:20 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi ac15x,

Read here how to reference custom indicators.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi made sure to do this but cannot seem to make it work 

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var indicator = Indicators.HighestHigh_LowestLow();
        }
    }

    [Indicator("Highest High Lowest Low Bands", IsOverlay = true, AccessRights = AccessRights.None)]
    public class HighestHigh_LowestLow : Indicator
    {

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsHigh { get; set; }

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsLow { get; set; }

        [Output("Top", LineColor  = "Red")]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", LineColor = "Blue")]
        public IndicatorDataSeries Bottom { get; set; }

        private HighestHigh_LowestLow _hl;
        protected override void Initialize()
        {
            _hl = Indicators.GetIndicator(PeriodsHigh, PeriodsLow, Top, Bottom);
        }

        public override void Calculate(int index)
        {
            Top[index] = Bars.HighPrices.Maximum(PeriodsHigh);
            Bottom[index] = Bars.HighPrices.Minimum(PeriodsLow);
        }
    }


}

 


@ac15x

ac15x
23 Jul 2020, 16:49

RE:

PanagiotisCharalampous said:

Hi ac15x,

You can use GetBars() to get data from other timeframes and use them as sources for your indicators.

Best Regards,

Panagiotis 

Join us on Telegram

 

thankyou


@ac15x

ac15x
22 Jul 2020, 16:52

RE:

PanagiotisCharalampous said:

Hi ac15x,

You can use the Cancel() method to cancel a pending order.

Best Regards,

Panagiotis 

Join us on Telegram

 

Do I have to watch the ontick event when order is pending to do this? is that the best way of doing it?


@ac15x

ac15x
22 Jul 2020, 16:47

RE:

PanagiotisCharalampous said:

Hi ac15x,

This is not the complete cBot code since I cannot just paste it and build it. Did you try to print the values? What SL and TP is set when the order is placed? Can you post an example?

Best Regards,

Panagiotis 

Join us on Telegram

Thanks I fixed it, the formula for stop loss is incorrect. I fixed this with this formula.

var stoploss = Math.Abs((entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3))) / Symbol.PipSize);

 

One last question with PlaceStopLimitOrder., if stop loss get hits first before entry, what is the best way to cancel the order?

 

Thanks,

 


@ac15x

ac15x
22 Jul 2020, 16:12 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi ac15x,

Can you provide the complete cBot code and an example of the issue? You need to explain what you expect the cBot to do and what does it do instead.

Best Regards,

Panagiotis 

Join us on Telegram

Thats the entire code basically im just coding automated entry 3 pips above the last bar high and stop loss 3 pips below the last bar low. Take profit is equal the number pips between entry and stop loss.

 

I think the error is calculating the number of pips between entry and stop loss.

var entry = Bars.HighPrices.Last(1) + (Symbol.PipSize * 3);
var stoploss = Math.Abs(entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3)) / Symbol.PipSize);
var takeProfit = stoploss;

 


@ac15x

ac15x
22 Jul 2020, 15:56

RE:

PanagiotisCharalampous said:

Hi ac15x,

You can use PlaceStopLimitOrder.

Best Regards,

Panagiotis 

Join us on Telegram

 

Thanks, that worked well. Still one issue remains seems like my pips calculation is wrong since it is not exiting position even after TP or SL reached.

 

   protected override void OnBar()
        {
            if (LastResult== null ||( LastResult.PendingOrder == null && LastResult.Position == null))
            {
                    SetEntry(trend);
            }
        }

        private void SetEntry(Trend trend)
        {
            if (trend == Trend.Uptrend)
            {
                var entry = Bars.HighPrices.Last(1) + (Symbol.PipSize * 3);
                var stoploss = Math.Abs(entry - (Bars.LowPrices.Last(1) - (Symbol.PipSize * 3)) / Symbol.PipSize);
                var takeProfit = stoploss;

                var result = PlaceStopLimitOrder(TradeType.Buy, SymbolName, 10000, entry, 5, InstanceName, stoploss, takeProfit);
            }
        
        }

 


@ac15x