Help with coding this strategy

Created at 10 Mar 2014, 18:41
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!
CR

Croboter

Joined 17.10.2013

Help with coding this strategy
10 Mar 2014, 18:41


Hi,

May I crave the indulgence of experienced cAlgo coders in the house to help me write the robot code for this strategy:

a. Execute to trade only once per bar

b. Trade only when spread is less than or equal to 5

c. Do not execute another trade if two trades are still on

d. Do not execute for the next two bars if trades have been executed in the last two consecutive bars

e. Do not execute trade for the next 10 bars if three consecutive losses were last made.

Else

Buy Market order when the current price crosses above the previous median price+10pips point (1 standard lot, 3 pips slippage, 40pips take profit and 20 pips stoploss)

or Sell Market order when the current price crosses below the previous median price+10pips point (1 standard lot, 3 pips slippage, 40pips take profit and 20 pips stoploss)

Thanks


@Croboter
Replies

Spotware
11 Mar 2014, 09:10

We can recommend you contact one of our Partners or post a job in Jobs section.


@Spotware

Old Account
11 Mar 2014, 19:05

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 cAlgoForum : Robot
    {
        public int FailTradeCount;
        public int TradeCooldown;

        protected override void OnStart()
        {
            Positions.Closed += PositionsOnClosed;
            FailTradeCount = 0;
            TradeCooldown = 0;
        }

        protected override void OnTick()
        {
            double Median_P10 = MarketSeries.Median.LastValue + (10 * Symbol.PipSize);
            double Median_M10 = MarketSeries.Median.LastValue - (10 * Symbol.PipSize);

            bool Check_1 = Symbol.Spread <= 5;
            bool Check_2 = Positions.Count <= 2;
            bool Check_3 = FailTradeCount <= 0;
            bool Chech_4 = TradeCooldown <= 0;

            bool Check_5B = Symbol.Ask >= Median_P10;
            bool Check_5S = Symbol.Ask <= Median_M10;



            if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5B)
                ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "Buy", 20, 40);

            if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5S)
                ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "Sell", 20, 40);
            Print("{0}{1}", Check_5S, Check_5B);
        }
        private void PositionsOnClosed(PositionClosedEventArgs args)
        {

            var position = args.Position;

            if (position.GrossProfit < 0)
                FailTradeCount = 10;

            if (position.EntryTime == DateTime.Now)
                TradeCooldown = 2;

        }
        protected override void OnBar()
        {
            FailTradeCount = FailTradeCount - 1;
            TradeCooldown = TradeCooldown - 1;
        }
    }
}

 


@Old Account