Topics
Replies

MongolTrader
30 Aug 2024, 09:21

If you want i can code you this bot with piece of donation cost

If you want i can code you this bot with piece of donation cost. 


@MongolTrader

MongolTrader
31 May 2024, 05:59

RE: Trouble error when get average Pips of Positions Label where starts with some Prefix

PanagiotisCharalampous said: 

Hi there,

This is probably thrown because your Label is null. Always check if Label is not null before you use it.

Best regards,

Panagiotis

My bot always open position with label and also i see there positions with label. Also you can check above code section this code is check whether this position not null.


@MongolTrader

MongolTrader
31 May 2024, 04:20

RE: Position average price triggers

firemyst said: 

I think your logic in both loops is wrong because you're changing the average price every time you do the loop.

That is, look at #1. When you have 10 positions open and the averagePrice (in pips) is < -10, you modify one position.

Then you do another loop and calculate the average again. The average will change because you've already modified one position. 

Same with #2. The average will change each time when you close a position.

What you should do is calculate the average once with all the current positions, and then do you loop. This way, the average won't change on each loop iteration.

For example:

double averagePrice = Positions.Average(x => x.Pips);if (averagePrice > 11){        foreach (var position in Positions)        {                    ClosePositionAsync(position);         }}

Please tell me how to add filter when label starts with some prefix when i try use startswith function it gives error as like as below.

AveragePips = Positions.Where(x => x.Label.StartsWith(Name)).Average(y => y.Pips);

Error message is → | Crashed in OnBarClosed with NullReferenceException: Object reference not set to an instance of an object.

 


@MongolTrader

MongolTrader
12 Dec 2022, 09:40 ( Updated at: 12 Dec 2022, 09:41 )

RE:

Spotware said:

Dear trader,

Please share with us the exact error you are getting.

Best regards,

cTrader Team

Exact error is 

1. When build bot to dotnet 4.x version work fine.

1. Than build bot to dotnet 6.0 version it not work. /Build process done fine but not run/

 


@MongolTrader

MongolTrader
04 Nov 2022, 06:10

RE:

firemyst said:

Why do you need to check it in a while loop? What's your logic or what are you trying to accomplish?

I need to know continuously every tick or bar what was last overbought or oversold point.  


@MongolTrader

MongolTrader
04 Nov 2022, 06:02

RE:

pick said:

Like the user above, I'm unsure as to why you require it to be a while loop. 

There are many options for what it sounds like you're looking to achieve.

The second statement in a for loop is a boolean check, for example you could do something like this:

bool found = false;

for (int i = startIndex; !found; i--)
{
	if (stoch[i] > 95 || stoch[i] < 5)
		found = true;
}

 

Ideally, you should identify the bounds of the loop, but you can combine that check:

bool found = false;

for (int i = startIndex; i >= 0 && !found; i--)
{
	if (stoch[i] > 95 || stoch[i] < 5)
		found = true;
}

 

However, if you really do require it to be a while loop, here's a simple example:

bool found = false;
int i = startIndex;

while (!found)
{
	if (stoch[i] > 95 || stoch[i] < 5)
		found = true;
		
	i--;
}

Just be cautious to not get stuck in an infinite loop, or access invalid indices from collections.

May i know your telegram please. When condition goes true it only take value one time. And it resets value to 0 and not continiuosly gives last data value. 


@MongolTrader

MongolTrader
06 Sep 2022, 08:55

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

Use the below instead

 Positions.Where(p => p.SymbolName == EURUSD_Buy)

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

I mean find by EURUSD prefix not full name search. It means select all positions started with "eurusd" preifx


@MongolTrader

MongolTrader
12 Aug 2022, 13:45

RE: a possible reason

paolo.panicali said:

Hi Mongol, maybe this can help you, I just tell you what it seems to me and my personal opinion, not the Truth.

...that code recalls the EntryPrice of the oldest currently open position on any symbol.

A possible reason for the price not being "stable" can be that by the time you use that function the position is already closed so that you are picking the price of another position and maybe on another symbol ( the second oldest that now it is the oldest because the oldest had been closed so now it is in the History and not in Positions) , in that case you should call History instead of Positions and refer to the current symbol.

You may also want to specify the symbol name in order not to pick another symbol price, which also could be the cause.

For instance if you run a bot with this line of code on 3 symbols in three different instances or in the same instance, you will end up mixing up prices and will take the price of a symbol for another symbol.

Not only that, if the outcome of the line of code you show is null cause there are not open positions currently, you will get a null value or the bot will crash and forced to stop.

Bottom line, I personally always hard type or parametrize the symbol name to sort, find or close positions (otherwise I sort find or close positions of another instance or another bot, also remember to label correctly the positions you open, that is the easiest wat to pick an open trade) and if the price is unstable is most likely because the position you are trying to take the price had been closed or maybe you set a rolling time window which is excluding the first open position time.

Hope that help bye.

 

Tank you  very much. Very rich explanation for me. Best& Regards


@MongolTrader

MongolTrader
12 Aug 2022, 10:49

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

Please explain why do you think it doesn't work.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

I use this entry price for take profit of another position. But it not stable it moves i dont know why. 


@MongolTrader

MongolTrader
03 Aug 2022, 10:58

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

You can do the following

  1. Set the timer to a 1 second interval
  2. Add a counter for seconds and count on each interval
  3. Reset the counters every 60 seconds.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Please code me im not sure write this code. 


@MongolTrader

MongolTrader
02 Aug 2022, 10:31

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

Here is a starting point

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBot2 : Robot
    {

        private int _tickCounter;
        
        protected override void OnStart()
        {
            // To learn more about cTrader Automate visit our Help Center:
            // https://help.ctrader.com/ctrader-automate

            Timer.TimerTick += Timer_TimerTick;
            Timer.Start(60);
        }

        private void Timer_TimerTick()
        {
           _tickCounter = 0;
        }

        protected override void OnTick()
        {
            // Handle price updates here
            _tickCounter++;
            Print(_tickCounter);
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

Thank you very much. Could you tell me more how to sync with bar timer with this timer. Timer not accord bar timer.


@MongolTrader

MongolTrader
02 Aug 2022, 09:45

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

You can create a counter that counts how many times OnTick() has been invoked and reset it every minute. You can use the Timer for this.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

please help me sample code for tick counter 


@MongolTrader

MongolTrader
29 Jul 2022, 05:03 ( Updated at: 21 Dec 2023, 09:22 )

RE: Try this code, it works for me with timeframe set to 1 minute it updates every minute....

paolo.panicali said:

//Answer to MongolTrader since: 12 Feb 2015  28 Jul 2022, 09:53
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MongolTrader : Indicator
    {
        public override void Calculate(int index)
        {
            var src = Bars.OpenTimes[index];
            var line1 = Chart.DrawVerticalLine("1", src.AddMinutes(-1), Color.Red, 2, LineStyle.DotsRare);
            var line2 = Chart.DrawVerticalLine("2", src.AddMinutes(-2), Color.Blue, 2, LineStyle.DotsRare);
            var line3 = Chart.DrawVerticalLine("3", src.AddMinutes(-3), Color.Blue, 2, LineStyle.DotsRare);
            var line4 = Chart.DrawVerticalLine("4", src.AddMinutes(-4), Color.Blue, 2, LineStyle.DotsRare);
            var line5 = Chart.DrawVerticalLine("5", src.AddMinutes(-5), Color.Blue, 2, LineStyle.DotsRare);
            var line6 = Chart.DrawVerticalLine("6", src.AddMinutes(-6), Color.Blue, 2, LineStyle.DotsRare);
            var line7 = Chart.DrawVerticalLine("7", src.AddMinutes(-7), Color.Blue, 2, LineStyle.DotsRare);
        }
    }
}

 

Is that what you wanted? Bye

Thank you very much bro. May i have friend with telegram or any other social fb instagram etc... Let me know ID if ok


@MongolTrader

MongolTrader
29 Jul 2022, 04:56 ( Updated at: 21 Dec 2023, 09:22 )

RE: Minute bar separator on tick chart

paolo.panicali said:

 

//Answer #2 to MongolTrader since: 12 Feb 2015  28 Jul 2022, 09:53
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MongolTrader2 : Indicator
    {
        public override void Calculate(int index)
        {
            var srcPrev = Bars.OpenTimes[index - 1];
            var src = Bars.OpenTimes[index];


            if (srcPrev.Minute == src.AddMinutes(-1).Minute)
            {
                var line1 = Chart.DrawVerticalLine("Line" + index, src.AddMinutes(-1), Color.Red, 2, LineStyle.DotsRare);
            }

        }
    }
}

Thank you very much bro. May i have friend with telegram or any other social fb instagram etc... Let me know ID if ok


@MongolTrader

MongolTrader
06 Jul 2022, 14:39

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

You need to make your question more specific. What exactly do you need to find out? How to initialize the indicator using data from another timeframe?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

I ask before about like this question adx multitime frame its same as this question only using indicator is bollinger band i dont know how use it in bollinger band case please check link below https://ctrader.com/forum/calgo-support/38261


@MongolTrader

MongolTrader
29 Jun 2022, 09:35

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

What exact sample do you need?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

My bot work only find and identify positions by only name. So when i run it on two pair it will conflict each other such as close funtion will close all position whether is one pair or other pair so how can i use my bot without edit and use one account. 


@MongolTrader

MongolTrader
29 Jun 2022, 09:18

RE:

firemyst said:

//Quick example on how to sort positions by NetProfit (not gross profit)
//Change things around if you want to sort by time or something else.

foreach (Position p in Positions.FindAll(YourLabel, s.Name).OrderBy(x => x.NetProfit))
{
	ClosePositionAsync(p, (TradeResult r) =>
	{
		if (r.IsSuccessful)
		{
			Print("Closed position \"{0} {1}\".", p.Id, p.Label);
		}
		else if (!r.IsSuccessful)
		{
			Print("WARNING! Could not close position \"{0} {1}\"!", p.Id, p.Label);
			Print("Error message: {0}", r.Error.Value);
		}
	});
}

 

Thank you very much. It delete from low profit to high. Can you provide code delete from high profit to low. 


@MongolTrader

MongolTrader
29 Jun 2022, 09:17

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

My problem is my bot only use label and it can't identify which symbol work with. 

Why not? You can use SymbolName property to check the symbol the cBot is running on.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Tell me with sample please 


@MongolTrader

MongolTrader
26 Jun 2022, 10:42

RE:

PanagiotisCharalampous said:

Hi MongolTrader,

You need to be a little bit more specific. What exactly is your problem? Did you try something and it did not work?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

My problem is my bot only use label and it can't identify which symbol work with. So main problem is if i  use it such as eurusd and xauusd so my bot cant identify whether it eurusd symbol position or xauusd position. So i need easy way to customize my bot or i look is there any new instance feature on ctrader. 


@MongolTrader

MongolTrader
22 Jun 2022, 13:02

RE: RE: RE:

m4trader4 said:

 Dear Mongol Trader,

The code will create a button and OnClick will close all the positions. If you are looking something to close from command line check this thread

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class Button : Robot
    {
       cAlgo.API.Button BCLP;

        void buttonCreate(string BName, string BText, string X, String Y, string clr, cAlgo.API.Button TButton)
        {


            TButton.Height = 15;
            TButton.Width = 24;
            TButton.FontSize = 9;
            TButton.HorizontalContentAlignment = 0;
            TButton.Padding = "0 0 0 0";
            //CornerRadius = 2,
            TButton.Text = BText;
            TButton.Margin = X + " " + Y;
            TButton.BackgroundColor = Color.FromHex(clr);
            TButton.HorizontalAlignment = cAlgo.API.HorizontalAlignment.Left;
            TButton.VerticalAlignment = VerticalAlignment.Bottom;
            //Chart.AddControl(TButton);

        }

        void CloseOrder()
        {

            BeginInvokeOnMainThread(() =>
            {
               
                    var positionsCBS = Positions.ToArray();
                    
                    foreach (var psnCBS in positionsCBS)
                    {
                       ClosePositionAsync(psnCBS);         
                    }

            });
        }


        protected override void OnStart()
        {

            BCLP = new cAlgo.API.Button();
            buttonCreate("CLP", "CLP", "1", "85", "#009345", BCLP);
            Chart.AddControl(BCLP);
            BCLP.Click += args => CloseOrder();
         
        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

 

Thank you very much


@MongolTrader