Symbol.VolumeForProportionalRisk and similar functions does not work properly, always return 0

Created at 30 May 2023, 18:43
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Best.Algo.Trader's avatar

Best.Algo.Trader

Joined 24.05.2023

Symbol.VolumeForProportionalRisk and similar functions does not work properly, always return 0
30 May 2023, 18:43


I have difficulties using the function Symbol.VolumeForProportionalRisk in cTrader Desktop version 4.7.9 15890. I tried my best but it always returns 0. Please see my code and the log statements below. As you can see I am facing this issue with other fucntions as well...

Log Statements:

30/05/2023 01:59:00.000 | CBot instance [TestRiskBasedVolume, EURUSD, h1] stopped.
30/04/2023 23:00:00.000 | Pips 2:   0
30/04/2023 23:00:00.000 | Pips 1:   0
30/04/2023 23:00:00.000 | Volume 2: 0
30/04/2023 23:00:00.000 | Volume 1: 0
30/04/2023 23:00:00.000 | Balance:  10000
29/04/2023 02:00:00.000 | CBot instance [TestRiskBasedVolume, EURUSD, h1] started.
 

Code of Bot:

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.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class TestRiskBasedVolume : Robot
    {
        protected override void OnStart()
        {
            double stopLossInPips   =     10.0;
            double percentToRisk    =      1.0;
            double amountToTisk     =    500.0;
            double volume           = 100000.0; // 1 Lot
            
            Print("Balance:  ", Account.Balance);
            
            Print("Volume 1: ", Symbol.VolumeForProportionalRisk(ProportionalAmountType.Balance, percentToRisk, stopLossInPips));
            
            Print("Volume 2: ", Symbol.VolumeForFixedRisk(amountToTisk, stopLossInPips));

            Print("Pips 1:   ", Symbol.PipsForFixedRisk(amountToTisk, volume));

            Print("Pips 2:   ", Symbol.PipsForProportionalRisk(ProportionalAmountType.Balance, percentToRisk, volume));
        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

 

 


@Best.Algo.Trader
Replies

PanagiotisChar
31 May 2023, 08:28 ( Updated at: 21 Dec 2023, 09:23 )

Hi there,

I tried your bot and works fine for me. 

Maybe try a clean installation. If it persists, let us know your broker.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

Best.Algo.Trader
31 May 2023, 11:51 ( Updated at: 31 May 2023, 11:52 )

Thanks for the quick response. The clean installation solved my problem. 

Now the bot takes several seconds to finish backtesting even so it doesn’t do anything in OnTick or OnBar. 

When I remove the Symbol function calls in OnStart it runs as fast as expected. 

Any idea what this could be the reason? 


@Best.Algo.Trader

PanagiotisChar
01 Jun 2023, 08:29

Hi there,

I tried it but there is no noticeable difference for me. Can provide more information i.e. broker and backtesting settings, and maybe record a video demonstrating this difference?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us


@PanagiotisChar

Best.Algo.Trader
01 Jun 2023, 15:39

RE:

PanagiotisChar said:

Hi there,

I tried it but there is no noticeable difference for me. Can provide more information i.e. broker and backtesting settings, and maybe record a video demonstrating this difference?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

I will create a video, but now I have the first issue again and need to solve this again. :-(

My broker is fpmarkets.com and I used EURGBD on 1H with tick data for last 30 days as backtesting settings. 


@Best.Algo.Trader

Best.Algo.Trader
01 Jun 2023, 19:48

I did once more a clean installation, but it seems to me, the problem is not really solved by that. I have a video which shows how the functions work for one currency pair but not for another pair. So at the moment I can run my test bot successfully with EURGBP on 1H, but when switiching to EURUSD on 1H the functions always return 0. The video is 144 MB big. Not sure how to provide it to you.

After I did the clean installation EURGBP was the first test I run and it was successful. Then I change my language settings from German to English and run the test with EURUSD and now the issue occurred. Swittching back to English does not change anything, nor deleting local data under App\Roaming\Spotware. 

My best guess is that the issue is relatedt to the bars data downloaded. Not sure if a change of language settings may have an impact on data formats.

I also made a test with a different broker (an old FTMO account) but no difference there. 

I should mention that I run cTrader on Windows 10 on an Apple Macbook Pro (Intel) with Bootcamp.

Please let me know what additional information I can provide to support further analysis.

Thanks in advance


@Best.Algo.Trader

9750706
07 Jun 2023, 14:26

RE:

Same here. trying to use VolumeForFixedRisk works on EURGBP not on majors like EURUSD and GBPUSD, AUDUSD but works on USDJPY

 

seems it does not works on XXXUSD pairs

Kaspricci said:

I did once more a clean installation, but it seems to me, the problem is not really solved by that. I have a video which shows how the functions work for one currency pair but not for another pair. So at the moment I can run my test bot successfully with EURGBP on 1H, but when switiching to EURUSD on 1H the functions always return 0. The video is 144 MB big. Not sure how to provide it to you.

After I did the clean installation EURGBP was the first test I run and it was successful. Then I change my language settings from German to English and run the test with EURUSD and now the issue occurred. Swittching back to English does not change anything, nor deleting local data under App\Roaming\Spotware. 

My best guess is that the issue is relatedt to the bars data downloaded. Not sure if a change of language settings may have an impact on data formats.

I also made a test with a different broker (an old FTMO account) but no difference there. 

I should mention that I run cTrader on Windows 10 on an Apple Macbook Pro (Intel) with Bootcamp.

Please let me know what additional information I can provide to support further analysis.

Thanks in advance

 


@9750706

Best.Algo.Trader
01 Jul 2023, 16:24

With version 4.7.13 this issue seems to be gone. Now it works fine for USD pairs.


@Best.Algo.Trader