Trade based on last candle colour

Created at 05 Mar 2021, 22:59
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!
Z0

z00k

Joined 03.05.2020

Trade based on last candle colour
05 Mar 2021, 22:59


New to trying automated trading and was wondering if there is a way to set up a bot that will place a trade based on the last candle close colour at a specific time. For example on the 30 min chart if the 11:00am candle closes green the bot will open a long, if the candle closes red it will short.

 

Thanks


@z00k
Replies

amusleh
08 Mar 2021, 13:00

Try this:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BarColorChangeTrader : Robot
    {
        protected override void OnBar()
        {
            if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1)
                && Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2))
            {
                Print("New bullish/up bar");

                ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin);
            }
            else if (Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1)
                && Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2))
            {
                Print("New bearish/down bar");

                ExecuteMarketOrder(TradeType.Sell, SymbolName, Symbol.VolumeInUnitsMin);
            }
        }
    }
}

 


@amusleh