Replies

jonlangdon
29 Sep 2023, 11:39 ( Updated at: 29 Sep 2023, 11:43 )

RE: MarketData.GetBars - Loading the same timeframe twice

PanagiotisChar said: 

Hi there,

I guess it will be loaded only once but why do you need to do that? Why don't you just use bars1?

 

Hi, thanks for that.

It's not really that I wanted to do it on purpose, more just for understanding and to avoid unnecessarily loading multiple instances of the same thing. 

In a case where I'm setting the time frame of an indicator from configuration like below, as an example:

[Parameter(DefaultValue = "m5", Group = "TimeFrames")]
public TimeFrame MaTimeframe { get; set; }

[Parameter(DefaultValue = "m10", Group = "TimeFrames")]
public TimeFrame BbTimeframe { get; set; }

// ...

DataSeries maBars = MarketData.GetBars(MaTimeframe).ClosePrices;
MovingAverage ma = Indicators.MovingAverage(maBars, 50, MovingAverageType.Simple);

DataSeries bbBars = MarketData.GetBars(BbTimeframe).ClosePrices;
BollingerBands bb = Indicators.BollingerBands(bbBars, 20, 2, MovingAverageType.Simple);

This would allow for time frames to be changed independently for each indicator, but could lead to a case where both time frames where the same.


@jonlangdon

jonlangdon
13 Apr 2023, 01:17

RE:

PanagiotisChar said:

Hi there,

I am not aware of any issues as I do not work for Pepperstone or Spotware. I was just trying to help.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

Hi Panagiotis,

I see, apologies for that - still finding my way around the setup here.

I must admit I did have it in my head that you were perhaps connected to Spotware - I think it's because I've seen your name come up so often since I've been looking around the Forum!

I don't suppose you would know what route, if any, I could follow to get an answer to the sort of question I had?

You're help is much appreciated!

Best regards,

Jon


@jonlangdon

jonlangdon
11 Apr 2023, 16:24

RE:

PanagiotisChar said:

Hi there,

Unfortunately I cannot tell what happens from a snippet I cannot run. I would need a complete cBot code that I can run and reproduce this behavior.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

Hi Panagiotis,

Thanks for your reply.

On the most simple level, if you had run the code below on 05-Apr-2023 06:00:00 (I was running this on GBPUSD 1m - Pepperstone, Europe - Demo - Hedging - USD), PipValue returned 0.

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 rtExample : Robot
    {

        protected override void OnStart()
        {

        }
        
        
        protected override void OnBar()
        {
            Print("Pip Value: ", Symbol.PipValue);
        }

    }
}

This appears to have since been fixed and pip value returns correctly now (I don't know exactly when it was fix but PipValue returned 0 for a few days). Really, I just want to know:

Were you aware of there being any issues in this regard?

Was this only an issue on Demo accounts?

Is there any chance of this happening going forward - is PipValue the correct/reliable value to use in my volume calculations?

 

Best regards,

Jon


@jonlangdon

jonlangdon
09 Apr 2023, 02:40

RE:

PanagiotisChar said:

Hi there,

Please share the cBot code that will allow us to reproduce this behavior so that we can explain what happens.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Hi Panagiotis,

Thanks for getting back to me - I did reply to this yesterday, but couldn't see my response online yet so wondered if something went wrong when I submitted. Hopefully this is not a repeat...

My code is fairly simple but I have got classes organised separately for reuse, so not easy to paste the whole thing. Hopefully the following will be enough to explain.

I have a class to map bar and symbol values, which I then pass to my strategy ...

    protected override void OnBar()
    {
        var updates = new BarUpdate() {
            BarTime = Bars.Last(1).OpenTime,
            OpenPrice = Bars.Last(1).Open,
            HighPrice = Bars.Last(1).High,
            LowPrice = Bars.Last(1).Low,
            ClosePrice = Bars.Last(1).Close,
            BidPrice = Symbol.Bid,
            AskPrice = Symbol.Ask,
            PipSize = Symbol.PipSize,
            PipValue = Symbol.PipValue,
        };

        MyStrategy.OnBar(updates);
    }

If a trade signal is triggered, I am then using the PipValue in my volume calculation. An example with $100 risk would be:

Volume = ($100 / Stop Loss Pips) / PipValue

I was hoping that by calculating the volume like this, it would be generic and could be used for all currencies/instruments regardless of my account currency.

My main worry is that this approach was working fine until 05-Apr as mentioned above. Since then PipValue has returned 0 and the calculation no longer works. So I was hoping to understand the best approach for this going forward.

Best regards,

Jon

 


@jonlangdon