Replies

Jonkey
16 Nov 2019, 03:32

RE: RE:

jani said:

Panagiotis Charalampous said:

Hi irmscher,

Yes you can specify market range in the ExecuteMarketOrder function.

Best Regards,

Panagiotis

Hello,

 

can you please give some examples of ::

 double basePrice

in   ExecuteMarketRangeOrder?


/* public TradeResult ExecuteMarketRangeOrder(TradeType tradeType, string symbolName, double volume, double marketRangePips, double basePrice, string label, double? stopLossPips, double? takeProfitPips, string comment, bool hasTrailingStop, StopTriggerMethod? stopLossTriggerMethod) */

ExecuteMarketRangeOrder(TradeType.Buy, Symbol, 5000, 3, Symbol.Ask, "myRobot", 20, 40, "this is a comment");

 


@Jonkey

Jonkey
28 Apr 2019, 12:39

RE:

Panagiotis Charalampous said:

Hi jonkey,

Try this approach and let me know if it works for you

            var source = MarketData.GetSeries(TimeFrame.Daily);
            sma = Indicators.SimpleMovingAverage(source.Close, smaPeriod);

Best Regards,

Panagiotis

Thanks for the response Panagiotis, but still no luck... It made sense when I read your code but the dataseries must initialise in the same way...

So I think the problem is the dataseries needs to be populated with more past data to correctly calculate for sma.Result.Last(1) and sma.Result.LastValue with a large period... kind of like turbo lag on a car that takes time to spool up...

Worst case could this be achieved with a custom SMA indicatior or would they initialise the same way?

All the different time frames have access to different amounts of data also when initialising... for example H1 has access to the past 125 entries and D1 has access to past 75 entries... that is just from my testing anyway.

Thanks heaps for your help with this.


@Jonkey

Jonkey
24 Apr 2019, 23:54

A more specific question I should have asked is:

Is there anyway I can see if the 200 Day SMA is rising or falling inside a cbot from the moment I start it?

Cheers.


@Jonkey

Jonkey
24 Apr 2019, 08:54

https://ctrader.com/forum/cbot-support/1573

The code you need is in here. But coupling it into your code is the fun bit (friendly sarcasm)... It's just a time thing... that I don't have right now to do it for you... and even then it might be buggy... and id have to spend time debugging it ... hope this helps but im sorry I can't be of more help.

Coding is a source, it will change your life... swear to God. : )

 

 


@Jonkey

Jonkey
24 Apr 2019, 06:33

RE:

Panagiotis Charalampous said:

Hi Jonkey,

Disconnections and reconnections can happen from time to time for several reasons e.g. connectivity issues. Is the issue with the VPS permanent or does it reconnect after a while?

Best Regards,

Panagiotis

The full events were... just for thoroughness.

1. Bought new vps .

2. download and install cTrader on vps and open but not log in

3. Update windows and restart vps.

4. Change windows admin password.

4. open ctrader and login... wasted so much time making sure overly secure password is correct that I couldn't remember if i checked "Rememeber me" at login

5. Close ctrader and re open to test if "Rememeber me" was checked...

6. Met with "Reconnecting to your trading a/c..." for 4-5 hours in top right before taking action...

7. Took action mentioned above...

 


@Jonkey

Jonkey
24 Apr 2019, 06:27

RE:

Panagiotis Charalampous said:

Hi Jonkey,

Disconnections and reconnections can happen from time to time for several reasons e.g. connectivity issues. Is the issue with the VPS permanent or does it reconnect after a while?

Best Regards,

Panagiotis

Yes semi pernanent... 

Like it stayed there until I manually clicked the live acount after about 4-5 hours... but when I clicked it it did work with out entering credentials so I did press the "remember me" checkbox.


@Jonkey

Jonkey
23 Apr 2019, 10:40

RE:

Panagiotis Charalampous said:

Hi Jonkey,

During weekends we have maintenance tasks running therefore servers might be shut down. This is why you cannot backtest on some occasions.

Best Regards,
Panagiotis

 

Hey sorry, Just one more question... It is happening on my VPS instance (EU located) and not at home (AUS) right now? Any ideas?

Both are IC Markets 3.3, At home I can open a new 2nd session no worries I didnt close the first session at home in case I lost it...

Cheers.


@Jonkey

Jonkey
22 Apr 2019, 14:20

Thanks Panagiotis, I will chill now that I know. 


@Jonkey

Jonkey
22 Apr 2019, 03:45

It looks like the bot has taken a hedged position. And then closed a portion of the winning position...then the bot time frame ended without actually closing another trade... this is why the yellow line stays horizontal from 1 to 2... but the price action has shifted in a way that  raises the high and low equity values but the mid equity balance average of long vs short volumes has shifted in a way that forces it off center between the high and low equity values. That is why I believe the equity could be -7... but I could be wrong as I can't see all the trades and I'm not quite smart enough to do the real time conversions between AUD and EUR and GBP... But I believe this can skew expected results of hedging strategies also. Welcome to the joys of zero sum games : D!


@Jonkey

Jonkey
29 Oct 2018, 12:11

using System;
using System.Linq;
using System.Collections.Generic;
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 MyRobot: Robot
    {
        [Parameter("Vol Qty", DefaultValue = 10000, MinValue = 1000, Step = 1000)]
        public int volQty { get; set; }

        private string currentName;

        // ########################################################################################################### ON START ##########
        protected override void OnStart()
        {
            if (CoolClass.instances != null)
            {
                CoolClass.instances.Clear();
            }

	        for (int i = 0; i < 10; i++)
	        {
		        string name = string.format("name{0}", i.toString());
            	CoolClass.Initializer(i, name);
	        }
        }

        protected override void OnTick()
        {
            // uses static dictionary in CoolClass to juggle stuff around
            currentName = "name5"
            if (CoolClass.instances[currentName].myName != "name5") {
                Stop();
            }
        }

        // ############################################################################################################ ON STOP ##########
        protected override void OnStop()
        {
            foreach (var position in Positions)
            {
                if (Symbol.Code == position.SymbolCode)
                {
                    ClosePosition(position);
                }
            }
        }
    }

    // ###################################################################################################################################
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< CUSTOM CLASS >>>>>>>>>>
    // ###################################################################################################################################

    public class CoolClass
    {

        public static Dictionary<string, CoolClass> instances;
        public int myNumber;

        private string myName;
        private bool isInitialized;

        // ######################################################################################################## CONSTRUCTOR ##########
        private CoolClass()
        {
            isInitialized = false;
        }

        // ################################################################################################### CONFIRM INSTANCE ##########
        private static bool ConfirmInstance(string name)
        {
            if (instances == null)
            {
                instances = new Dictionary<string, CoolClass>();
            }
            if (!instances.ContainsKey(name))
            {
                instances.Add(name, new CoolClass());
            }
            return true;
        }

        // ######################################################################################################## INITIALISER ##########
        public static void Initializer(int number,  string name)
        {
            if (ConfirmInstance(name))
            {
                if (!instances[name].isInitialized)
                {
                    instances[name].myNumber = number;
                    
                    instances[name].myName = name;
                  
                    instances[name].isInitialized = true;
                }
            }
        }

	public static void SomeMethod()
        {
            //Do something
        }
    }
}

Would anyone mind considering this example code and following questions? In particular the static dictionary "instances" in the custom class... I am pretty sure it will not conflict across my instances... but any clarification will help...

Hallucination 1. (True or False or explain) The static Dictionary "instances" in MyRobot running on EURUSD may conflict with a MyRobot running on AUDUSD as they both share memory for CoolClass.instances? (as Dictionary Keys of the same name may write over each others values possibly?)

Hallucination 2. (True or False or explain) Duplicated robots named MyRobot_EURUSD to run on EURUSD and MyRobot_AUDUSD to run on AUDUSD will not conflict with each other as they are compiled to separate executables and each of their Dictionary's hold their own space in memory?

Thank you in advance. (Note: if there are syntactical and logic errors in the example code, no need to point them out... i would just like to understand more about the behaviour in memory of the static dictionary)

 


@Jonkey

Jonkey
26 Sep 2018, 14:33

RE:

Panagiotis Charalampous said:

Hi Jonkey,

The method needs to be called inside the cBot attached on the chart. Could you please explain us what are you trying to do? Maybe we can suggest something different.

Best Regards,

Panagiotis

I just needed a better way to manage the context of many sets of compound trades? I was thin ing maybe a struct, that then fed data like average position.EntryPrice back to main algo?

Thank you Panagiotis.


@Jonkey

Jonkey
26 Sep 2018, 14:26

RE:

Jonkey said:

This sorta happened to me when I first set up my vps. It may be a different thing but make sure when you log into cTrader on the vps "remember me" is selected at login so it stays logged in. Otherwise when you are not watching it logs you out and your cBot stops...

Sorry forget that different problem...


@Jonkey

Jonkey
26 Sep 2018, 14:23

This sorta happened to me when I first set up my vps. It may be a different thing but make sure when you log into cTrader on the vps "remember me" is selected at login so it stays logged in. Otherwise when you are not watching it logs you out and your cBot stops...


@Jonkey

Jonkey
26 Sep 2018, 14:07

Hope this helps, its a good starting point for that sort of a robot...

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        // ######################################################################################################## PARAMETERS ##########
        [Parameter("Vol as %", DefaultValue = false)]
        public bool volPercentBool { get; set; }

        [Parameter("Vol %", DefaultValue = 1, MinValue = 1, Step = 1)]
        public int volPercent { get; set; }

        [Parameter("Vol Qty", DefaultValue = 50000, MinValue = 1000, Step = 1000)]
        public int volQty { get; set; }

        [Parameter("StopLoss Pips", DefaultValue = 10.0, Step = 0.1)]
        public double slPips { get; set; }

        [Parameter("Allowable Slippage", DefaultValue = 0.5, MinValue = 0.5, Step = 0.1)]
        public double marketRangePips { get; set; }

        // ########################################################################################################### VARIABLES ##########

        private int volume;

        // ################################################################################################## CALCULATE VOLUME ##########
        private int CalculateVolume(double stopLossPips)
        {

            int result;
            switch (volPercentBool)
            {
                case true:
                    double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;
                    double posSizeForRisk = (Account.Balance * volPercent / 100) / (stopLossPips * costPerPip);
                    double posSizeToVol = (Math.Round(posSizeForRisk, 2) * 100000);
                    Print("costperppip = {0}, posSizeFoprRisk = {1}, posSizeLotsToVol = {2}", costPerPip, posSizeForRisk, posSizeToVol);
                    result = (int)Symbol.NormalizeVolumeInUnits(posSizeToVol, RoundingMode.ToNearest);
                    result = result > 150000 ? 150000 : result;
                    Print("{0}% of Account Balance used for Volume! Volume equals {1}", volPercent, result);
                    break;
                default:
                    result = volQty;
                    Print("Volume Quantity Used! Volume equals {0}", result);
                    break;
            }
            return result;
        }

        // ########################################################################################################### ON START ##########
        protected override void OnStart()
        {
            // Put your initialization logic here
            volume = CalculateVolume(slPips);
        }

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

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

 


@Jonkey