Replies

sarvann24
15 Nov 2023, 07:29 ( Updated at: 15 Nov 2023, 07:30 )

RE: reply

PanagiotisCharalampous said: 

Hi there,

Here is an example how to calculate the moving average for the high prices

        var ma = Indicators.MovingAverage(Bars.HighPrices, 14, MovingAverageType.Exponential);

Best regards,

Panagiotis

Thanks :)


@sarvann24

sarvann24
10 Nov 2023, 09:55

RE: RE: RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisCharalampous said: 

sarvann24 said: 

PanagiotisCharalampous said: 

Here is an example

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawText("Diff", DIFF.ToString(),  Bars.OpenTimes.Last(0), Symbol.Bid, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

HI, Can we set rules to make only one trade per bar ONTICK( ),

Only reversing the old postion .

Hi there,

Yes, use a flag after you place a trade and reset it on each bar.

I am a learner, dont know how to do it,

 much appreciated if you provide me the code for this RSI example


@sarvann24

sarvann24
10 Nov 2023, 06:14

RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisCharalampous said: 

Here is an example

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawText("Diff", DIFF.ToString(),  Bars.OpenTimes.Last(0), Symbol.Bid, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

HI, Can we set rules to make only one trade per bar ONTICK( ),

Only reversing the old postion .


@sarvann24

sarvann24
02 Nov 2023, 07:09

RE: RE: RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisCharalampous said: 

sarvann24 said: 

PanagiotisCharalampous said: 

Here is an example

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawText("Diff", DIFF.ToString(),  Bars.OpenTimes.Last(0), Symbol.Bid, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

HI Panagiotis,

can the displayed text  be moved to top left?

Here you go

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawStaticText("Diff", DIFF.ToString(),  VerticalAlignment.Top, HorizontalAlignment.Left, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

Thanks


@sarvann24

sarvann24
01 Nov 2023, 11:20

RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisCharalampous said: 

Here is an example

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawText("Diff", DIFF.ToString(),  Bars.OpenTimes.Last(0), Symbol.Bid, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

HI Panagiotis,

can the displayed text  be moved to top left?


@sarvann24

sarvann24
01 Nov 2023, 10:56

RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisCharalampous said: 

Here is an example

        protected override void OnTick()        {            var DIFF = Bars.HighPrices.Last(6)-Bars.LowPrices.Last(6);                        Chart.DrawText("Diff", DIFF.ToString(),  Bars.OpenTimes.Last(0), Symbol.Bid, Color.Red);                               if (rsi.Result.LastValue < 30)                {                    Close(TradeType.Sell);                    Open(TradeType.Buy);                }                else if (rsi.Result.LastValue > 70)                {                    Close(TradeType.Buy);                    Open(TradeType.Sell);                }            }

Many thanks :)


@sarvann24

sarvann24
01 Nov 2023, 07:24 ( Updated at: 01 Nov 2023, 10:30 )

RE: HOW TO DISPLAY A VALUE ON CHART

PanagiotisChar said: 

Hi there,

You can try using the DrawText method

I don't know even basic of this coding,i am copying here and there and trying to build a cbot,

 I tried different ways with DrawText but getting error.

 So could be please tell me where exactly and what exact code has to be inserted in the above example cbot


@sarvann24

sarvann24
30 Oct 2023, 06:45

RE: Findiing Maximum and Minimum for previuos set of bars

ialhamdazeez said: 

Bars is an array beginning from the oldest price to current price. So you should first reverse it to begin from the current price, then skip the current price using skip function, then take the bars that you want to check for highest price using take function. Use the following code:

var bars = Bars.Reverse().Skip(1).Take(5).Where(b => b.High == Bars.Reverse().Skip(1).Take(5).Max(a => a.High));// print the result foreach (var b in bars)            {                Print("time: " + b.OpenTime.ToString() + ", price: " + b.Close.ToString());            }

Thanks :)


@sarvann24

sarvann24
30 Oct 2023, 06:45

RE: Findiing Maximum and Minimum for previuos set of bars

PanagiotisChar said: 

Hi there, 

You can try something like this

Bars.HighPrices.Take(Bars.HighPrices.Count-2).Skip(Bars.HighPrices.Count-5).Max()

Thanks :)


@sarvann24

sarvann24
30 Oct 2023, 03:07

RE: Findiing Maximum and Minimum for previuos set of bars

r.stipriaan said: 

Hi Sarvann,

You can make a array of the last bars and use the .min() and .max() function.

Or draw lines whenever a high is higher or low when lower.

 

 

 

 

Hi Stipriaan,

Thanks , but I don't know coding, how to create an array

 


@sarvann24

sarvann24
28 Oct 2023, 06:26 ( Updated at: 29 Oct 2023, 06:15 )

RE: RE: RE: RE: Only trade within certain hours

sarvann24 said: 

PanagiotisChar said: 

sarvann24 said: 

PanagiotisCharalampous said: 

Hi Liquidity,

Here you go

// -------------------------------------------------------------------------------------------------////    This code is a cAlgo API sample.////    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.////    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("Source")]        public DataSeries Source { get; set; }        [Parameter("Periods", DefaultValue = 14)]        public int Periods { get; set; }        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]        public double Quantity { get; set; }        [Parameter("From", DefaultValue = 7)]        public int From { get; set; }        [Parameter("To", DefaultValue = 10)]        public int To { get; set; }        private RelativeStrengthIndex rsi;        protected override void OnStart()        {            rsi = Indicators.RelativeStrengthIndex(Source, Periods);        }        protected override void OnTick()        {            if (Server.Time.Hour >= From && Server.Time.Hour < To)            {                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", Symbol, tradeType))                ClosePosition(position);        }        private void Open(TradeType tradeType)        {            var position = Positions.Find("SampleRSI", Symbol, tradeType);            var volumeInUnits = Symbol.QuantityToVolume(Quantity);            if (position == null)                ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI");        }    }}

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi, can anybody help me how to close all the open position after “ X ” hour

 

Hi there,

You can write something like this

            if(Server.Time.TimeOfDay > TimeSpan.ParseExact("21:00", "hh\\:mm", null))
            {
                foreach (var position in Positions)
                {
                    position.Close();
                }
            }

Thanks :)

HI, i am new to this ctrader and i don't know how to write the codes, so could you help me to find the highest high of last set of bars and not including the current bar, the code below includes current bar i believe. i want to check whether the current bar close price has crossed previous maximum for set of bars or minimum for set of bars 

      Bars.ClosePrices.Last(1) >   Bars.HighPrices.Maximum(3) 
      Bars.ClosePrices.Last(1) <   Bars.LowPrices.Minimum(3) 

 


@sarvann24

sarvann24
25 Oct 2023, 06:48 ( Updated at: 25 Oct 2023, 10:53 )

RE: RE: RE: Only trade within certain hours

PanagiotisChar said: 

sarvann24 said: 

PanagiotisCharalampous said: 

Hi Liquidity,

Here you go

// -------------------------------------------------------------------------------------------------////    This code is a cAlgo API sample.////    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.////    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("Source")]        public DataSeries Source { get; set; }        [Parameter("Periods", DefaultValue = 14)]        public int Periods { get; set; }        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]        public double Quantity { get; set; }        [Parameter("From", DefaultValue = 7)]        public int From { get; set; }        [Parameter("To", DefaultValue = 10)]        public int To { get; set; }        private RelativeStrengthIndex rsi;        protected override void OnStart()        {            rsi = Indicators.RelativeStrengthIndex(Source, Periods);        }        protected override void OnTick()        {            if (Server.Time.Hour >= From && Server.Time.Hour < To)            {                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", Symbol, tradeType))                ClosePosition(position);        }        private void Open(TradeType tradeType)        {            var position = Positions.Find("SampleRSI", Symbol, tradeType);            var volumeInUnits = Symbol.QuantityToVolume(Quantity);            if (position == null)                ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI");        }    }}

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi, can anybody help me how to close all the open position after “ X ” hour

 

Hi there,

You can write something like this

            if(Server.Time.TimeOfDay > TimeSpan.ParseExact("21:00", "hh\\:mm", null))
            {
                foreach (var position in Positions)
                {
                    position.Close();
                }
            }

Thanks :)


@sarvann24

sarvann24
25 Oct 2023, 02:44 ( Updated at: 25 Oct 2023, 05:49 )

RE: Only trade within certain hours

PanagiotisCharalampous said: 

Hi Liquidity,

Here you go

// -------------------------------------------------------------------------------------------------////    This code is a cAlgo API sample.////    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.////    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("Source")]        public DataSeries Source { get; set; }        [Parameter("Periods", DefaultValue = 14)]        public int Periods { get; set; }        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]        public double Quantity { get; set; }        [Parameter("From", DefaultValue = 7)]        public int From { get; set; }        [Parameter("To", DefaultValue = 10)]        public int To { get; set; }        private RelativeStrengthIndex rsi;        protected override void OnStart()        {            rsi = Indicators.RelativeStrengthIndex(Source, Periods);        }        protected override void OnTick()        {            if (Server.Time.Hour >= From && Server.Time.Hour < To)            {                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", Symbol, tradeType))                ClosePosition(position);        }        private void Open(TradeType tradeType)        {            var position = Positions.Find("SampleRSI", Symbol, tradeType);            var volumeInUnits = Symbol.QuantityToVolume(Quantity);            if (position == null)                ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "SampleRSI");        }    }}

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi, can anybody help me how to close all the open position after “ X ” hour

 


@sarvann24