EntryPrice Position

11 Jun 2019, 09:24EntryPrice Position#11
Panagiotis Charalampousposts: 2868since: 13 Jan 2017

Hi diegorcirelli,

What is not working?

Best Regards,

Panagiotis


Head of Community Management at cTrader
11 Jun 2019, 13:18#12
diegorcirelliposts: 22since: 03 Jun 2019
Good Morning...
I would like you to return the position with the biggest entryprice.
Example
I have positions
1010
1005
1000
I would like you to return the 1010

 

        private double FindHighestPositionPrice(TradeType tradeType)
        {
            double highestPriceBuy = 0;
 
            foreach (var position in Positions)
            {
                if (position.Label == Label && position.SymbolCode == Symbol.Code)
                {
                    if (position.TradeType == tradeType)
                    {
                        if (highestPriceBuy == 0)
                        {
                            highestPriceBuy = position.EntryPrice;
                            continue;
                        }
                        if (position.EntryPrice > highestPriceBuy)
                            highestPriceBuy = position.EntryPrice;
                    }
                }
            }
 
            return highestPriceBuy;
        }

 

12 Jun 2019, 01:24#13
diegorcirelliposts: 22since: 03 Jun 2019
Good evening ... now a little developed this code, but also did not work, could you help me ??

 

        protected override void OnTick()
        {
            var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice);
            if (highestPriceBuy + Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

 

12 Jun 2019, 10:26RE:#14
Panagiotis Charalampousposts: 2868since: 13 Jan 2017

diegorcirelli said:

Good evening ... now a little developed this code, but also did not work, could you help me ??

 

        protected override void OnTick()
        {
            var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice);
            if (highestPriceBuy + Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

 

Hi diegorcirelli,

I do not see any problem in this code. Can you please explain to us why you think it is not working? What do you expect it to do and what does it do instead?

Best Regards,

Panagiotis


Head of Community Management at cTrader
12 Jun 2019, 14:32#15
diegorcirelliposts: 22since: 03 Jun 2019

Good morning then...
It is not running ... the idea is that when symbol.bid is "x" pips above the largest existing position, it executes the order ...

Example:

Existing positions
1010
1005
1000

Using 5 pips, when the highest position (which is 1010) added to the pips (which is 5) is less than or equal to symbol.bid, it should run.

But it is not running, it does nothing.

12 Jun 2019, 14:36#16
Panagiotis Charalampousposts: 2868since: 13 Jan 2017

Hi diegorcirelli,

Can you provide enough information to reproduce what you are seeing? We need

  • The full cBot code
  • Backtesting parameters
  • Date and time where you would expect the trade to happed but does not.

Best Regards,

Panagiotis

 


Head of Community Management at cTrader
12 Jun 2019, 14:47#17
diegorcirelliposts: 22since: 03 Jun 2019
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 MeuMesmo : Robot
    {
        [Parameter("Volume", DefaultValue = 1)]
        public double Vol { get; set; }

        [Parameter("StopLoss", DefaultValue = 1000)]
        public double SL { get; set; }

        [Parameter("TakeProfit", DefaultValue = 100)]
        public double TP { get; set; }

        [Parameter("Distância", DefaultValue = 100)]
        public double Pips { get; set; }

        private readonly string Label = "MeuMesmo";

        protected override void OnStart()
        {
            
        }

        protected override void OnTick()
        {
            var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice);
            if (highestPriceBuy + Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
            var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice);
            if (lowestPriceBuy - Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

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

12 Jun 2019, 15:00#18
Panagiotis Charalampousposts: 2868since: 13 Jan 2017

Ηι diegorcirelli,

If you run the cBot as is, it will not do anything as there are no open positions in the first place. When the cBot starts, from which position do you expect it to measure the distance since there is none open?

Best Regards,

Panagiotis


Head of Community Management at cTrader
12 Jun 2019, 15:07#19
diegorcirelliposts: 22since: 03 Jun 2019

I already did this test and also did not work, he buys several ...

 

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 MeuMesmo : Robot
    {
        [Parameter("Volume", DefaultValue = 1)]
        public double Vol { get; set; }

        [Parameter("StopLoss", DefaultValue = 1000)]
        public double SL { get; set; }

        [Parameter("TakeProfit", DefaultValue = 100)]
        public double TP { get; set; }

        [Parameter("Distância", DefaultValue = 100)]
        public double Pips { get; set; }

        private readonly string Label = "MeuMesmo";

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

        protected override void OnTick()
        {
            var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice);
            if (highestPriceBuy + Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
            var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice);
            if (lowestPriceBuy - Pips <= Symbol.Bid)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

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

12 Jun 2019, 15:16#20
Panagiotis Charalampousposts: 2868since: 13 Jan 2017

Hi diegorcirelli,

Here is an attempt to guess what you are trying to do

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 MeuMesmo : Robot
    {
        [Parameter("Volume", DefaultValue = 1)]
        public double Vol { get; set; }

        [Parameter("StopLoss", DefaultValue = 1000)]
        public double SL { get; set; }

        [Parameter("TakeProfit", DefaultValue = 100)]
        public double TP { get; set; }

        [Parameter("Distância", DefaultValue = 100)]
        public double Pips { get; set; }

        private readonly string Label = "MeuMesmo";

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
        }

        protected override void OnTick()
        {
            if (Positions.Count > 0)
            {
                var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice);
                if (highestPriceBuy + (Symbol.PipValue * Pips) <= Symbol.Bid)
                    ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
                var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice);
                if (lowestPriceBuy - (Symbol.PipValue * Pips) >= Symbol.Bid)
                    ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP);
            }
        }

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

Best Regards,

Panagiotis


Head of Community Management at cTrader