Need help with Moving Averages and Fibonacci
Need help with Moving Averages and Fibonacci
27 Dec 2024, 17:41
It should be simple but I am stuck in this.
I would like that each of two Moving Averages pick only specific values, in my case only Fibonacci values (for example only 5, 8, 13 ,21 ,34, 55, 89).
Beside being useful for my strategy, it would make my cBot optimisation much faster (instead of using Steps of 1 which takes forever).
Anyone may help please ?
Vicktor
Replies
Vicktor
29 Dec 2024, 17:44
RE: Need help with Moving Averages and Fibonacci
firemyst said:
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
Thank you for your welcome hint !
Will try to work on that even if I never used Enum in Parameter.
If you further suggestions please feel free to advise.
@Vicktor
Vicktor
30 Dec 2024, 08:49
RE: Need help with Moving Averages and Fibonacci
firemyst said:
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
I did the following but I am missing something because it is not working, can you please help?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.EEuropeStandardTime, AccessRights = AccessRights.None)]
public class Enum_Test : Robot
{
public enum FastValues
{
3,
5,
8,
13,
}
[Parameter("Fast Values")]
public FastValues P1 { get; set; }
public enum SlowValues
{
13,
21,
35,
55,
}
[Parameter("MA Slow Values")]
public SlowValues P2 { get; set; }
// MA FAST
[Parameter("Fast Source", Group = "Fast")]
public DataSeries MAfast { get; set; }
[Parameter("Fast Type", Group = "Fast")]
public MovingAverageType MAfasttype { get; set; }
private MovingAverage MA_fast;
// MA SLOW
[Parameter("Slow Source", Group = "Slow")]
public DataSeries MAslow { get; set; }
[Parameter("Slow Type", Group = "Slow")]
public MovingAverageType MAslowtype { get; set; }
private MovingAverage MA_slow;
protected override void OnStart()
{
MA_fast = Indicators.MovingAverage(MAfast, FastValues, MAfasttype);
MA_slow = Indicators.MovingAverage(MAslow, SlowValues, MAslowtype);
}
protected override void OnTick()
{
bool MA_fast_rise = Functions.IsRising(MA_fast.Result);
bool MA_fast_fall = Functions.IsFalling(MA_fast.Result);
bool MA_slow_rise = Functions.IsRising(MA_slow.Result);
bool MA_slow_fall = Functions.IsFalling(MA_slow.Result);
}
}
}
@Vicktor
firemyst
30 Dec 2024, 13:27
RE: RE: Need help with Moving Averages and Fibonacci
Vicktor said:
firemyst said:
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
I did the following but I am missing something because it is not working, can you please help?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.EEuropeStandardTime, AccessRights = AccessRights.None)]
public class Enum_Test : Robot
{
public enum FastValues
{
3,
5,
8,
13,
}
[Parameter("Fast Values")]
public FastValues P1 { get; set; }
public enum SlowValues
{
13,
21,
35,
55,
}
[Parameter("MA Slow Values")]
public SlowValues P2 { get; set; }
// MA FAST
[Parameter("Fast Source", Group = "Fast")]
public DataSeries MAfast { get; set; }
[Parameter("Fast Type", Group = "Fast")]
public MovingAverageType MAfasttype { get; set; }
private MovingAverage MA_fast;
// MA SLOW
[Parameter("Slow Source", Group = "Slow")]
public DataSeries MAslow { get; set; }
[Parameter("Slow Type", Group = "Slow")]
public MovingAverageType MAslowtype { get; set; }
private MovingAverage MA_slow;
protected override void OnStart()
{
MA_fast = Indicators.MovingAverage(MAfast, FastValues, MAfasttype);
MA_slow = Indicators.MovingAverage(MAslow, SlowValues, MAslowtype);
}
protected override void OnTick()
{
bool MA_fast_rise = Functions.IsRising(MA_fast.Result);
bool MA_fast_fall = Functions.IsFalling(MA_fast.Result);
bool MA_slow_rise = Functions.IsRising(MA_slow.Result);
bool MA_slow_fall = Functions.IsFalling(MA_slow.Result);
}
}
}
Your parameters to create the moving averages are incorrect. The second value needs to be an integer representing the length/period; you're passing it an enum type, but not the actual parameter value which is “P1” or “P2”.
Second, you need to convert it to an integer because P1 and P2 are enum types, not integers.
public enum FastValues
{
_1 = 1,
_2 = 2,
_3 = 3,
};
[Parameter("Fast Values", DefaultValue = FastValues._2)]
public FastValues P1 { get; set; }
MA_fast = Indicators.MovingAverage(MAfast, (int)P1, MAfasttype);
@firemyst
Vicktor
30 Dec 2024, 13:38
RE: RE: RE: Need help with Moving Averages and Fibonacci
firemyst said:
Vicktor said:
firemyst said:
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
I did the following but I am missing something because it is not working, can you please help?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.EEuropeStandardTime, AccessRights = AccessRights.None)]
public class Enum_Test : Robot
{
public enum FastValues
{
3,
5,
8,
13,
}
[Parameter("Fast Values")]
public FastValues P1 { get; set; }
public enum SlowValues
{
13,
21,
35,
55,
}
[Parameter("MA Slow Values")]
public SlowValues P2 { get; set; }
// MA FAST
[Parameter("Fast Source", Group = "Fast")]
public DataSeries MAfast { get; set; }
[Parameter("Fast Type", Group = "Fast")]
public MovingAverageType MAfasttype { get; set; }
private MovingAverage MA_fast;
// MA SLOW
[Parameter("Slow Source", Group = "Slow")]
public DataSeries MAslow { get; set; }
[Parameter("Slow Type", Group = "Slow")]
public MovingAverageType MAslowtype { get; set; }
private MovingAverage MA_slow;
protected override void OnStart()
{
MA_fast = Indicators.MovingAverage(MAfast, FastValues, MAfasttype);
MA_slow = Indicators.MovingAverage(MAslow, SlowValues, MAslowtype);
}
protected override void OnTick()
{
bool MA_fast_rise = Functions.IsRising(MA_fast.Result);
bool MA_fast_fall = Functions.IsFalling(MA_fast.Result);
bool MA_slow_rise = Functions.IsRising(MA_slow.Result);
bool MA_slow_fall = Functions.IsFalling(MA_slow.Result);
}
}
}
Your parameters to create the moving averages are incorrect. The second value needs to be an integer representing the length/period; you're passing it an enum type, but not the actual parameter value which is “P1” or “P2”.
Second, you need to convert it to an integer because P1 and P2 are enum types, not integers.
public enum FastValues{ _1 = 1, _2 = 2, _3 = 3,}; [Parameter("Fast Values", DefaultValue = FastValues._2)] public FastValues P1 { get; set; } MA_fast = Indicators.MovingAverage(MAfast, (int)P1, MAfasttype);
You made my day !
Thank you so much !
@Vicktor
Vicktor
30 Dec 2024, 13:57
RE: RE: RE: RE: Need help with Moving Averages and Fibonacci
Vicktor said:
firemyst said:
Vicktor said:
firemyst said:
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
I did the following but I am missing something because it is not working, can you please help?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.EEuropeStandardTime, AccessRights = AccessRights.None)]
public class Enum_Test : Robot
{
public enum FastValues
{
3,
5,
8,
13,
}
[Parameter("Fast Values")]
public FastValues P1 { get; set; }
public enum SlowValues
{
13,
21,
35,
55,
}
[Parameter("MA Slow Values")]
public SlowValues P2 { get; set; }
// MA FAST
[Parameter("Fast Source", Group = "Fast")]
public DataSeries MAfast { get; set; }
[Parameter("Fast Type", Group = "Fast")]
public MovingAverageType MAfasttype { get; set; }
private MovingAverage MA_fast;
// MA SLOW
[Parameter("Slow Source", Group = "Slow")]
public DataSeries MAslow { get; set; }
[Parameter("Slow Type", Group = "Slow")]
public MovingAverageType MAslowtype { get; set; }
private MovingAverage MA_slow;
protected override void OnStart()
{
MA_fast = Indicators.MovingAverage(MAfast, FastValues, MAfasttype);
MA_slow = Indicators.MovingAverage(MAslow, SlowValues, MAslowtype);
}
protected override void OnTick()
{
bool MA_fast_rise = Functions.IsRising(MA_fast.Result);
bool MA_fast_fall = Functions.IsFalling(MA_fast.Result);
bool MA_slow_rise = Functions.IsRising(MA_slow.Result);
bool MA_slow_fall = Functions.IsFalling(MA_slow.Result);
}
}
}
Your parameters to create the moving averages are incorrect. The second value needs to be an integer representing the length/period; you're passing it an enum type, but not the actual parameter value which is “P1” or “P2”.
Second, you need to convert it to an integer because P1 and P2 are enum types, not integers.
public enum FastValues{ _1 = 1, _2 = 2, _3 = 3,}; [Parameter("Fast Values", DefaultValue = FastValues._2)] public FastValues P1 { get; set; } MA_fast = Indicators.MovingAverage(MAfast, (int)P1, MAfasttype);
You made my day !
Thank you so much !
Just implemented and it works perfectly.
Thank you again !
In general I am a fast learner, but I have troubles since I did not find any complete course on cAlgo.
@Vicktor
firemyst
28 Dec 2024, 03:14
You have to make them as a C# Enum, and use the Enum in the parameter if you only want those specific values chosen.
Of course, you could always set the step in the parameter to something else like “5” instead of “1” as well. It won't land on the specific fib numbers, but it's less clicking to get there.
@firemyst