Topics
14 Aug 2023, 16:53
 287
 0
Replies

nafewhossain03
28 Apr 2024, 22:48

RE: RE: RE: RE: RE: RE: RE: data isn't read correctly?

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code and information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

using cAlgo.API;using System.Threading;namespace cAlgo{    [Robot(AccessRights = AccessRights.None)]    public class SinglePositionBot : Robot    {        private double StopLossPips = 10;        private double TakeProfitPips = 20;        private TradeType _lastTradeType;        private double _lastVolume;        private int _doubleCount;        protected override void OnStart()        {            if (SymbolName == "EURUSD")            {                StopLossPips = 10;                TakeProfitPips = 20;            }            else if (SymbolName == "GBPUSD")            {                StopLossPips = 13.5;                TakeProfitPips = 27;            }            else if (SymbolName == "USDJPY")            {                StopLossPips = 11;                TakeProfitPips = 22;            }            else if (SymbolName == "USDCHF")            {                StopLossPips = 15;                TakeProfitPips = 30;            }                                    _lastTradeType = TradeType.Buy;            _lastVolume = 1000;                        Positions.Opened += OnPositionOpened;                       ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                    }        protected override void OnTick()        {            if (Positions.Find("SinglePositionBot", SymbolName) == null && Symbol.Spread == 0)            {                if (LastResult.Position.GrossProfit > 0)                {                    _lastVolume = 1000;                    _lastTradeType = LastResult.Position.TradeType;                    _doubleCount = 0;                }                else if ( LastResult.Position.GrossProfit < 0)                {                    VolAmount();                    _lastTradeType = LastResult.Position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;                }                ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                            }        }                        private void OnPositionOpened(PositionOpenedEventArgs args)        {            if (args.Position.StopLoss == null && LastResult.Position.SymbolName == SymbolName)            {                ClosePosition(LastResult.Position);            }        }                private double VolAmount()        {            _lastVolume = LastResult.Position.VolumeInUnits * 2;            _doubleCount++;            if (_doubleCount >= 12)            {                _lastVolume = 1000;                _doubleCount = 0;            }                        return _lastVolume;        }            }}

Hi there,

We still need information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

the symbols are eurusd, gbpusd starting from 7/11/2022 utc+2 5min timeframe.
on eurousd the 161st trade

on gbpusd the 3247th and 3311th trade

 

Trade 161 looks correct to me

mine is like this

could it be that you have different data? i'm using fusion market as broker, 22.5 per million as commission or 2.25 per lot, 4.5 roundturn

Hi there,

The problem in your logic is here

                if (LastResult.Position.GrossProfit > 0)                {                    _lastVolume = 1000;                    _lastTradeType = LastResult.Position.TradeType;                    _doubleCount = 0;                }                else if ( LastResult.Position.GrossProfit < 0)                {                    VolAmount();                    _lastTradeType = LastResult.Position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;                }

You are determining the size of the next trade based on an open position's profit, which changes on each tick. You should check historical trades using the History collection instead.

Best regards,

Panagiotis

ok thanks, have a great day


@nafewhossain03

nafewhossain03
27 Apr 2024, 21:19 ( Updated at: 27 Apr 2024, 21:27 )

RE: RE: RE: RE: RE: data isn't read correctly?

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code and information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

using cAlgo.API;using System.Threading;namespace cAlgo{    [Robot(AccessRights = AccessRights.None)]    public class SinglePositionBot : Robot    {        private double StopLossPips = 10;        private double TakeProfitPips = 20;        private TradeType _lastTradeType;        private double _lastVolume;        private int _doubleCount;        protected override void OnStart()        {            if (SymbolName == "EURUSD")            {                StopLossPips = 10;                TakeProfitPips = 20;            }            else if (SymbolName == "GBPUSD")            {                StopLossPips = 13.5;                TakeProfitPips = 27;            }            else if (SymbolName == "USDJPY")            {                StopLossPips = 11;                TakeProfitPips = 22;            }            else if (SymbolName == "USDCHF")            {                StopLossPips = 15;                TakeProfitPips = 30;            }                                    _lastTradeType = TradeType.Buy;            _lastVolume = 1000;                        Positions.Opened += OnPositionOpened;                       ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                    }        protected override void OnTick()        {            if (Positions.Find("SinglePositionBot", SymbolName) == null && Symbol.Spread == 0)            {                if (LastResult.Position.GrossProfit > 0)                {                    _lastVolume = 1000;                    _lastTradeType = LastResult.Position.TradeType;                    _doubleCount = 0;                }                else if ( LastResult.Position.GrossProfit < 0)                {                    VolAmount();                    _lastTradeType = LastResult.Position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;                }                ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                            }        }                        private void OnPositionOpened(PositionOpenedEventArgs args)        {            if (args.Position.StopLoss == null && LastResult.Position.SymbolName == SymbolName)            {                ClosePosition(LastResult.Position);            }        }                private double VolAmount()        {            _lastVolume = LastResult.Position.VolumeInUnits * 2;            _doubleCount++;            if (_doubleCount >= 12)            {                _lastVolume = 1000;                _doubleCount = 0;            }                        return _lastVolume;        }            }}

Hi there,

We still need information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

the symbols are eurusd, gbpusd starting from 7/11/2022 utc+2 5min timeframe.
on eurousd the 161st trade

on gbpusd the 3247th and 3311th trade

 

Trade 161 looks correct to me

mine is like this

could it be that you have different data? i'm using fusion market as broker, 22.5 per million as commission or 2.25 per lot, 4.5 roundturn


@nafewhossain03

nafewhossain03
25 Apr 2024, 16:40 ( Updated at: 25 Apr 2024, 17:06 )

RE: RE: RE: data isn't read correctly?

PanagiotisCharalampous said: 

nafewhossain03 said: 

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code and information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

using cAlgo.API;using System.Threading;namespace cAlgo{    [Robot(AccessRights = AccessRights.None)]    public class SinglePositionBot : Robot    {        private double StopLossPips = 10;        private double TakeProfitPips = 20;        private TradeType _lastTradeType;        private double _lastVolume;        private int _doubleCount;        protected override void OnStart()        {            if (SymbolName == "EURUSD")            {                StopLossPips = 10;                TakeProfitPips = 20;            }            else if (SymbolName == "GBPUSD")            {                StopLossPips = 13.5;                TakeProfitPips = 27;            }            else if (SymbolName == "USDJPY")            {                StopLossPips = 11;                TakeProfitPips = 22;            }            else if (SymbolName == "USDCHF")            {                StopLossPips = 15;                TakeProfitPips = 30;            }                                    _lastTradeType = TradeType.Buy;            _lastVolume = 1000;                        Positions.Opened += OnPositionOpened;                       ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                    }        protected override void OnTick()        {            if (Positions.Find("SinglePositionBot", SymbolName) == null && Symbol.Spread == 0)            {                if (LastResult.Position.GrossProfit > 0)                {                    _lastVolume = 1000;                    _lastTradeType = LastResult.Position.TradeType;                    _doubleCount = 0;                }                else if ( LastResult.Position.GrossProfit < 0)                {                    VolAmount();                    _lastTradeType = LastResult.Position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;                }                ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);                            }        }                        private void OnPositionOpened(PositionOpenedEventArgs args)        {            if (args.Position.StopLoss == null && LastResult.Position.SymbolName == SymbolName)            {                ClosePosition(LastResult.Position);            }        }                private double VolAmount()        {            _lastVolume = LastResult.Position.VolumeInUnits * 2;            _doubleCount++;            if (_doubleCount >= 12)            {                _lastVolume = 1000;                _doubleCount = 0;            }                        return _lastVolume;        }            }}

Hi there,

We still need information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

the symbols are eurusd, gbpusd starting from 7/11/2022 utc+2 5min timeframe.
on eurousd the 161st trade

on gbpusd the 3247th and 3311th trade

 


@nafewhossain03

nafewhossain03
24 Apr 2024, 16:25

RE: data isn't read correctly?
PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code and information on how to reproduce this (Symbol, timeframe, dates) so that we can advise.

Best regards,

Panagiotis

using cAlgo.API;
using System.Threading;

namespace cAlgo
{
    [Robot(AccessRights = AccessRights.None)]
    public class SinglePositionBot : Robot
    {
        private double StopLossPips = 10;
        private double TakeProfitPips = 20;

        private TradeType _lastTradeType;
        private double _lastVolume;
        private int _doubleCount;

        protected override void OnStart()
        {
            if (SymbolName == "EURUSD")
            {
                StopLossPips = 10;
                TakeProfitPips = 20;
            }
            else if (SymbolName == "GBPUSD")
            {
                StopLossPips = 13.5;
                TakeProfitPips = 27;
            }
            else if (SymbolName == "USDJPY")
            {
                StopLossPips = 11;
                TakeProfitPips = 22;
            }
            else if (SymbolName == "USDCHF")
            {
                StopLossPips = 15;
                TakeProfitPips = 30;
            }
            
            
            _lastTradeType = TradeType.Buy;
            _lastVolume = 1000;
            
            Positions.Opened += OnPositionOpened;
           
            ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);
            
        }
        protected override void OnTick()
        {
            if (Positions.Find("SinglePositionBot", SymbolName) == null && Symbol.Spread == 0)
            {
                if (LastResult.Position.GrossProfit > 0)
                {
                    _lastVolume = 1000;
                    _lastTradeType = LastResult.Position.TradeType;
                    _doubleCount = 0;
                }
                else if ( LastResult.Position.GrossProfit < 0)
                {
                    VolAmount();
                    _lastTradeType = LastResult.Position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
                }
                ExecuteMarketOrder(_lastTradeType, SymbolName, _lastVolume, "SinglePositionBot", StopLossPips, TakeProfitPips);
                
            }
        }
        
        
        private void OnPositionOpened(PositionOpenedEventArgs args)
        {
            if (args.Position.StopLoss == null && LastResult.Position.SymbolName == SymbolName)
            {
                ClosePosition(LastResult.Position);
            }
        }
        
        private double VolAmount()
        {
            _lastVolume = LastResult.Position.VolumeInUnits * 2;
            _doubleCount++;

            if (_doubleCount >= 12)
            {
                _lastVolume = 1000;
                _doubleCount = 0;
            }
            
            return _lastVolume;
        }
        
    }
}

@nafewhossain03

nafewhossain03
21 Apr 2024, 22:15

RE: backtest chart freeze

PanagiotisCharalampous said: 

Hi there,

Your problem is here

while (Symbol.Spread != 0)    //the new part that i added is from here                {                    Thread.Sleep(1000);                }       

If you prevent the cBot from receiving new ticks, the spread will never change.

Best regards,

Panagiotis

i now understand, thank you very much

 


@nafewhossain03

nafewhossain03
20 Apr 2024, 18:27 ( Updated at: 20 Apr 2024, 18:33 )

RE: backtest chart freeze

PanagiotisCharalampous said: 

Hi there,

Your problem is here

while (Symbol.Spread != 0)    //the new part that i added is from here                {                    Thread.Sleep(1000);                }       

If you prevent the cBot from receiving new ticks, the spread will never change.

Best regards,

Panagiotis

the problem is the chart, it should not freeze. if i made any mistake in the code it should still continue the backtest with its errors, by the way it freezes even if i remove the backtesting chart view

oh and i also removed “&& symbol.spread == 0” from the else if line


@nafewhossain03