Topics

Forum Topics not found

Replies

Daedalusx086
05 Dec 2015, 02:02 ( Updated at: 21 Dec 2023, 09:20 )

RE: Your materials need to be better

jhtrader said:

Dear CAlgo Team,

The example I am trying to demonstrate is not for trading purposes.  The material you have in  Referencing Custom Indicators does not show any example where a robot reads the information from an indicator.  This question is directly asks how to use the API to access information from an indicator inside a robot.  There is no trading logic it is a simple "hello world" type example.

In order to build use of your platform I urge you to document many more examples so that people new to the platform can use the API better. I am trying to help bridge gaps in the knowledge base by framing simple searchable examples that I am sure will provide useful examples to the community, I am deliberately making them general so that they are not in any way specific to any strategy, just a simple use case on how to use the API.

Please consider that without users actively able to use the API the good work you are doing will amount to little.

 

Hey JHTrader, 

 

The NaN you are getting arises from the disparity between the rates of growth in the indexes on different timeframes. Your results are there, just not displaying in terms of the chart time frame - see below pic:

EUR/USD 15min

As the indexes grow at different rates (15 min at 4 times that of the 1 hour time frame), you need to convert the index of the chart time frame you want to get the result for to terms of the referenced time frame.

 

The following code shows the changes in the indicator that are required to get the referenced time frame to show in terms of the chart time frame (plus I updated the NaN check, just couldn't help myself):

 

public override void Calculate(int index)
{
    //Calculate the output for the Symbol asked for by the User
    // and return

    // Convert index of current chart timeframe to the index of the timeframe being referenced
    int i_symbolindex = mktSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

    // Use this converted index to get values in relation to chart indexes
    double high = mktSeries.High[i_symbolindex];
    double low = mktSeries.Low[i_symbolindex];

    // Moved for error check
    var prevClose = mktSeries.Close[i_symbolindex - 1];

    // Modified check for robustness
    if (double.IsNaN(prevClose))
    {
        _tempBuffer[index] = (high - low);
        //* symbol.PipSize
    }
    else
    {
        _tempBuffer[index] = (Math.Max(high, prevClose) - Math.Min(low, prevClose));
        //* symbol.PipSize
    }

    Result[index] = _ema.Result[index];
}

 

Cheers.


@Daedalusx086

Daedalusx086
15 Nov 2015, 22:42

Looks like that is being caused by the fact you're only updating the values for Current_Open_Price and Current_Close_Price at the start of each new bar.

 

That means that when you're getting the values for Current_Close_Price when only 1 tick has defined the current bar, which means the close price (the last tick) the system has for that bar also happens to be the starting (opening value) for that bar. Backtesting treats the tick flow as if it's in real-time for the bot, so won't let it see the "future" (namely the ticks yet to pass) from the bot's time reference.

 

You would need to adjust your code so it is updating the Current_Close_Price dynamically every few ticks if the Current_Close_Price is vital in your algo. 

 

Cheers.


@Daedalusx086

Daedalusx086
03 Nov 2015, 09:59

MarketSeries.TimeFrame.ToString()

Should be what you're after.


@Daedalusx086