Replies

ctid5083541
03 Dec 2023, 21:02

RE: How to Add "From" and "to" Dates

firemyst said: 

You can try doing:

 

//Pseudo code//Get the start index you want to search fromint startIndex = Bars.OpenTimes.GetIndexByTime( <enter your start date/time value here> );//get the end index corresponding to the ending date/time you wantint endIndex = Bars.OpenTimes.GetIndexByTime( <enter your end date/time value here> );//Now go through every barfor (int x=startIndex; x <= endIndex; x++){  // put your logic here that you want to do}

What is the date/time value? :

int endIndex = Bars.OpenTimes.GetIndexByTime( “01/01/2023” );

I have tried with and without quotes. I even tried the code below, but I still have the problem of assigning values to MyStartDate and MyEndDate. I keep getting an error no matter what I try. I suppose it is a case of understanding the syntax, although I have read about it. Most examples are for times not dates.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class MyDates : Indicator
    {
        
        private readonly DateTime MyStartDate;
        private readonly DateTime MyEndDate;
        
        protected override void Initialize()
        {
            

            //Get the start index you want to search from
            int startIndex = Bars.OpenTimes.GetIndexByTime(MyStartDate);
            
            //get the end index corresponding to the ending date/time you want
            int endIndex = Bars.OpenTimes.GetIndexByTime(MyEndDate);
            
            //Now go through every bar
            for (int x=startIndex; x <= endIndex; x++)
            {
              // put your logic here that you want to do
            }
                    }
            
                    public override void Calculate(int index)
                    {
                        
                    }
    }
}

 

 


@ctid5083541

ctid5083541
17 Apr 2023, 15:56

RE: RE:

No I don't have Visual Studio but thanks for your reply.

 

firemyst said:

You don't have to. It can be simplified doesn't mean it has to be simplified.

If you simplify it, the syntax may not be compatible with .net framework 4.x.

If you are using Visual Studio, just hover the issue in the actual code and then in the pop up window select "show potential fixes".

 


@ctid5083541

ctid5083541
06 Apr 2023, 15:03

RE:

Thanks for your input firemyst. I'm only interested in bars, ticks and renko are unlikely to be necessary. I only want to know if the moving average has been tested or a false breakout has recently occurred.

Kind regards.

 

firemyst said:

Are you wanting to check for each "tick", or only the previous bar?

It sounds like you're wanting to check each tick, but am not 100% sure.

If you want to check the previous bar when a new bar is formed, if you are on Renko charts it'll be a bit more complex than any of the other kinds of charts since cTrader doesn't keep track of Renko "tails" for bar related data.

Otherwise, pseudo business logic:

1) get current bar's open

2) check if open is initially above/below the MA

3) if open was below MA, then on each tick:

     a) get the MA's current value

     b) get the Symbol Ask/Bid/Closing price (whatever you want to consider has touched the MA)

    c) check if the above price is >= MA current value

4) if open was above MA, then:

    a) repeat steps 3a/3b

    b) check if the price is <= MA current value

 

Hope that helps and is what you're after?

 


@ctid5083541

ctid5083541
01 Apr 2023, 13:46

This code seems to make sense but I couldn't get it working. This may be due to the fact that I have my FromDateTime in a function - I should have stated this in the first post, my appologies.


@ctid5083541

ctid5083541
16 Mar 2023, 21:03

RE: RE:Is there a way to show the indicator on the actual chart?

samuelbreezey said:

PanagiotisCharalampous said:

Hi Sam,

See an example below

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeTheMinimalTrader : Indicator
    {

        [Output("UpVolume", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries DownVolume { get; set; }

        [Output("MA", LineColor = "Blue", PlotType = PlotType.Line, Thickness = 4)]
        public IndicatorDataSeries MA { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        private MovingAverage volumeMA;

        protected override void Initialize()
        {
            // Initialize and create nested indicators    
            volumeMA = Indicators.MovingAverage(Bars.TickVolumes, Periods, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = Bars.TickVolumes[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
            MA[index] = volumeMA.Result[index];
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you Panagiotis,

Is there a way to show the indicator on the actual chart?

Sam

It works if you have the indicator on the "Target Framework: .NET Framework 4.x".


@ctid5083541

ctid5083541
23 Dec 2022, 11:53

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OrderFlowTicks : Indicator
    {
        public enum GetMyData
        {
            On_Chart,
            Today,
            Yesterday,
            Weekly,
            Bi_Week,
            Monthly,
            Customized
        }

        [Parameter("Load From", DefaultValue = GetMyData.On_Chart, Group = "SETTINGS")]
        public GetMyData GetMyDataChoice { get; set; }

        [Parameter("Custom (dd/mm/yyyy)", DefaultValue = "00/00/0000", Group = "SETTINGS")]
        public string strDate { get; set; }

        public enum ReturnedType_Data
        {
            Percentage,
            Value,
            PercentageAndValue
        }
        [Parameter("Returned Type", DefaultValue = ReturnedType_Data.Percentage, Group = "OUTPUT")]
        public ReturnedType_Data ReturnedType_Choice { get; set; }

        [Parameter("Row Height", DefaultValue = 1.0, MinValue = 0.1, Group = "FORMATTING")]
        public double myHeight { get; set; } 

        [Parameter("Sell Color", DefaultValue = Colors.Green, Group = "BUY/SELL")]
        public Colors mySellColor { get; set; }

And many other Parameter Inputs.

None of these settings will ever change. I have some complex nested if statements referring to these Parameter Inputs which have to be executed if the value never changes - it just makes the code more labor intensive than it needs to be. I want to take out the if statements and at the same time speed up the running of the program that currently takes a long time to load initially.

Many thanks!


@ctid5083541

ctid5083541
26 May 2022, 15:09

RE:

amusleh said:

Hi,

What's the issue? are you using different labels?

I'm not a programmer although I know a little bit of Visual Basic. I think I now have it working correctly, at least I hope so.

 


@ctid5083541