How to define candle open in relation to moving average

Created at 17 Mar 2019, 08:03
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!
AN

anjanbfx@gmail.com

Joined 17.03.2019

How to define candle open in relation to moving average
17 Mar 2019, 08:03


HI guys,

I am trying to code on Cautomate.

I can define the moving average crosses. But I don't know how to define "if commands" for the candles above MA.

example: if ( price is above MA && previous candle open is above the MA && previous previous candle open is also above MA)

                    { OP BUY }

 

can someone guide me with this particular logic? 

In mql4 I just used  "open0, open1, open2 ... etc" 

 

thank you in advance


@anjanbfx@gmail.com
Replies

PanagiotisCharalampous
18 Mar 2019, 12:13

Hi anjan babu,

See below an example

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.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        SimpleMovingAverage _sma;
        protected override void OnStart()
        {
            _sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 14);
        }

        protected override void OnTick()
        {
            if (_sma.Result.LastValue > Symbol.Bid && MarketSeries.Open.Last(1) > _sma.Result.LastValue && MarketSeries.Open.Last(2) > _sma.Result.LastValue)
            {
                // Do something
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous