JZ Koh
JZ Koh's avatar

Info

Username:chocoboy
Name:JZ Koh
Member since: 16 Sep 2014

About

I have been coding indicators and trading algorithms(Mathematical/Statistical Models & Technical Indicators) for my personal use for at least a year.

Signature

None

Last Algorithm Comments

@RSI & Boll Bands w Threshold activation:  13 Jan 2015, 16:55


none of the "sl" variables should be negative. The lower bound should be 0.  You are prob getting that msg because whenever the bot tries to submit a trade, the negative "sl" values prevents it from doing so. That should solve the problem.      

@RSI & Boll Bands w Threshold activation:  12 Jan 2015, 09:54


Hm... You might want to try changing the value of the "lotsize" parameter?    

Last Forum Posts

@cBot Crashed in OnTick:  16 Sep 2014, 16:41


This is my first using the cAlgo platform. 

In this code, I am trying to code a simple trend following strategy. However, I must be missing something because I get the following error message:

15/03/2013 01:33:30.000 | Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object.

Can someone help me and tell me what I am doing wrong please? Thank you

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 Trend : Robot
    {

        public int LotSize = 10;


        protected override void OnStart()
        {
       
        }
        protected override void OnTick()
        {
            double y_range = (MarketSeries.Close.Last(1) - MarketSeries.Open.Last(1));
            double trail_stop = 0.2 * Math.Abs(y_range);
            double hardstop = 0.5 * Math.Abs(y_range);
            int total_positions = Positions.Count;


            if (total_positions < 1)
            {
                //Buy market entry with hard stop at 50% of t-1
                if (y_range > 0 && Symbol.Bid > MarketSeries.Close.Last(1))
                {
                    var b_signal = ExecuteMarketOrder(TradeType.Buy, Symbol, LotSize);

                    if (b_signal.IsSuccessful)
                    {
                        var position = b_signal.Position;
                        var stopLoss = position.EntryPrice - hardstop;
                        ModifyPosition(position, stopLoss, null);
                    }
                }
                //Sell market entry with hard stop at 50% of t-1
                else if (MarketSeries.Open.Last(1) < MarketSeries.Close.Last(1) && y_range < 0)
                {
                    var s_signal = ExecuteMarketOrder(TradeType.Sell, Symbol, LotSize);

                    if (s_signal.IsSuccessful)
                    {
                        var position = s_signal.Position;
                        var stopLoss = position.EntryPrice + hardstop;
                        ModifyPosition(position, stopLoss, null);
                    }
                }
            }

            if (total_positions > 0)
            {
                var position_b = Positions.Find(null, null, TradeType.Buy);
                var position_s = Positions.Find(null, null, TradeType.Sell);
                var trailer_b = Symbol.Ask - trail_stop;
                var trailer_s = Symbol.Bid + trail_stop;

                if (position_b != null && Symbol.Ask - trail_stop > position_b.StopLoss)
                {
                    ModifyPosition(position_b, trailer_b, null);
                }

                if (position_s != null && Symbol.Bid + trail_stop > position_s.StopLoss)
                {
                    ModifyPosition(position_s, trailer_s, null);
                }

            }
            //Buy market entry

            //Sell market entry

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
free  06 Jan 2015
Reversion & Trend trading robot. Utilizes threshold to determine entry. Includes trailing stop loss. Reversion & Trend trading robot. Utilizes threshold to determine entry. Includes trailing stop loss.