Assist to build simple MA cross strat bot
29 Jun 2018, 03:21
i would like to ask if anyone could help to build or share a simple MA cross strat bot for ctrader. I’m struggling to get the coding in my head and would love a simple template to build from. If anyone would be kind enough to help let me know.
Thankyou
Replies
zedodia
29 Jun 2018, 09:47
Thankyou very much. im trying to learn the code. in calgo - where do i find the codes for different things. as an example
{
SimpleMovingAverage SlowMA, FastMA;
Position Pos;
protected override void OnStart()
{
SlowMA = Indicators.SimpleMovingAverage(MarketSeries.Close, 100);
FastMA = Indicators.SimpleMovingAverage(MarketSeries.Close, 50);
}
in this section, i would like to alter the type of indicator i use. lets say i want to change it to a weighted moving average. in the right hand coloum there is a list. is this where i find the correct syntax to replace the 'SimpleMovingAverage'?
sorry if this is a super noob question. once i know where to look i can usually work most things out with playing.
@zedodia
AlgoCorner
29 Jun 2018, 09:54
Just replace SimpleMovingAverage for WeightedMovingAverage
@AlgoCorner

AlgoCorner
29 Jun 2018, 09:17
Here's a simple example:
using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Examples : Robot { SimpleMovingAverage SlowMA, FastMA; Position Pos; protected override void OnStart() { SlowMA = Indicators.SimpleMovingAverage(MarketSeries.Close, 100); FastMA = Indicators.SimpleMovingAverage(MarketSeries.Close, 50); } protected override void OnBar() { bool direction = FastMA.Result.Last(1) > SlowMA.Result.Last(1); TradeType tT = direction ? TradeType.Buy : TradeType.Sell; if (Positions.Count == 0) { Pos = ExecuteMarketOrder(tT, Symbol, 1000).Position; } else { if((Pos.TradeType == TradeType.Buy && !direction) || (Pos.TradeType == TradeType.Sell && direction)) ClosePosition(Pos); } } } }@AlgoCorner