Can this be done

Created at 26 Feb 2018, 10:56
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!
JJ

jjwes76@gmail.com

Joined 03.11.2017

Can this be done
26 Feb 2018, 10:56


I dont know if i can put a logick in to my cbot to to open a trade at a specific price

example; Yen ,when the sma crosses below a surten price say150.000 the cbot then opens a Sell position

i want to use the sma combined with the actual price or the round number indicator

please explane if this is posseble


@jjwes76@gmail.com
Replies

PanagiotisCharalampous
26 Feb 2018, 12:40

Hi jjwes76@gmail.com,

Yes this is possible. See an example below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        [Parameter(DefaultValue = 0.0)]
        public double TargerPrice { get; set; }
        private SimpleMovingAverage _sma;
        protected override void OnStart()
        {
            _sma = Indicators.SimpleMovingAverage(MarketSeries.High, 5);
        }

        protected override void OnTick()
        {
            if (_sma.Result.LastValue < TargerPrice)
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000);
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous