Topics
Replies
markmath01
02 Dec 2024, 18:38
Hi All,
I just wanted to add that there is definitely something strange / errorneous happening - and it doesn't appear to be with just the MACD.
I have just decided to output the previous and current MACD values, alongside the Bars.ClosePrices.Last(0) and Bars.ClosePrices.LastValue properties and they are definitely NOT Closing Prices.
They are OpenPrices.
See highlight below
Can someone shed some light as to what could be happening here as I can't see why the MACD is incorrect or why this is returning Open Prices and not Closing Prices?
Thanks
Mark
@markmath01
markmath01
09 Nov 2024, 18:01
( Updated at: 10 Nov 2024, 15:35 )
RE: Backtest: How to enter a trade at the Open of the *next* bar
firemyst said:
If you're programming a bot, use the OnBar() method.
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{ [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class ThirdBarMarketOrderBot : Robot { private int barCount; protected override void OnStart() { barCount = 0; } protected override void OnBar() { barCount++; Print ("Bar count {0}", barCount); } }}
You can find more about it by googling “calgo onbar”
Thanks !
@markmath01
markmath01
03 Dec 2024, 09:09
RE: MACD query - is the calculation correct in cTrader?
PanagiotisCharalampous said:
Hi - see code below. Thanks.
protected override void OnStart()
{
_macd = Indicators.MacdCrossOver(SlowMAPeriod, FastMAPeriod, SignalLinePeriod);
Print("MACD-Analysis started with MACD parameters: Fast MA = {0}, Slow MA = {1}, Signal Line = {2}",
FastMAPeriod, SlowMAPeriod, SignalLinePeriod);
}
protected override void OnBar()
{
double macdValue = _macd.MACD.LastValue;
//Print("MACD = {0:F7}, Time = {1}, {2}", macdValue, Bars.OpenTimes.LastValue, Bars.OpenTimes.Last(1));
//Print("MACD = {0:F7}", macdValue);
Print("Last MACD = {0:F7}, MACD = {1}, Last(0) = {2}, LastVal = {3}", lastMACD, macdValue, Bars.ClosePrices.Last(0), Bars.ClosePrices.LastValue);
// Check for zero-line crossing
if (lastMACD.HasValue)
{
if ((lastMACD < 0 && macdValue > 0) || (lastMACD > 0 && macdValue < 0))
{
// A zero-line crossing occurred
ProcessWave(macdValue < 0);
}
}
lastMACD = macdValue; // Update the last MACD value
//Print("Last MACD = " + lastMACD) ;
}
@markmath01