icollocollo
icollocollo's avatar

Info

Username:icollocollo
Name:icollocollo
Member since: 26 Nov 2021

About

None

Signature

None

Last Algorithm Comments

@Choppiness Indicator - CHOP:  28 Apr 2022, 18:22


For the cbot, i can't seem to get the correct parameters under desired periods. 

Last Forum Posts

@Custom Fractal feeding bot no value:  13 May 2022, 16:16


amusleh said:

Hi,

We can only help you if you post a code sample that can reproduce this issue.

Please post the code for your cBot and the custom indicator you are using.

Updated Please check, really need these values. 

@Custom Fractal feeding bot no value:  12 May 2022, 23:32


This is my fractals indicator gets 4hr values

I am trying to get .last (1) and last (0) using the for loop below

Values needed is UpFractal 1 and 2

                            DownFractal 1 and 2

i have tried it prints last values but then repeats them. need to get last values at a particular time.

for (int i = i_fractal.UpFractal.Count; i > i_fractal.UpFractal.Count - 5; i--)
            {

                for (int j = i_fractal.DownFractal.Count; j > i_fractal.DownFractal.Count - 5; j--)
                {
                    if (i_fractal.DownFractal.Last(0) < i_fractal.DownFractal.Last(1) && FSeries.ClosePrices.Last(0) > i_fractal.DownFractal.Last(1) && FSeries.LowPrices.Last(0) < i_fractal.DownFractal.Last(1))
                    {
                        if (i_fractal.UpFractal.Last(0) < i_fractal.UpFractal.Last(1))
                        {
                            if (OneBearish)
                            {

                                Hdown = true;

                                break;
                            }
                        }

                    }

                }
            }

The indicator code is below

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, TimeZone = TimeZones.EAfricaStandardTime)]
    public class Spring : Indicator
    {


        [Output("Up Fractal", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpFractal { get; set; }

        [Output("Down Fractal", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownFractal { get; set; }


        private Bars HSeries;
        protected override void Initialize()
        {
            HSeries = MarketData.GetBars(TimeFrame.Hour4);
        }



        public override void Calculate(int index)
        {
            if (index == 1)
                return;

            DrawUpFractal(index);
            DrawDownFractal(index);



        }

        private void DrawUpFractal(int index)
        {

            int middleIndex = index - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];

            bool up = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex + 1])
                {
                    up = true;
                    break;
                }
            }
            if (up)
                UpFractal[middleIndex] = middleValue;
        }

        private void DrawDownFractal(int index)
        {

            int middleIndex = index - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];
            bool down = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex + 1])
                {
                    down = true;
                    break;
                }
            }
            if (down)
                DownFractal[middleIndex] = middleValue;

        }



    }
}

@Partial Volume close after 2RR not working:  26 Apr 2022, 12:00


amusleh said:

Hi,

You can store the partially closed position ID on a collection like a List and check if it's already partially closed or not.

Thanks amusleh for the reply, i have seen that list offers great way for doing that. Unfortunately am not really experienced with it. Do you have an example of an indicator or cbot that fully exploits linq that can be help in illustrating this?. Also need lists for a supply and demand indicator

@Positions - Partial Close event:  26 Apr 2022, 09:10


amusleh said:

icollocollo said:

ncel01 said:

amusleh,

That's clear. Thanks for the extra clarifications!

Is it possible to use this position modified in another Method? @amusleh

Hi,

What do you mean by using the position on another method?

I was looking for a way to stop my positions from bwing modified twice in a cbot but i realized this is and event so i think i will try to use an if logic to implement that. Thank you

@Positions - Partial Close event:  25 Apr 2022, 17:34


ncel01 said:

amusleh said:

Hi,

You can do something like this:

using cAlgo.API;
using System.Collections.Generic;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private Dictionary<int, double> _positionsVolume = new Dictionary<int, double>(100);

        protected override void OnStart()
        {
            foreach (var position in Positions)
            {
                _positionsVolume.Add(position.Id, position.VolumeInUnits);
            }

            Positions.Opened += Positions_Opened;
            Positions.Closed += Positions_Closed;
            Positions.Modified += Positions_Modified;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (_positionsVolume.ContainsKey(obj.Position.Id))
            {
                _positionsVolume.Remove(obj.Position.Id);
            }
        }

        private void Positions_Opened(PositionOpenedEventArgs obj)
        {
            _positionsVolume.Add(obj.Position.Id, obj.Position.VolumeInUnits);
        }

        private void Positions_Modified(PositionModifiedEventArgs obj)
        {
            if (_positionsVolume.ContainsKey(obj.Position.Id))
            {
                var positionPreviousVolume = _positionsVolume[obj.Position.Id];

                if (positionPreviousVolume == obj.Position.VolumeInUnits)
                {
                    // It means volume desn't changed
                }
                // volume changed
                else
                {
                    // new volume added
                    if (positionPreviousVolume < obj.Position.VolumeInUnits)
                    {
                        Print("Position {0} volume increased, new volume: {1} | previous volume: {2}", obj.Position.Id, obj.Position.VolumeInUnits, positionPreviousVolume);
                    }
                    // position partially closed
                    else
                    {
                        Print("Position {0} partially closed, new volume: {1} | previous volume: {2}", obj.Position.Id, obj.Position.VolumeInUnits, positionPreviousVolume);
                    }
                }

                _positionsVolume[obj.Position.Id] = obj.Position.VolumeInUnits;
            }
            else
            {
                _positionsVolume.Add(obj.Position.Id, obj.Position.VolumeInUnits);
            }
        }
    }
}

amusleh,

That's clear. Thanks for the extra clarifications!

Is it possible to use this position modified in another Method? @amusleh

@Partial volume close:  25 Apr 2022, 10:01


firemyst said:

Yes.

In your code set a boolean flag to indicate that you've done your modification on the position. For example, "alreadyModifiedPosition = true;"

Every time you go through your code, only enter into the part that does the position modification if the flag is set to false.

Eg:

if (!alreadyModifiedPosition)

{

   /// do your position modification

   alreadyModifiedPosition = true;

}

Then you just have to figure out the logic when you reset alreadyModifiedPosition back to false. Every time you start your bot? When the position is closed? Something else?

Good luck! :-)

Thank you for your reply. Please check this thread for the code. An example will be of help since i already use for each position in positions.

@Partial Volume close after 2RR not working:  25 Apr 2022, 01:37


icollocollo said:

amusleh said:

icollocollo said:

amusleh said:

Hi,

Can you provide more context and what you are after?

If you want to close a position when it reach 2 Risk:Reward, then you can use the Position Pips, if it's double the amount of stop loss in pips then close it.

You don't have to use volume to calculate it.

Reason i am trying to use Volume is because my SL varies from one to the other. And TP is a multiple of SL, say SL*5. Closing partials at SL * 2 and modifying the remaining to break even at +2 pips.

Hi,

It doesn't matter if your SLs varies or not, you can get each position current SL in pips, for example if your position current pips is 10 and your stop loss is 5 pips then it means your position is reached 2 RR, and you can close half of its volume, no need for calculating volume.

UPDATE! Got the code below working,,,

{
            var allPositions = Positions.FindAll(MyLabel, SymbolName);
            foreach (Position p in allPositions)
            {
                double entryPrice = p.EntryPrice;
                double distance = p.TradeType == TradeType.Buy ? (Symbol.Bid - entryPrice) / Symbol.PipSize : (entryPrice - Symbol.Ask) / Symbol.PipSize;
                double newVol = Symbol.NormalizeVolumeInUnits((p.VolumeInUnits / 2), RoundingMode.Up);
                var sl = p.TradeType == TradeType.Buy ? (entryPrice - p.StopLoss) / Symbol.PipSize : (p.StopLoss - entryPrice) / Symbol.PipSize;


                if (p.TradeType == TradeType.Buy)
                {
                    if (distance / sl == 2)
                    {
                        ModifyPosition(p, newVol);
                        Print("Partial closing " + newVol + " of " + p + "2RR Achieved!");
                    }

                }
                if (p.TradeType == TradeType.Sell)
                {
                    if (distance / sl == 2)
                    {
                        ModifyPosition(p, newVol);
                        Print("Partial closing " + newVol + " of " + p + "2RR Achieved!");
                    }

                }


                // Close trades without stoploss or takeprofit

                if (p.StopLoss == null || p.TakeProfit == null)
                {

                    ClosePosition(p);

                }
            }

        }

Hello @Amusleh here is a problem with this code. I want to prevent a position from being modified twice. Like the position after partials is closed. Should either hit SL or TP. But since price moves up and down when price distance is equal to 2 again. The same percentage of the remaining volume is calculated again. 

E.g 50 % of 1000 is 500. When condition is true again 50% of 500 = 250 is closed again then 125 then 62.5 theb 31.5 until tp or sl is hit. 

Please help

@Partial volume close:  25 Apr 2022, 01:31


Hello guys, is it possible to prevent a modified position not to be modified again? For example if the profit is equal to stop loss * 2 and i want to close partials. 

Problem is when price comes back to stoploss *2 it closes partials again instead of going to take profit as the remaining volume.

@Partial Volume close after 2RR not working:  20 Jan 2022, 16:31


amusleh said:

icollocollo said:

amusleh said:

Hi,

Can you provide more context and what you are after?

If you want to close a position when it reach 2 Risk:Reward, then you can use the Position Pips, if it's double the amount of stop loss in pips then close it.

You don't have to use volume to calculate it.

Reason i am trying to use Volume is because my SL varies from one to the other. And TP is a multiple of SL, say SL*5. Closing partials at SL * 2 and modifying the remaining to break even at +2 pips.

Hi,

It doesn't matter if your SLs varies or not, you can get each position current SL in pips, for example if your position current pips is 10 and your stop loss is 5 pips then it means your position is reached 2 RR, and you can close half of its volume, no need for calculating volume.

UPDATE! Got the code below working,,,

{
            var allPositions = Positions.FindAll(MyLabel, SymbolName);
            foreach (Position p in allPositions)
            {
                double entryPrice = p.EntryPrice;
                double distance = p.TradeType == TradeType.Buy ? (Symbol.Bid - entryPrice) / Symbol.PipSize : (entryPrice - Symbol.Ask) / Symbol.PipSize;
                double newVol = Symbol.NormalizeVolumeInUnits((p.VolumeInUnits / 2), RoundingMode.Up);
                var sl = p.TradeType == TradeType.Buy ? (entryPrice - p.StopLoss) / Symbol.PipSize : (p.StopLoss - entryPrice) / Symbol.PipSize;


                if (p.TradeType == TradeType.Buy)
                {
                    if (distance / sl == 2)
                    {
                        ModifyPosition(p, newVol);
                        Print("Partial closing " + newVol + " of " + p + "2RR Achieved!");
                    }

                }
                if (p.TradeType == TradeType.Sell)
                {
                    if (distance / sl == 2)
                    {
                        ModifyPosition(p, newVol);
                        Print("Partial closing " + newVol + " of " + p + "2RR Achieved!");
                    }

                }


                // Close trades without stoploss or takeprofit

                if (p.StopLoss == null || p.TakeProfit == null)
                {

                    ClosePosition(p);

                }
            }

        }

@Partial Volume close after 2RR not working:  20 Jan 2022, 09:02


amusleh said:

Hi,

Can you provide more context and what you are after?

If you want to close a position when it reach 2 Risk:Reward, then you can use the Position Pips, if it's double the amount of stop loss in pips then close it.

You don't have to use volume to calculate it.

Reason i am trying to use Volume is because my SL varies from one to the other. And TP is a multiple of SL, say SL*5. Closing partials at SL * 2 and modifying the remaining to break even at +2 pips.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.