Creating Standard Deviation with SMA as source in cBot Robot
Creating Standard Deviation with SMA as source in cBot Robot
06 Sep 2023, 13:39
Hi, is there any chance we could calculate standard deviation with SMA result in cBot ? Appreciate if anyone could me help solving it ! I want to make SMA50 as the source of Standard Deviation I can do it in the indicator but I dont know how to do it in cBot this is the indicator code
this is the indicator code
///
protected override void Initialize()
{
_standardDeviation = Indicators.StandardDeviation(SMA50, 50, MovingAverageType.Simple);
}
public override void Calculate(int index)
{
// Calculate SMAbands
var SMA50dev = 2*_standardDeviation.Result[index];
}
///
how can I make this in robot?
Replies
JXTA
08 Sep 2023, 06:26
RE: Creating Standard Deviation with SMA as source in cBot Robot
PanagiotisChar said:
Here you go
var sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 50);
var sd = Indicators.StandardDeviation(sma.Result,50, MovingAverageType.Simple);
Thanks Panagiotis, I found another problem while creating multiple SMAs and trying to use it as source in standard deviation it’s not possible to add up these SMAs, it says operator ‘+’ cannot be applied to operands of type ’SimpleMoving Average’ and ’SimpleMoving Average’, can you help me with the problem?
eg:
var sma1 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 50);
var sma2 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 100);
var sma3 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 150);
var sma4 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 200);
var sma_1234 = (((sma1+sma2)/2) + ((sma3+sma4)/2))/2
var sd = Indicators.StandardDeviation(sma_1234.Result,50, MovingAverageType.Simple);
@JXTA
PanagiotisChar
08 Sep 2023, 06:32
var sma_1234 = (((sma1+sma2)/2) + ((sma3+sma4)/2))/2
You cannot do this, this is not pinescript :) You need to create a new indicator that will do this and return a single result as output
@PanagiotisChar
PanagiotisChar
07 Sep 2023, 06:06
Here you go
var sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 50);
var sd = Indicators.StandardDeviation(sma.Result,50, MovingAverageType.Simple);
@PanagiotisChar