Replies

PanagiotisCharalampous
25 Aug 2022, 09:03

Hi peshay,

Please have a look at the thread below. It might be helpful

https://ctrader.com/forum/ctrader-support/36294#post-9

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
25 Aug 2022, 08:59

Hi noob7,

Did you try checking executionEvent.Position.HasStopLoss and  executionEvent.Position.HasTakeProfit?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

PanagiotisCharalampous
25 Aug 2022, 08:51

Hi noolohp,

he results always show that Bars.Last(1).OpenTime is 1 bar ahead of Bars.OpenTime[i]

Correct. The proble here is that sometimes is > 1, therefore it points to an older date. There is clearly a logical error in your code. You need to debug it and understand what is wrong.

 Moreover, with regards to the mentioned code is there any possible alteration, in your opinion, to align the two value ?

No, because I have no idea what you are trying to do. I can only explain what you are doing which is probably not aligned with your intentions.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
25 Aug 2022, 08:41

Hi there,

You can check the sample cBots in cTrader. like the Sample cBot Reference SMA

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------

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 SamplecBotReferenceSMA : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("SMA Period", DefaultValue = 14)]
        public int SmaPeriod { get; set; }

        private SampleSMA sma;

        protected override void OnStart()
        {
            sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);
        }

        protected override void OnTick()
        {
            Print("{0}", sma.Result.LastValue);
        }
    }
}

and the Sample RSI cBot

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample RSI cBot" will create a buy order when the Relative Strength Index indicator crosses the  level 30, 
//    and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in 
//    the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level 
//    and sell orders are closed when RSI crosses the 30 level). 
//
//    The cBot can generate only one Buy or Sell order at any given time.
//
// -------------------------------------------------------------------------------------------------

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 SampleRSIcBot : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", Group = "RSI", DefaultValue = 14)]
        public int Periods { get; set; }

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        protected override void OnTick()
        {
            if (rsi.Result.LastValue < 30)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.LastValue > 70)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("SampleRSI", SymbolName, tradeType);
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);

            if (position == null)
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI");
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
24 Aug 2022, 11:14

Hi Stanley,

Please send us some troubleshooting information and paste the link to this discussion in the text box.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
24 Aug 2022, 10:24

Hi there,

Thanks, you don't need to reproduce the entire logic inside the cBot. You just need to reference the indicator and check the values.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
24 Aug 2022, 08:34

Hi noolohp,

as per my understanding Bars.OpenTime[] starts from [0] and surplus each time new bar is opened so with i++ the value of Bars.OpenTimes[i] should be the same as Bars.Last(1).OpenTime

But you run the loop from the beginning for each bar, therefore the condition (see below) that prints the curreBarOpenTime might become true before the last bar is reached.

    if (isCurrentBarRed && isPreviousBarRed && !isRedDriven)

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
24 Aug 2022, 08:29

Hi there,

It is not clear what are you trying to achieve here. What do you want the cBot to do? In general, Calculate is called on once for each bar for historical data and on each tick for the current bar.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
23 Aug 2022, 14:20

Hi noolohp,

I am not sure why you expect the two values to match. Here you always pring the last value

  Print("method " + Bars.Last(1).OpenTime);

and here you print a value based on the i counter

    Print(curreBarOpenTime);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
23 Aug 2022, 14:15

Hi nsvtrade,

You need to double click on the pop up window, not on the taskbar icon.

 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
23 Aug 2022, 08:03

Hi peshay,

What graphics card do you have?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 10:47

Hi peshay,

Thanks for reporting this problem. Can you record a video demonstrating this behavior?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 09:50

Hi Benjamin,

We are looking at this issue. In the meanwhile, you can add a reference to the project manually.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 09:49

Hi there,

There are no candles there. Ichimoku indicator always plots values in the future.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 09:15

Hi there,

Can you explain what do you mean? I don't see any obvious problem on the chart.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 08:48

Hi there,

No there is't. It's not possible to know the exact price for the stop loss unless the order is filled. Hence this behavior.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 08:44

Hi Giuseppe,

Thanks for posting in our forum but I really have a hard time understanding what are you writing about :)

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 08:41

Dear pedroesplago,

ExecuteOrder(InitialQuantity, GetRandomTradeType());

to

ExecuteOrder(InitialQuantity, TradeType.Buy);

 and

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialQuantity, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder(position.Quantity * 2, position.TradeType);
            }

to

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialQuantity, TradeType.Buy);
            }
            else
            {
                ExecuteOrder(position.Quantity * 2, TradeType.Buy);
            }

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

PanagiotisCharalampous
22 Aug 2022, 08:36

Hi Anthony,

Can you please try a clean installation and let me know if it resolves the problem?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

PanagiotisCharalampous
19 Aug 2022, 12:46

Hi hishalv,

You need to use the actual type

TextBlock _textBlock

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous