Obsolete x Code

Created at 26 Jul 2018, 15:40
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!
LA

lavio@gigalink.com.br

Joined 11.07.2017

Obsolete x Code
26 Jul 2018, 15:40


I get this error when running a backtest using version 3.0 (from ICMarkets or FxPro):

31/03/2011 21:00:10.000Crashed in OnTimer with TypeLoadException: Not possible to load type cAlgo.API.Color from assembly cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880.

The OnTimer() has:

        protected override void OnTimer()
        {
            if (IsBacktesting)
                return;
            API.Color cor;
            string s;

......

If I use "Colors cor;" when building it says it is obsolete, to use Color instead.

Using CTrader 3.01 beta it works fine.

Using CTrader 3.0 it builds fine, but does not run.

-0-0-0-0-0-0-

Version 3.01 runs the OnTimer event when backtasting and optimizing when it should not. And the optimization does not run at all.

-0-0-0-

Lavio

 


@lavio@gigalink.com.br
Replies

PanagiotisCharalampous
26 Jul 2018, 15:45

Hi Lavio,

Is it possible to have the full cBot code so that we can reproduce?

Best Regards,

Panagiotis


@PanagiotisCharalampous

lavio@gigalink.com.br
27 Jul 2018, 04:57

Hi Panagiotis,

Only in private. Can you tell me a email?

Lavio (lavio@gigalink.com.br)

 


@lavio@gigalink.com.br

PanagiotisCharalampous
27 Jul 2018, 09:54

Hi Lavio,

Please send it at community@spotware.com

Best Regards,

Panagiotis


@PanagiotisCharalampous

lavio@gigalink.com.br
31 Jul 2018, 00:31

/*
Roleta original (acaso ou alternador)
Turbo com prazo
*/
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
using System.Windows.Forms;
// referenciar System.Windows.Forms no .NET Framework
using System.Security.Permissions;
using System.Collections;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.ESouthAmericaStandardTime, AccessRights = AccessRights.FullAccess)]
    public class ROL : Robot
    {
        private string robi = "ROL";

        [Parameter("Alavanca proporcional?", DefaultValue = true)]
        public bool alavprop { get; set; }

        [Parameter("Acaso(1) ou Alternar(0)", DefaultValue = 0, MinValue = 0, MaxValue = 1)]
        public int acaso { get; set; }

        [Parameter("Trocar sinc erros>=X (0 não usa)\nSe acaso, não usa", DefaultValue = 3, MinValue = 0)]
        public int xacertos { get; set; }

        [Parameter("SG pips", DefaultValue = 100, MinValue = 1)]
        public double sgp { get; set; }

        [Parameter("SL = sg + DELTA pips", DefaultValue = 10)]
        public double slpdelta { get; set; }

        [Parameter("TSL ganhando 0=nao usar", DefaultValue = 0, MinValue = 0, Step = 1)]
        public double tstop { get; set; }

        [Parameter("Boost de volume > N (0 não usa)", DefaultValue = 3, MinValue = 0, MaxValue = 5)]
        public int boostvol { get; set; }

        [Parameter("Turbo...\n0:não\n1:alavancar\n2:anular", DefaultValue = 0, MinValue = 0, MaxValue = 2, Step = 1)]
        public int anular { get; set; }

        [Parameter("Max erros p/ turbo", DefaultValue = 3, MinValue = 1)]
        public int maxerr { get; set; }

        [Parameter("Max prazo p/ dividir turbo", DefaultValue = 1, MinValue = 1)]
        public int maxprazo { get; set; }

        [Parameter("Roda a cada N ticks", DefaultValue = 1, MinValue = 1, Step = 1)]
        public int NTICKS { get; set; }

        [Parameter("C (1), V (-1) ou ambos (0)", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = 1)]
        public int xcv { get; set; }

        [Parameter("Janelinha (1-9), 1=top left", DefaultValue = 5, MinValue = 1, MaxValue = 9)]
        public int jinha { get; set; }

        private Position _position = null;
        private int VolFixo = 1000;
        private int maxpos = 1;
        private double LUCRO = 0;
        private double pnl;
        private int ST1 = 0;
        private int ctot;
        private bool busy = false;
        private double capmax;
        // capital máximo a que chegou
        private double capini;
        private double caprobi;
        private int pulabar = 0;
        // contador acertos consecutivos
        private int csim = 0;
        // cont erros consecutivos
        private int cnao = 0;
        private int csimtot = 0;
        private int csimcount = 0;
        private int cticks;
        private int c10segs = 0;
        // contador do timer de 10 segs
        private int currbar;
        private double slp;
        private double sgpnovo;
        private int somador = 0;
        private int limsoma = 5;
        // limite dos contadores
        private int cacertos = 0;
        private double slip = 1;
        private int copsbar = 0;
        // contador de ops por barra
        private int xpulabar = 0;
        private int lastop = 0;
        private double alavanca = 1;

        protected override void OnStart()
        {
            robi = GetNomeRobi(robi, jinha);

            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;
            capini = Account.Balance;
            capmax = capini;
            caprobi = capmax;
            cticks = NTICKS;
            LerLucro();
            slp = sgp + slpdelta;
            sgpnovo = sgp;
            if (slp <= 0)
            {
                Stop();
                return;
            }
            if (alavprop)
                alavanca = 1.0;
            else
                alavanca = 0;
            cprazo = maxprazo;
            Timer.Start(10);
        }

        // evento
        protected override void OnStop()
        {
            Timer.Stop();
            Print("STOPing...");
            foreach (var pos in Positions.FindAll(robi, Symbol))
            {
                Print("POS {0} type: {1}, PNL: {2}", pos.Id, pos.TradeType, pos.GrossProfit);
                LUCRO = LUCRO + pos.NetProfit;
                ctot++;
                busy = true;
                ClosePosition(pos);
                busy = false;
            }
            CancelarPendentes();
            SalvarLucro();
        }

        /* versão 3.01 */
        protected override void OnTimer()
        {
            if (IsBacktesting)
                return;
            API.Color cor;
            string s;

            if (IsBacktesting)
                return;
            double x = 0;
            foreach (var pos in Positions.FindAll(robi))
                x = x + pos.NetProfit;

            pnl = CalcPNL(robi);

            if (maxpos == 1)
            {
                ST1 = GetPosition();
                s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nST1: " + ST1.ToString() + "\nOPS: " + ctot.ToString();
            }
            else
            {
                int cposC = ContarPosicoesBuy(robi);
                int cposV = ContarPosicoesSell(robi);
                s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nPOSC: " + cposC.ToString() + "\nPOSV: " + cposV.ToString() + "\nOPS: " + ctot.ToString();
            }

            if (LUCRO < 0)
                cor = Color.Red;
            else if (LUCRO > 0)
                cor = Color.Green;
            else
                cor = Color.Yellow;

            //ChartObjects.DrawText("lucro", s, GetJanelinha(jinha), cor);
            API.HorizontalAlignment h;
            API.VerticalAlignment v;
            GetJanelinha(jinha, out h, out v);
            Chart.DrawStaticText("lucro", s, v, h, cor);

            c10segs++;
            if (c10segs >= 360)
            {
                // 1 hs
                SalvarLucro();
                c10segs = 0;
            }
        }

        /* versão 3.0
        protected override void OnTimer()
        {
            Colors cor;
            string s;

            if (IsBacktesting)
                return;
            pnl = CalcPNL(robi);
            if (maxpos == 1)
            {
                ST1 = GetPosition();
                s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nST1: " + ST1.ToString() + "\nOPS: " + ctot.ToString();
            }
            else
            {
                int cposC = ContarPosicoesBuy(robi);
                int cposV = ContarPosicoesSell(robi);
                s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nPOSC: " + cposC.ToString() + "\nPOSV: " + cposV.ToString() + "\nOPS: " + ctot.ToString();
            }
            if (LUCRO < 0)
                cor = Colors.Red;
            else if (LUCRO > 0)
                cor = Colors.Green;
            else
                cor = Colors.Yellow;

            ChartObjects.DrawText("lucro", s, GetJanelinha(jinha), cor);
            //Chart.DrawStaticText();

            c10segs++;
            if (c10segs >= 360)
            {
                // 1 hs
                SalvarLucro();
                c10segs = 0;
            }
        }
        */
        protected override void OnTick()
        {
            cticks--;
            if (cticks > 0)
                return;
            cticks = NTICKS;
            if (pulabar > 0)
                return;

            // FECHAR
            pnl = CalcPNL(robi);

            if (tstop > 0)
                SetTrailingStop(tstop);
        }

        protected override void OnBar()
        {
            copsbar = 0;
            currbar = MarketSeries.Close.Count;

            if (pulabar > 0)
            {
                pulabar--;
                return;
            }

            int cpos = ContarPosicoes(robi);
            int cpend = ContarPendentes(robi);

            // ABRIR
            if (cpos + cpend < maxpos)
            {
                int cv = Selecionar();
                if (cv == 1 && xcv >= 0)
                {
                    BuyMarket(CalcVol(alavanca));
                    pulabar = xpulabar;
                }
                if (cv == -1 && xcv <= 0)
                {
                    SellMarket(CalcVol(alavanca));
                    pulabar = xpulabar;
                }
            }
        }

        private int lastsel = 0;
        private int Selecionar()
        {
            int x = 0;
            if (acaso == 1)
                x = MyRand(-1, 1);
            else
            {
                if (lastop == 0)
                {
                    x = 1;
                }
                else
                {
                    x = -lastop;
                    //if (cnao == 1) x = -x;
                    if (xacertos > 0 && cacertos <= -xacertos)
                    {
                        x = -x;
                        // ressincronizar
                        cacertos = 0;
                    }
                }
            }
            lastsel = x;
            return (x);
        }

        private Random random = new Random();
        private int MyRand(int n1, int n2)
        {
            return (random.Next(n1, n2 + 1));
        }

        // calcvol com prazo e corrigido para uso de TSL e de PNL de fechar geral com ganho
        private int cprazo;
        private double CalcVol(double alav)
        {
       ret = VolFixo;
                }
            }

            if (anular > 0 && ret > 10000)
                ret = 10000;
            d = slp * Symbol.PipValue * ret;
            // se for mais do que tem e pode perder, limitar...
            if (anular > 0)
            {
                // turbo
                if (d > 0.5 * caprobi)
                    ret = 0.5 * caprobi / (slp * Symbol.PipValue);
            }
            else
            {
                // não turbo
                if (d > 0.66 * caprobi)
                    ret = 0.66 * caprobi / (slp * Symbol.PipValue);
            }
            ret = Symbol.NormalizeVolumeInUnits(ret, RoundingMode.ToNearest);
            if (ret > Symbol.VolumeInUnitsMax)
                ret = Symbol.VolumeInUnitsMax;
            else if (ret < Symbol.VolumeInUnitsMin)
                ret = Symbol.VolumeInUnitsMin;

            return (ret);
        }

        private double TimeDifMins(DateTime t1, DateTime t2)
        {
            TimeSpan tsp;
            tsp = t2.Subtract(t1);
            return (tsp.TotalMinutes);
        }

        // diferença entre t2 - t1 em BARRAS (fração)
        private double TimeDifBarras(DateTime t1, DateTime t2)
        {
            TimeSpan tsp;
            tsp = t2.Subtract(t1);
            return (tsp.TotalMinutes / TimeFrameToMin());
        }

        // diferença entre t2 - t1 em DIAS
        private double TimeDifDias(DateTime t1, DateTime t2)
        {
            TimeSpan tsp;
            tsp = t2.Subtract(t1);
            return (tsp.TotalDays);
        }

        private void CancelarPendentes()
        {
            foreach (var order in PendingOrders)
            {
                if (order.Label == robi && order.SymbolCode == Symbol.Code)
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private int GetPosition()
        {
            int ret;
            _position = Positions.Find(robi, Symbol);
            if (_position != null)
            {
                if (_position.TradeType == TradeType.Buy)
                    ret = 1;
                else if (_position.TradeType == TradeType.Sell)
                    ret = -1;
                else
                    ret = ST1;
                // não muda
            }
            else
            {
                ret = 0;
            }
            return (ret);
        }

        // posições abertas
        private int ContarPosicoes(string label)
        {
            int c = 0;
            foreach (var position in Positions.FindAll(label, Symbol))
                c++;
            return (c);
        }

        private int ContarPosicoesBuy(string label)
        {
            int c = 0;
            foreach (var position in Positions.FindAll(label, Symbol, TradeType.Buy))
                c++;
            return (c);
        }

        private int ContarPosicoesSell(string label)
        {
            int c = 0;
            foreach (var position in Positions.FindAll(label, Symbol, TradeType.Sell))
                c++;
            return (c);
        }

        // qtos pendentes há?
        private int ContarPendentes(string label)
        {
            int c = 0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == label && order.SymbolCode == Symbol.Code)
                    c++;
            }
            return (c);
        }

        private double CalcDeriva(DataSeries ds, int off)
        {
            return ((ds.Last(off) - ds.Last(off + 1)) / Symbol.PipSize);
        }

        // segunda derivada
        private double CalcDeriva2Pips(DataSeries ds)
        {
            return (((ds.Last(0) - ds.Last(1)) - (ds.Last(1) - ds.Last(2))) / Symbol.PipSize);
        }

        private double CalcSL(int b, double frac)
        {
            double d = Functions.Maximum(MarketSeries.High, b) - Functions.Minimum(MarketSeries.Low, b);
            return (frac * PriceToPip(d));
        }

        private DateTime CalcExpira(int nbarras)
        {
            int x = nbarras * TimeFrameToMin();
            return (Server.Time.AddMinutes(x));
        }

        private TradeResult BuyMarket(double vol)
        {
            return (ExecuteMarketOrder(TradeType.Buy, Symbol, vol, robi, slp, sgp, slip));
        }

        private TradeResult SellMarket(double vol)
        {
            return (ExecuteMarketOrder(TradeType.Sell, Symbol, vol, robi, slp, sgp, slip));
        }

        private void BuyLimit(double vol, double d, double slp, double sgp, double expmin)
        {
            if (expmin > 0)
            {
                DateTime dt = Server.Time.AddMinutes(expmin);
                PlaceLimitOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp, dt);
            }
            else
                PlaceLimitOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp);
        }

        private void BuyStop(double vol, double d, double slp, double sgp, double expmin)
        {
            if (expmin > 0)
            {
                DateTime dt = Server.Time.AddMinutes(expmin);
                PlaceStopOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp, dt);
            }
            else
                PlaceStopOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp);
        }

        private void SellLimit(double vol, double d, double slp, double sgp, double expmin)
        {
            if (expmin > 0)
            {
                DateTime dt = Server.Time.AddMinutes(expmin);
                PlaceLimitOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp, dt);
            }
            else
                PlaceLimitOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp);
        }

        private void SellStop(double vol, double d, double slp, double sgp, double expmin)
        {
            if (expmin > 0)
            {
                DateTime dt = Server.Time.AddMinutes(expmin);
                PlaceStopOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp, dt);
            }
            else
                PlaceStopOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp);
        }

        private void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            if (args.Position.Label != robi || args.Position.SymbolCode != Symbol.Code)
                return;

            _position = args.Position;
            if (_position.TradeType == TradeType.Buy)
                ST1 = 1;
            else if (_position.TradeType == TradeType.Sell)
                ST1 = -1;
            copsbar++;
        }

        private void OnPositionsClosed(PositionClosedEventArgs obj)
        {
            if (obj.Position.Label != robi || obj.Position.SymbolCode != Symbol.Code)
                return;

            _position = null;
            ST1 = 0;
            if (!busy)
            {
                LUCRO = LUCRO + obj.Position.NetProfit;
                ctot++;
            }
            else
                busy = false;
            caprobi = caprobi + obj.Position.NetProfit;
            if (caprobi > capmax)
                capmax = caprobi;

            if (obj.Position.GrossProfit > 0)
            {
                csim++;
                cnao = 0;
                if (obj.Position.TradeType == TradeType.Buy)
                {
                    somador = somador + 1;
                    lastop = 1;
                }
                else if (obj.Position.TradeType == TradeType.Sell)
                {
                    somador = somador - 1;
                    lastop = -1;
                }
                cacertos++;
            }
            else if (obj.Position.GrossProfit < 0)
            {
                cnao++;
                // acumula csim máx atingido
                csimtot = csimtot + csim;
                csimcount++;
                csim = 0;
                if (obj.Position.TradeType == TradeType.Buy)
                {
                    somador = somador - 1;
                    lastop = -1;
                }
                else if (obj.Position.TradeType == TradeType.Sell)
                {
                    somador = somador + 1;
                    lastop = 1;
                }
                cacertos--;
            }
            if (somador > limsoma)
                somador = limsoma;
            else if (somador < -limsoma)
                somador = -limsoma;
            if (cacertos > limsoma)
                cacertos = limsoma;
            else if (cacertos < -limsoma)
                cacertos = -limsoma;
        }

        // calc pnl com múltiplas posições abertas
        private double CalcPNL(string label)
        {
            double x = 0;
            foreach (var pos in Positions.FindAll(label, Symbol))
                x = x + pos.GrossProfit;
            return (x);
        }

        private void FecharTudo()
        {
            CancelarPendentes();
            FecharPosicoes(robi);
        }

        private void FecharPosicoes(string label)
        {
            foreach (var position in Positions.FindAll(label, Symbol))
                ClosePosition(position);
        }

        private double PriceToPip(double price)
        {

            return (price / Symbol.PipSize);
        }

        private double PipToPrice(double pips)
        {
            return (pips * Symbol.PipSize);
        }

        private double PipToGrana(double pips, double volu)
        {
            return (pips * Symbol.PipValue * volu);
        }

        private double PriceToGrana(double price, double volu)
        {
            return (Symbol.PipValue * volu * price / Symbol.PipSize);
        }

        private double GranaToPip(double grana, double volu)
        {
            return (grana / (volu * Symbol.PipValue));
        }

        private int MinToBarras(double min)
        {
            return ((int)Math.Round(min / TimeFrameToMin()));
        }

        private double MyMax(DataSeries ds, int per, int off)
        {
            double xmax, d;
            xmax = 0;
            for (int i = 0; i < per; i++)
            {
                d = ds.Last(i + off);
                if (d > xmax)
                    xmax = d;
            }
            return (xmax);
        }

        private double MyMin(DataSeries ds, int per, int off)
        {
            double xmin, d;
            xmin = 99999;
            for (int i = 0; i < per; i++)
            {
                d = ds.Last(i + off);
                if (d < xmin)
                    xmin = d;
            }
            return (xmin);
        }

        /* BEGIN TRAIL STOP NOVO USANDO AUTOTS */
        private void SetTrailingStop(double xstop)
        {
            double newstop;

            foreach (var pos in Positions.FindAll(robi, Symbol))
            {
                if (pos == null)
                    continue;
                if (pos.HasTrailingStop)
                    continue;
                if (pos.Pips > xstop)
                {
                    // trocar SL para entryprice e ativar autots
                    newstop = pos.EntryPrice;
                    // price
                    sgpnovo = PriceToPip(xstop);
                    ModifyPosition(pos, newstop, pos.TakeProfit, true, StopTriggerMethod.Trade);
                }
            }
        }
        /* END TRAIL STOP */

        private int TimeFrameToMin()
        {
            int ret;
            TimeFrame tf = MarketSeries.TimeFrame;

            if (tf == TimeFrame.Minute)
                ret = 1;
            else if (tf == TimeFrame.Minute2)
                ret = 2;
            else if (tf == TimeFrame.Minute3)
                ret = 3;
            else if (tf == TimeFrame.Minute4)
                ret = 4;
            else if (tf == TimeFrame.Minute5)
                ret = 5;
            else if (tf == TimeFrame.Minute6)
                ret = 6;
            else if (tf == TimeFrame.Minute7)
                ret = 7;
            else if (tf == TimeFrame.Minute8)
                ret = 8;
            else if (tf == TimeFrame.Minute9)
                ret = 9;
            else if (tf == TimeFrame.Minute10)
                ret = 10;
            else if (tf == TimeFrame.Minute15)
                ret = 15;
            else if (tf == TimeFrame.Minute30)
                ret = 30;
            else if (tf == TimeFrame.Hour)
                ret = 60;
            else if (tf == TimeFrame.Hour2)
                ret = 120;
            else if (tf == TimeFrame.Hour3)
                ret = 180;
            else if (tf == TimeFrame.Hour4)
                ret = 240;
            else if (tf == TimeFrame.Hour6)
                ret = 360;
            else if (tf == TimeFrame.Hour8)
                ret = 480;
            else if (tf == TimeFrame.Hour12)
                ret = 720;
            else if (tf == TimeFrame.Daily)
                ret = 1440;
            else
                ret = 0;
            return (ret);
        }

        private TimeFrame MinToTimeFrame(int m)
        {
            TimeFrame tf;

            tf = TimeFrame.Minute;
            switch (m)
            {
                case 1:
                    tf = TimeFrame.Minute;
                    break;
                case 2:
                    tf = TimeFrame.Minute2;
                    break;
                case 3:
                    tf = TimeFrame.Minute3;
                    break;
                case 4:
                    tf = TimeFrame.Minute4;
                    break;
                case 5:
                    tf = TimeFrame.Minute5;
                    break;
                case 6:
                    tf = TimeFrame.Minute6;
                    break;
                case 7:
                    tf = TimeFrame.Minute7;
                    break;
                case 8:
                    tf = TimeFrame.Minute8;
                    break;
                case 9:
                    tf = TimeFrame.Minute9;
                    break;
                case 10:
                    tf = TimeFrame.Minute10;
                    break;
                case 15:
                    tf = TimeFrame.Minute15;
                    break;
                case 30:
                    tf = TimeFrame.Minute30;
                    break;
                case 60:
                    tf = TimeFrame.Hour;
                    break;
                case 120:
                    tf = TimeFrame.Hour2;
                    break;
                case 180:
                    tf = TimeFrame.Hour3;
                    break;
                case 240:
                    tf = TimeFrame.Hour4;
                    break;
                case 360:
                    tf = TimeFrame.Hour6;
                    break;
                case 480:
                    tf = TimeFrame.Hour8;
                    break;
                case 720:
                    tf = TimeFrame.Hour12;
                    break;
                case 1440:
                    tf = TimeFrame.Daily;
                    break;
            }
            return (tf);
        }

        /* versão 3.01 */
        private void GetJanelinha(int i, out API.HorizontalAlignment x, out API.VerticalAlignment y)
        {
            switch (i)
            {
                case 1:
                    x = API.HorizontalAlignment.Left;
                    y = API.VerticalAlignment.Top;
                    break;
                case 2:
                    x = API.HorizontalAlignment.Center;
                    y = API.VerticalAlignment.Top;
                    break;
                case 3:
                    x = API.HorizontalAlignment.Right;
                    y = API.VerticalAlignment.Top;
                    break;
                case 4:
                    x = API.HorizontalAlignment.Right;
                    y = API.VerticalAlignment.Center;
                    break;
                case 5:
                    x = API.HorizontalAlignment.Right;
                    y = API.VerticalAlignment.Bottom;
                    break;
                case 6:
                    x = API.HorizontalAlignment.Center;
                    y = API.VerticalAlignment.Bottom;
                    break;
                case 7:
                    x = API.HorizontalAlignment.Left;
                    y = API.VerticalAlignment.Bottom;
                    break;
                case 8:
                    x = API.HorizontalAlignment.Left;
                    y = API.VerticalAlignment.Center;
                    break;
                default:
                    x = API.HorizontalAlignment.Center;
                    y = API.VerticalAlignment.Center;
                    break;
            }
        }

        /* versão 3.0
        private StaticPosition GetJanelinha(int i)
        {
            StaticPosition ret;

            switch (i)
            {
                case 1:
                    ret = StaticPosition.TopLeft;
                    break;
                case 2:
                    ret = StaticPosition.TopCenter;
                    break;
                case 3:
                    ret = StaticPosition.TopRight;
                    break;
                case 4:
                    ret = StaticPosition.Right;
                    break;
                case 5:
                    ret = StaticPosition.BottomRight;
                    break;
                case 6:
                    ret = StaticPosition.BottomCenter;
                    break;
                case 7:
                    ret = StaticPosition.BottomLeft;
                    break;
                case 8:
                    ret = StaticPosition.Left;
                    break;
                default:
                    ret = StaticPosition.Center;
                    break;
            }
            return (ret);
        }
        */

        private string GetNomeRobi(string nome, int j)
        {
            return (nome + "-" + Symbol.Code + "-J" + j.ToString() + "-M" + TimeFrameToMin().ToString());
        }

        private string[] Explode(string s, char[] carr)
        {
            if (carr == null)
                carr = new char[] 
                {
                    ';',
                    ','
                };
            string[] x = s.Split(carr);
            return (x);
        }

        // BEGIN FILE IO
        string mypath = "C:\\CTRADER\\";
        public bool SalvarLucro()
        {
            bool ret = true;
            if (!IsBacktesting)
            {
                ret = SalvarTxt(mypath + robi + "-LUCRO.txt", LUCRO.ToString("0.00") + ";" + ctot.ToString());
            }
            return (ret);
        }

        public double LerLucro()
        {
            double d = 0;
            string s;
            string[] sarr;

            if (!IsBacktesting)
            {
                s = FileReadTxt(mypath + robi + "-LUCRO.txt");
                if (s != null)
                {
                    sarr = Explode(s, null);
                    if (sarr != null)
                    {
                        LUCRO = double.Parse(sarr[0]);
                        ctot = int.Parse(sarr[1]);
                    }
                }
                else
                {
                    LUCRO = 0;
                    ctot = 0;
                }
            }
            return (d);
        }

        public bool SalvarTxt(string arq, string s)
        {
            try
            {
                File.WriteAllText(arq, s);
                return (true);
            } catch (IOException ex)
            {
                Print("ERRO: " + ex.ToString());
                //MessageBox.Show(ex.ToString());
                return (false);
            }
        }

        // retorna stringão com tudo
        public string FileReadTxt(string arq)
        {
            if (File.Exists(arq))
            {
                string s = File.ReadAllText(arq);
                return (s);
            }
            else
                return (null);
        }
        // END FILE IO        
    }

}


@lavio@gigalink.com.br

lavio@gigalink.com.br
31 Jul 2018, 00:46

The editor here did a mess when copying.

Put this on the CalcVol(x):

private double CalcVol(double alav) {

 return((double)VolFixo);

}

Just a dumb thing is fine. The calculation is not relevant to the issue.

 

It compiles on any CTrader without the warning stuff if you set the /* ... */ accordingly.

But only runs on the Spotware version 3.01.

In others, IC Markets and FxPro 3.0, it crahes the OnTimer(): Crashed in OnTimer with TypeLoadException: Not possible to load type cAlgo.API.Color from assembly cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880.

I also had problems in the " API.HorizontalAlignment" setting, because without the "API." (my kick) it says there are two conflicting versions of the  HorizontalAlignment property, one used by API and other by Windows. I guess there is a mess on such libraries, .NET, references ...


Lavio
 


@lavio@gigalink.com.br

PanagiotisCharalampous
31 Jul 2018, 09:34

Hi Lavio,

If you have installed Spotware cTrader Public Beta 3.01 then there might be a conlfict in the API libraries. API.Color is available only in 3.01.

Best Regards,

Panagiotis


@PanagiotisCharalampous

lavio@gigalink.com.br
31 Jul 2018, 15:39

Yes, but it builds succssefully (!?) using CTrader 3.0 (from ICM and FxPro).
 


@lavio@gigalink.com.br