Replies

mindfulness
27 Dec 2022, 13:42

RE:

Ok, understand. I was not aware of it, that it doesn‘t make sense and I thought I was asking the right way. Sorry for the misunderstanding.

What I want to have is the following. I want to look if the  Kyushu formula in the script is true in different timeframes to get a entry decision.

For example: It has to be true in daily or H4 AND in H1 or M30.

Thats why I tried to place the variable behind the timeframe variable to combine them. Maybe without any sense as you said. Didn‘t found any example to place a formula like this in timeframes. Only already existing indicators, which can be referenced like this. Like Ichimoku for example.

thanks for any help so far.

Alex


PanagiotisChar said:

What I mean is that the code does not make sense and the error message is clear regarding what the problem is. The property does not exist. So my guess was that the code was copied from somewhere and its out of context. 

Instead of asking us to fix a non sensical code which we don't understand what is supposed to do, maybe it's better to tell us what are you trying to achieve and ask for a small example.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@mindfulness

mindfulness
23 Dec 2022, 14:21

RE:

No, i haven´t copied them from somewhere. I only try to undersdtand how to do it. I am no a programmer, so i need to look to a similiar solution to get things working. That´s why i asked here. The error message didn´t point me to my error or things i have to change. And yes i try to learn by coping frames and testing them in my scripts. Isn´t this the way lot´s of people around here started?
I tried to get the data from the timeframe and combine them with the code of kyushu ashi. Sorry, if this is not that clear to me.

PanagiotisChar said:

Hi Alex,

I think the messages in the log are more than clear. I am not sure what you are trying to do with the code or what you think its doing. But lines of code like this make no sense

            var kyushu_d_bullish = kyushu_d.kyushu_bullish;
            var kyushu_h4_bullish = kyushu_h4.kyushu_bullish;
            var kyushu_h1_bullish = kyushu_h1.kyushu_bullish;
            var kyushu_m30_bullish = kyushu_m30.kyushu_bullish;

Did you copy this from somewhere?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@mindfulness

mindfulness
23 Dec 2022, 12:04 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Hi,

sure here is the code i am using:

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.EEuropeStandardTime, AccessRights = AccessRights.None)]
    public class ClickAlgoSchoolSMA : Robot
    {
        #region User defined parameters


        [Parameter("Instance Name", DefaultValue = "001")]
        public string InstanceName { get; set; }

                [Parameter("Calculate OnBar", DefaultValue = true)]
        public bool CalculateOnBar { get; set; }

        #endregion

        #region Indicator declarations

        //private StochasticOscillator _stochastic;
        private ExponentialMovingAverage _ema9 { get; set; }
        private ExponentialMovingAverage _ema26 { get; set; }
        private ExponentialMovingAverage _ema51 { get; set; }

        private BollingerBands _bollingerBands;

        private IchimokuKinkoHyo _ichimokuKinkoHyo;

        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 20)]
        public int Period { get; set; }
        
        [Parameter("Stop Loss", DefaultValue = 35)]
        public double StopLoss { get; set; }

        [Parameter("Risk %", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double RiskPerTrade { get; set; }
        #endregion

        #region cTrader events


        protected override void OnStart()
        {
                }

        [Obsolete()]
        protected override void OnBar()
        {
            if (!CalculateOnBar)
            {
                return;
            }

            ManagePositions();
        }


        protected override void OnStop()
        {
            // unused
        }

        #endregion

        #region Position management

        [Obsolete()]
        private void ManagePositions()
        {

            #region Daten f�r timeframes
            
            var kyushu_d = MarketData.GetBars(TimeFrame.Daily);
            var kyushu_h4 = MarketData.GetBars(TimeFrame.Hour4);
            var kyushu_h1 = MarketData.GetBars(TimeFrame.Hour);
            var kyushu_m30 = MarketData.GetBars(TimeFrame.Minute30);
            var kyushu_m15 = MarketData.GetBars(TimeFrame.Minute15);
            var kyushu_m5 = MarketData.GetBars(TimeFrame.Minute5);
            #endregion

            
             #region Variablen Kyushu Ashi
            var kyushu_bullish = Bars.OpenPrices.Last(8) < Bars.ClosePrices.LastValue;
            var kyushu_d_bullish = kyushu_d.kyushu_bullish;
            var kyushu_h4_bullish = kyushu_h4.kyushu_bullish;
            var kyushu_h1_bullish = kyushu_h1.kyushu_bullish;
            var kyushu_m30_bullish = kyushu_m30.kyushu_bullish;
            
            var kyushu_bearish = Bars.OpenPrices.Last(8) > Bars.ClosePrices.LastValue;
            var kyushu_d_bearish = kyushu_d.kyushu_bearish;
            var kyushu_h4_bearish = kyushu_h4.kyushu_bearish;
            var kyushu_h1_bearish = kyushu_h1.kyushu_bearish;
            var kyushu_m30_bearish = kyushu_m30.kyushu_bearish;
            
            #endregion

                    

            #region Trading
                #region Entry
                
                var higher_trend = (kyushu_d_bullish || kyushu_d_bearish) || (kyushu_h4_bullish || kyushu_h4_bearish);
                var lower_trend = (kyushu_h1_bullish || kyushu_h1_bearish) || (kyushu_m30_bullish || kyushu_m30_bearish);
                
                var confirmation_bullish = (kyushu_d_bullish || kyushu_h4_bullish) && (kyushu_h1_bullish || kyushu_m30_bullish) && kyushu_bullish;
                var confirmation_bearish = (kyushu_d_bearish || kyushu_h4_bearish) && (kyushu_h1_bearish || kyushu_m30_bearish) && kyushu_bearish;
                
                
                #endregion
                
                #region exit
                var before_BE = LastResult.Position.Pips < 30;
                var after_BE = LastResult.Position.Pips > 30;
                
                var exit_bullish_before_BE = (kyushu_bearish || !higher_trend) && before_BE;
                var exit_bearish_before_BE = (kyushu_bullish || !lower_trend) && before_BE;
                
                var exit_bullish_after_BE = !higher_trend  && after_BE;
                var exit_bearish_after_BE = !lower_trend  && after_BE;
                
                var exit_bullish = exit_bullish_before_BE || exit_bullish_after_BE;
                var exit_bearish = exit_bearish_before_BE || exit_bearish_after_BE;
                
                #endregion

                #region Tradingzeiten
                var tradingStarts = TimeSpan.ParseExact("07:00", "hh\\:mm", null);
                var tradingStops = TimeSpan.ParseExact("17:00", "hh\\:mm", null);
                #endregion

                #region Orderaufgabe
                if (Server.Time.TimeOfDay >= tradingStarts && Server.Time.TimeOfDay < tradingStops)
                {
                    if (confirmation_bullish)
                    {
                        if (!IsPositionOpenByType(TradeType.Buy))
                        {
                            OpenPosition(TradeType.Buy);
                        }
                    }

                    if (exit_bullish)
                    {
                        ClosePosition(TradeType.Buy);
                    }

                    if (confirmation_bearish)
                    {
                        if (!IsPositionOpenByType(TradeType.Sell))
                        {
                            OpenPosition(TradeType.Sell);
                        }
                    }

                    if (exit_bearish)
                    {
                        ClosePosition(TradeType.Sell);
                    }
                }
                
        }



        [Obsolete()]
            private void OpenPosition(TradeType type)
            {


            ExecuteMarketOrder(type, this.Symbol, GetVolume(StopLoss), InstanceName, StopLoss, null);
        }


            private void ClosePosition(TradeType type)
            {
                var p = Positions.Find(InstanceName, this.Symbol, type);

                if (p != null)
                {
                    ClosePosition(p);
                }
            }

            protected override void OnTick()
            {
              //  foreach (var position in Positions.FindAll(InstanceName, Symbol))
              //  {
              //      if (position.StopLoss != position.EntryPrice)
              //      {
              //          if (position.Pips >= Trigger)
              //          {
              //              ModifyPosition(position, position.EntryPrice, position.TakeProfit);
              //          }
              //      }
              //  }
            }
        #endregion


        #region Position Information

        
        [Obsolete()]
            private bool IsPositionOpenByType(TradeType type)
            {
                var p = Positions.FindAll(InstanceName, Symbol, type);

                if (p.Count() >= 1)
                {
                    return true;
                }

                return false;
            }


        private double GetVolume(double? stopLossPips = null)
        {
            double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;

            // Change this to Account.Balance if you want to
            double baseNumber = Account.Equity;

            double sizeInLots = Math.Round((baseNumber * RiskPerTrade / 100) / (stopLossPips.Value * costPerPip), 2);

            var result = Symbol.QuantityToVolumeInUnits(sizeInLots);

            if (result > Symbol.VolumeInUnitsMax)
            {
                result = Symbol.VolumeInUnitsMax;
            }
            else if (result < Symbol.VolumeInUnitsMin)
            {
                result = Symbol.VolumeInUnitsMin;
            }
            else if (result % Symbol.VolumeInUnitsStep != 0)
            {
                result = result - (result % Symbol.VolumeInUnitsStep);
            }

            return result;
        }
        #endregion

        #endregion


    }
}

#endregion

 

And this are the error messages:

Hope this helps.

 

PanagiotisChar said:

Hi Alex,

Please share the complete code and explain what do you think is wrong.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@mindfulness

mindfulness
27 Oct 2022, 13:38

RE:

PanagiotisChar said:

Hi Alex,

If you mean a parameter, then use the DefaultValue

        [Parameter("TimeFrame", DefaultValue = "Minute")]
        public TimeFrame TimeFrame { get; set; }

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

Thanks, but that´s maybe not the one. I mean when i add pait to the bot, it has per default H1 as a timeframe. I want to have M5 as default. Is this possible?


@mindfulness

mindfulness
27 Oct 2022, 09:58

RE:

PanagiotisChar said:

Hi Alex,

It's not possible to change a chart's timeframe from a cBot.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Hmm, maybe i have make it not clear. I don´t want to change the chart timeframe. Only the timeframe the bot is using for the complete code when running.


@mindfulness

mindfulness
27 Oct 2022, 09:56

RE:

PanagiotisChar said:

Hi Alex,

Shouldn't you address this question to the developer?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Oh, sure ... sorry wrong forum for it here.


@mindfulness

mindfulness
30 Sep 2022, 09:57 ( Updated at: 21 Dec 2023, 09:22 )

RE:

mindfulness said:

Hello,

i am using a bot with a fixed SL, which opens two positions at a time. There is not trailing, move to BE, no partial profit,  etc. Please have a look at this trades. Can you tell me why this happens?

Both positions have been opened at the same time as expected. Only the second trade runs nearly three days more then the first one. Both have the same SL when opened at the same time

One additional information ... i have just seen, that this behaviour is perhaps always on different pairs. But only on the last trade. The earlier trades differ only by 5 Minutes.

 


@mindfulness

mindfulness
30 Sep 2022, 09:10

RE:

PanagiotisCharalampous said:

Hi mindfulness,

That's expected because TradingView does not really backtest. It just post processes information by connectiing dots on prepopulated charts. So many times the results are way off.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Pana,

 

thanks for the info

 

br

 

Alex


@mindfulness

mindfulness
29 Sep 2022, 12:00

RE: RE: RE:

mindfulness said:

Sendgate said:

mindfulness said:

Sendgate said:

Quick glanced... Change & to &&?
& is a bitwise operand, && is a logical operand

Just give it a try, but makes no difference. Not sure, but i think it´s a mistake regarding converting the "len" from the former script to C# Calgo.

Well it really should make a difference in the logical query.
I suggest you try to use the debugger to se your code working. You can download a free, community edition, of Visual Studio and get going :)

Cheers

This is the correct syntax:
 

var kyushu_bullish = ((kyushu_d_bullish || kyushu_h4_bullish) && (kyushu_h1_bullish && kyushu_m30_bullish && kyushu_m15_bullish && kyushu_m5_bullish));

var kyushu_bearish = ((kyushu_d_bearish || kyushu_h4_bearish) && (kyushu_h1_bearish && kyushu_m30_bearish && kyushu_m15_bearish && kyushu_m5_bearish));

 

Thanks for the answer. I have already made the above mentioned changes amde. still no difference. And i am already working with Visual Studio. VA has not thrown an error when using only one "&". Using version 2019, maybe this is in 2022 different.

This one can be closed. Very poor failure on my side. The ">" and "<" were wrong sided. ;)


@mindfulness

mindfulness
27 Sep 2022, 14:34

RE: RE:

Sendgate said:

mindfulness said:

Sendgate said:

Quick glanced... Change & to &&?
& is a bitwise operand, && is a logical operand

Just give it a try, but makes no difference. Not sure, but i think it´s a mistake regarding converting the "len" from the former script to C# Calgo.

Well it really should make a difference in the logical query.
I suggest you try to use the debugger to se your code working. You can download a free, community edition, of Visual Studio and get going :)

Cheers

This is the correct syntax:
 

var kyushu_bullish = ((kyushu_d_bullish || kyushu_h4_bullish) && (kyushu_h1_bullish && kyushu_m30_bullish && kyushu_m15_bullish && kyushu_m5_bullish));

var kyushu_bearish = ((kyushu_d_bearish || kyushu_h4_bearish) && (kyushu_h1_bearish && kyushu_m30_bearish && kyushu_m15_bearish && kyushu_m5_bearish));

 

Thanks for the answer. I have already made the above mentioned changes amde. still no difference. And i am already working with Visual Studio. VA has not thrown an error when using only one "&". Using version 2019, maybe this is in 2022 different.


@mindfulness

mindfulness
26 Sep 2022, 08:26

RE:

Sendgate said:

Quick glanced... Change & to &&?
& is a bitwise operand, && is a logical operand

Just give it a try, but makes no difference. Not sure, but i think it´s a mistake regarding converting the "len" from the former script to C# Calgo.


@mindfulness

mindfulness
25 Sep 2022, 17:48 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

mindfulness said:

mindfulness said:

mindfulness said:

Hello,

 

maybe ask multiple times, but i can´t find it. How can i restrict the execution time of orders to for example 7am till 5pm on weekdays?

 

thanks in advanced

 

Alex

I have tried it now with this, but was not succesfull. The error messages: (sorry in german)

       if (Server.Time.TimeOfDay > TimeSpan.ParseExact("07:00")) & (Server.Time.TimeOfDay < TimeSpan.ParseExact("17:00"));
        {
                if (bullish)
                {
                    if (!IsPositionOpenByType(TradeType.Buy))
                    {
                        OpenPosition(TradeType.Buy);
                    }
                }

                if (exit_bullish)
                {
                    ClosePosition(TradeType.Buy);
                }

                if (bearish)
                {
                    if (!IsPositionOpenByType(TradeType.Sell))
                    {
                        OpenPosition(TradeType.Sell);
                    }
                }

                if (exit_bearish)
                {
                    ClosePosition(TradeType.Sell);
                }
            }
        }

 

Also tried this one. Now without error messages, but just ignored when executing.

if ((DateTime.Now.Hour >= 07) & (DateTime.Now.Hour <= 17));

 

Can be closed, got it working:
 


var tradingStarts = TimeSpan.ParseExact("08:00", "hh\\:mm", null);
var tradingStops = TimeSpan.ParseExact("18:00", "hh\\:mm", null);

if (Server.Time.TimeOfDay >= tradingStarts && Server.Time.TimeOfDay < tradingStops)

 


@mindfulness

mindfulness
25 Sep 2022, 15:11 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

mindfulness said:

mindfulness said:

Hello,

 

maybe ask multiple times, but i can´t find it. How can i restrict the execution time of orders to for example 7am till 5pm on weekdays?

 

thanks in advanced

 

Alex

I have tried it now with this, but was not succesfull. The error messages: (sorry in german)

       if (Server.Time.TimeOfDay > TimeSpan.ParseExact("07:00")) & (Server.Time.TimeOfDay < TimeSpan.ParseExact("17:00"));
        {
                if (bullish)
                {
                    if (!IsPositionOpenByType(TradeType.Buy))
                    {
                        OpenPosition(TradeType.Buy);
                    }
                }

                if (exit_bullish)
                {
                    ClosePosition(TradeType.Buy);
                }

                if (bearish)
                {
                    if (!IsPositionOpenByType(TradeType.Sell))
                    {
                        OpenPosition(TradeType.Sell);
                    }
                }

                if (exit_bearish)
                {
                    ClosePosition(TradeType.Sell);
                }
            }
        }

 

Also tried this one. Now without error messages, but just ignored when executing.

if ((DateTime.Now.Hour >= 07) & (DateTime.Now.Hour <= 17));

 


@mindfulness

mindfulness
25 Sep 2022, 14:29

RE:

mindfulness said:

Hello,

 

maybe ask multiple times, but i can´t find it. How can i restrict the execution time of orders to for example 7am till 5pm on weekdays?

 

thanks in advanced

 

Alex

I have tried it now with this, but was not succesfull. The error messages: (sorry in german)

       if (Server.Time.TimeOfDay > TimeSpan.ParseExact("07:00")) & (Server.Time.TimeOfDay < TimeSpan.ParseExact("17:00"));
        {
                if (bullish)
                {
                    if (!IsPositionOpenByType(TradeType.Buy))
                    {
                        OpenPosition(TradeType.Buy);
                    }
                }

                if (exit_bullish)
                {
                    ClosePosition(TradeType.Buy);
                }

                if (bearish)
                {
                    if (!IsPositionOpenByType(TradeType.Sell))
                    {
                        OpenPosition(TradeType.Sell);
                    }
                }

                if (exit_bearish)
                {
                    ClosePosition(TradeType.Sell);
                }
            }
        }

 


@mindfulness

mindfulness
03 Aug 2022, 12:50

RE:

PanagiotisCharalampous said:

How about this?

            var ichimoku = Indicators.IchimokuKinkoHyo(9,26,52);
            var b =  ichimoku.SenkouSpanA.Last(0) > ichimoku.SenkouSpanB.Last(0);
            var ichimokuDaily = Indicators.IchimokuKinkoHyo(MarketData.GetBars(TimeFrame.Daily),9,26,52);
            var c = ichimokuDaily.SenkouSpanA.Last(0) > ichimokuDaily.SenkouSpanB.Last(0);
            var a = c && b;

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

That easy? Was all the time thinking, that i have to join it together like in JSON. ;)

Wow ... you made my day. :) Thank you very much

Alex


@mindfulness

mindfulness
03 Aug 2022, 12:32

RE:

PanagiotisCharalampous said:

Hi mindfullness,

Here you go

 var B = ichimoku.SenkouSpanA.Last(0) > ichimoku.SenkouSpanB.Last(0);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Maybe not easy to explain. I will try it again:

1. This bot will run in M5 timeframe
2. I have to check within the bot, if var A is true in timeframe daily. So maybe a combination of your explaination regarding using Ichimoku and timeframe and using in M5 is needed. ?
3. I need to check two conditions in the bot:
    a) is var A true in daily timeframe

     b) is var B true in M5 timeframe
4. If both true , then execute the trade.

Sorry for the missunderstandings.


@mindfulness

mindfulness
03 Aug 2022, 12:13

RE:

PanagiotisCharalampous said:

Hi Alex,

I am not sure what are you trying to do. Do you want to compare two ichimoku indicators from two different timeframes?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Panagiotis,

 

I want to use the bot in the M5. Now i need to check the higher and middle TF if there is a condition true. So for example:

The value of var A is true, when:

1. var B in daily is true (var B = senkouSpanA.Last(0) > senkouSpanB.Last(0)

In JSON fiormat like mentioned above it looks like this:
ichi_d_bullish = request.security(syminfo.tickerid, 'D', ichi_bullish, lookahead=barmerge.lookahead_on)

ichi_d_bullish would var A and ichi_bullish var B in the example

Hope that makes it more clear and understandable.

Thanks 

Alex

 

 


@mindfulness

mindfulness
03 Aug 2022, 11:27

RE:

PanagiotisCharalampous said:

Hi Alex,

Here is how you can initialize an Ichimoku indicator using a different timeframe

 var ichimoku = Indicators.IchimokuKinkoHyo(MarketData.GetBars(TimeFrame.Minute2),9,26,52);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Panagiotis,

 

thanks for the fast reply. Sorry if i have to ask another question. ;)

How can i combine a condition together with the timeframe variable above, like:

var A = B & C

where C is the var Ichimoku you mentioned.and is only checked in that timeframe.

 

thanks Alex


@mindfulness

mindfulness
03 Aug 2022, 06:46

RE:

mindfulness said:

Hello,

i am new to calgo cbot writing. Made my first bot almost complete, but stuck on the multitimeframe support.

In Tradingview JSON i am using the following:

ichi_m30_bullish = request.security(syminfo.tickerid, '30', ichi_bullish, lookahead=barmerge.lookahead_on)
ichi_m30_bearish = request.security(syminfo.tickerid, '30', ichi_bearish, lookahead=barmerge.lookahead_on)

ichi_h1_bullish = request.security(syminfo.tickerid, '60', ichi_bullish, lookahead=barmerge.lookahead_on)
ichi_h1_bearish = request.security(syminfo.tickerid, '60', ichi_bearish, lookahead=barmerge.lookahead_on)

ichi_h4_bullish = request.security(syminfo.tickerid, '240', ichi_bullish, lookahead=barmerge.lookahead_on)
ichi_h4_bearish = request.security(syminfo.tickerid, '240', ichi_bearish, lookahead=barmerge.lookahead_on)

ichi_d_bullish = request.security(syminfo.tickerid, 'D', ichi_bullish, lookahead=barmerge.lookahead_on)
ichi_d_bearish = request.security(syminfo.tickerid, 'D', ichi_bearish, lookahead=barmerge.lookahead_on)
 

That´s all needed to use the variable to request the timeframe.I have already looked in the new annoncement thread regarding multitimeframe, but don´t understand it completely how to use it for Ichimoku in the definitions and declarations. The definitions for Ichimoku are already made and working. Now i need only the request for example if this "var ssa_bullish = (ssa.LastValue > ssa.LastValue);" is true in a different timeframe, when executing on M5.

Thanks in advanced

Alex


I have just found this on cTDN Forum - Multi time frame Ichimoku indicator (ctrader.com), but because it is 9 years old, there are some outdated things in it. Would be good if can get help on it.

thanks

Alex


@mindfulness

mindfulness
01 Aug 2022, 14:52

RE:

PanagiotisCharalampous said:

Hi Alex,

You can try creating a new account without any history for your strategy.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Panagiotis,

 

very interesting, now it is the correct view. Don´t know what happened.

Thanks!

Alex


@mindfulness