Assist to build simple MA cross strat bot

Created at 29 Jun 2018, 03:21
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ZE

zedodia

Joined 30.05.2018

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


@zedodia
Replies

Waxy
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);
            }
        }
    }
}

 


@Waxy

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

Waxy
29 Jun 2018, 09:54

Just replace SimpleMovingAverage for WeightedMovingAverage


@Waxy

zedodia
29 Jun 2018, 09:58

Thanks - i realise thats how to change it. i am asking this to find where to look to get these syntax's.


@zedodia