Replies

yaghouti
13 Apr 2023, 09:19

RE:

i want to check some parameters on each tick and change the period1 from calculate,

would you mind please explain me how to do this task?

 

 

firemyst said:

It won't change unless you create a new MovingAverage with the new setting or overwrite the previous one.

So after you change "period1", you should do this again:

param1 = Indicators.MovingAverage(param2, period1, MovingAverageType.Simple);

The Initialize method will only run again if you display the parameters window and change it that way.

If you programmatically change values, then you need to programmatically create new movingaverage objects with those new parameters.

 


@yaghouti

yaghouti
14 Mar 2023, 09:03

RE:

PanagiotisChar said:

Hi there,

Well that's not what you asked for initially :) Here is an example

var volume = Symbol.NormalizeVolumeInUnits(Balance * Symbol.DynamicLeverage[0].Leverage / AssetConverter.Convert(1, Symbol.BaseAsset, Account.Asset));

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

hi there
Error    CS0103    The name 'AssetConverter' does not exist in the current context   

i have these includes:

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;

is there any package that i should add with Nuget?


@yaghouti

yaghouti
14 Mar 2023, 08:34

RE:

PanagiotisChar said:

Hi there,

Well that's not what you asked for initially :) Here is an example

var volume = Symbol.NormalizeVolumeInUnits(Balance * Symbol.DynamicLeverage[0].Leverage / AssetConverter.Convert(1, Symbol.BaseAsset, Account.Asset));

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

thank you very much


@yaghouti

yaghouti
13 Mar 2023, 17:24

RE:

PanagiotisChar said:

Hi there,

Sorry, is the Symbol.VolumeToQuantity() you should be using. My typo.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

thanks for your reply and help

unfortunately this one also not working, for example if account balance is 170usd this will return 0.0017,
i need a code that i give it usd amount, then it calculated maximum lot which use all the 170usd margine in order to manage the risk in next steps,
is leverage should consider manualy?


@yaghouti

yaghouti
13 Mar 2023, 16:39

RE:

PanagiotisChar said:

Hi there,

Use Symbol.QuantityToVolumeInUnits method

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

hi there

unfortunately not working:

public static double GetLotPerRisk(Symbol symbol, double riskPercentage, double accountBalance, double stopLossInPips)
        {
            return symbol.QuantityToVolumeInUnits( accountBalance);
        }

for example if i have 170usd in account this function returns 17000000


@yaghouti

yaghouti
09 Mar 2023, 15:54

RE: RE: RE:

pick said:

yaghouti said:

pick said:

Does your bot have full access rights?

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class YourBot : Robot
{

 

thanks alot, i changed the accessright to fullaccess and that problem solved but unfortunately i get new erro:

09/03/2023 15:36:36.527 | CBot instance [Sample Hotkey Trading, AUDUSD, h1] crashed with error "Crashed in OnStart with SharpDXException: HRESULT: [0x80040154], Module: [SharpDX.DirectInput], ApiCode: [DIERR_DEVICENOTREG/DeviceNotRegistered], Message: Class not registered "

 

 

error refers to this part of code:

 protected override void OnStart()
        {

            
            directInput = new DirectInput();
            var joystickGuid = Guid.Empty;
            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            joystick = new Joystick(directInput, joystickGuid);/////////////////////<<<<<<<<<<here is the error
            joystick.Properties.BufferSize = 128;
            joystick. Acquire();

}

Is your "joystickGuid" variable still empty after that for loop? I have not used this library before, but that's what I would check first.

A quick search found this, if you look here, they are searching for DeviceType.Joystick if there is no result for DeviceType.Gamepad

thank you very much for your guide.

the problem solved and i can read the joystick keys in the cbot but one last question, i use onTick to trigger the key press which is not suitable, i want to get trigger as soon as user press any key on the joystick, how can i solve this problem?


@yaghouti

yaghouti
09 Mar 2023, 14:08 ( Updated at: 09 Mar 2023, 14:14 )

RE:

pick said:

Does your bot have full access rights?

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class YourBot : Robot
{

 

thanks alot, i changed the accessright to fullaccess and that problem solved but unfortunately i get new erro:

09/03/2023 15:36:36.527 | CBot instance [Sample Hotkey Trading, AUDUSD, h1] crashed with error "Crashed in OnStart with SharpDXException: HRESULT: [0x80040154], Module: [SharpDX.DirectInput], ApiCode: [DIERR_DEVICENOTREG/DeviceNotRegistered], Message: Class not registered "

 

 

error refers to this part of code:

 protected override void OnStart()
        {

            
            directInput = new DirectInput();
            var joystickGuid = Guid.Empty;
            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            joystick = new Joystick(directInput, joystickGuid);/////////////////////<<<<<<<<<<here is the error
            joystick.Properties.BufferSize = 128;
            joystick. Acquire();

}


@yaghouti

yaghouti
23 Jul 2021, 17:25

RE:

Hi again

just one more problem.

i try to use this linePriceValue in for my stoploss:

position.ModifyStopLossPrice(Math.Round(DefaultSTL,Symbol.Digits)); or position.ModifyStopLossPrice(DefaultSTL);

but unfortunately i get the error:

23/07/2021 18:50:48.947 | → Modifying position PID17057357 (SL: 1.17751257895653, TP: 1.17541361298747) FAILED with error "InvalidStopLossTakeProfit", Position PID17057357

i print the linePriceValue and the printed value is OK but when i try to assign it to my position stoploss i get the error.

 

amusleh said:

Hi,

You can draw an interactive chart trend line and then whenever the user changed it you can use the chart objects updated event.

 


@yaghouti

yaghouti
23 Jul 2021, 15:56

RE:

Hi Ahmad
thank you VERY MUCH, it works now

thanks for code.

 

amusleh said:

Hi,

You can draw an interactive chart trend line and then whenever the user changed it you can use the chart objects updated event.

 


@yaghouti

yaghouti
23 Jul 2021, 14:18

RE:

Hi 

thanks for reply

i just need one line, which could be change by user on the chart, and in the bot side, we can get it's Y and compare with price, the most important point is that user can click and change the position or angle of the line

amusleh said:

Hi,

You can use a chart trend line CalculateY method to check if the price is touched or not, this sample might help you:

using cAlgo.API;
using System;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LineAlert : Indicator
    {
        #region Parameters

        [Parameter("Single Alert", DefaultValue = true, Group = "General")]
        public bool SingleAlert { get; set; }

        [Parameter("Trend/Ray", DefaultValue = true, Group = "Line Types")]
        public bool TrendLine { get; set; }

        [Parameter("Horizontal", DefaultValue = true, Group = "Line Types")]
        public bool HorizontalLine { get; set; }

        [Parameter("Vertical", DefaultValue = true, Group = "Line Types")]
        public bool VerticalLine { get; set; }

        [Parameter("Show Comment", DefaultValue = true, Group = "Comment")]
        public bool ShowComment { get; set; }

        [Parameter("Comment Suffix", Group = "Comment")]
        public string CommentSuffix { get; set; }

        #endregion Parameters

        #region Overridden methods

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            foreach (var chartObject in Chart.Objects)
            {
                if (!string.IsNullOrEmpty(CommentSuffix) && !chartObject.Comment.EndsWith(CommentSuffix, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }


				var isAlert = false;
				
                if (chartObject.ObjectType == ChartObjectType.TrendLine || chartObject.ObjectType == ChartObjectType.HorizontalLine)
                {
                    var linePriceValue = double.NaN;

                    if (TrendLine && chartObject.ObjectType == ChartObjectType.TrendLine)
                    {
                        var chartTrendLine = chartObject as ChartTrendLine;

                        if (chartTrendLine != null) linePriceValue = chartTrendLine.CalculateY(index);
                    }
                    else if (HorizontalLine && chartObject.ObjectType == ChartObjectType.HorizontalLine)
                    {
                        var chartHorizontalLine = chartObject as ChartHorizontalLine;

                        if (chartHorizontalLine != null) linePriceValue = chartHorizontalLine.Y;
                    }

                    if (Bars.ClosePrices[index] >= linePriceValue && Bars.ClosePrices[index - 1] < linePriceValue)
                    {
                        isAlert = true;
                    }

                    if (Bars.ClosePrices[index] <= linePriceValue && Bars.ClosePrices[index - 1] > linePriceValue)
                    {
                        isAlert = true;
                    }
                }
                else if (VerticalLine && chartObject.ObjectType == ChartObjectType.VerticalLine)
                {
                    var chartVerticalLine = chartObject as ChartVerticalLine;

                    if (chartVerticalLine != null 
                        && Bars.OpenTimes[index] >= chartVerticalLine.Time 
                        && Bars.OpenTimes[index - 1] < chartVerticalLine.Time)
                    {
                        isAlert = true;
                    }
                }

                if (isAlert)
                {
                    // The code for alert goes here
                }
            }
        }

        #endregion Overridden methods
    }
}

 

 


@yaghouti

yaghouti
16 Jul 2021, 11:36

RE:

Hi Panagiotis 
thanks for reply
i exactly do the same it works in swing trades but my problem is that in scalp trades when we reach the target usually not execute at the point and close in next ticks which maybe lower prices. is there any trick to close position exactly at the trigger tick?

regards

PanagiotisCharalampous said:

Hi yaghouti,

You can use ModifyVolume method to change the position's volume and partially close it at any stage of the execution. So if you want to close 50% of the position, just modify the volume to be half of the initial quantity.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

 


@yaghouti