My diary notes and learning

General discussion about cTrader and CAlgo
Post Reply
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

My diary notes and learning

Post by babalu4u »

If this will be useful to anyone I will be happy... :geek:

Ok....

This is on the start empty template robot (EA) document:

Code: Select all

// -------------------------------------------------------------------------------
//
//    This is a Template used as a guideline to build your own Robot. 
//    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot]
    public class NewRobot : Robot
    {
        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
Last edited by babalu4u on Thu Jun 06, 2013 10:04 pm, edited 1 time in total.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: My diary notes and learning

Post by SteveHopwood »

Please keep adding to this as you go - it is in the true spirit of our forum and will help others program for this platform.

Apart from, anything else, you always have a backup copy if you lose all your files in a disastrous event. :lol:

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: My diary notes and learning

Post by babalu4u »

Disadvantage for now is that you can use only current chart time frame and currency in Robots (robots can't trade multycurrency).... but in near future will support this options....
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: My diary notes and learning

Post by babalu4u »

Yes my intention is to write all but I am not good writer and also my english :oops: this will look more like notes and one day somebody can use notes to write better cAlgo for Dummies ...
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: My diary notes and learning

Post by babalu4u »

Called on each incoming Bar. This method is used by Robots. Izzy..

Code: Select all

        protected override void OnBar()
        {
            // Put your core logic here
        }

Now I will look to others Robots to find useful things and to learn ...
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: My diary notes and learning

Post by babalu4u »

I find one useful money management function and i will tray to use or adopt to my robot...

Code: Select all

        /// <summary>
        /// Volume calculated based on Risk if winning trade otherwise doubled
        /// </summary>
        protected int Volume
        {
            get
            {
                if (profit < 0)
                    // Profit < 0 => Double previous Volume or use MaxVolume
                    return (volume * 2) > MaxVolume ? MaxVolume : volume * 2;

                // profit > 0 => Calculate Volume based on Risk and Pip value
                var risk = (int)(RiskPercent * Account.Balance / 100);
                var volumeOnRisk = (int)(risk * Symbol.Ask / (Symbol.PipSize * StopLoss));
                // round volume to nearest tradable value
                return volumeOnRisk / VolumeIncreament * VolumeIncreament;
            }
        }

        /// <summary>
        /// Max Allowed trade volume 
        /// </summary>
        protected int MaxVolume
        {
            get
            {
                // calculated based on equity and leverage 
                double maxVolume = Account.Equity * Leverage * 100 / 101;
                //round to the nearest tradable value                
                return (int)Math.Truncate(Math.Round(maxVolume) / VolumeIncreament) * VolumeIncreament;
            }
        }
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: My diary notes and learning

Post by Radar »

Hey Babalu4u,


I'm not real sure here, but the first section looks like martingaling against a floating loss...

Code: Select all

                if (profit < 0)
                    // Profit < 0 => Double previous Volume or use MaxVolume
                    return (volume * 2) > MaxVolume ? MaxVolume : volume * 2;

Not a nice toy to play with. Might be better to get rid of that bit.

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: My diary notes and learning

Post by babalu4u »

Radar wrote:Hey Babalu4u,


I'm not real sure here, but the first section looks like martingaling against a floating loss...

Code: Select all

                if (profit < 0)
                    // Profit < 0 => Double previous Volume or use MaxVolume
                    return (volume * 2) > MaxVolume ? MaxVolume : volume * 2;

Not a nice toy to play with. Might be better to get rid of that bit.

Have fun!

Radar =8^)
Hi Radar yes I know, this is only copy paste from one martingale sample robot. I will use only part of that code... ;)
Post Reply

Return to “General discussion”