Replies

ahadfirdosi
01 Sep 2022, 04:30

RE:

Spotware said:

Dear Trader,

Here is the code for the cBot

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CloseAllPositions : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            if (DateTime.Now.Hour == 8 && DateTime.Now.Minute == 0)
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
        }

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

Best Regards,

cTrader Team

This is not working!!! Please help. How to make it work? Where is the problem?

It just doesn't close the positions. No Errors.

 


@ahadfirdosi

ahadfirdosi
31 Aug 2022, 11:47

Only Work With Gold

This bot is working just fine now on Gold as I want. But I am still not sure why it is working only with Gold and not other pairs. Can you please let me know why and how to make it work with other pairs as well?


@ahadfirdosi

ahadfirdosi
31 Aug 2022, 11:26

RE:

PanagiotisCharalampous said:

Hi there,

You need to provide more information regarding what is not working. But an obvious issue is that you do not use brackets for your if statement. So the Stop() method is always executed.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

I appreciate your help. It's working just fine now. I have just put brackets:

protected override void OnTick()
       {
            //if account equity is more than equity take profit or less than equity stop loss, we close all positions
            if (Account.Equity > Account.Balance + Positions.Count || Account.Equity < EquityStopLoss || Account.Equity > EquityTakeProfit)
              {
              foreach (var position in Positions)
                    ClosePosition(position);
                    Stop();
                    }
                
        }

 


@ahadfirdosi

ahadfirdosi
30 Aug 2022, 21:15

RE:

PanagiotisCharalampous said:

Hi there,

You can use the Stop() method.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

& also I don't know why it is working only for Gold and not on any other pair. Can you help me to enable other pairs as well?


@ahadfirdosi

ahadfirdosi
30 Aug 2022, 17:55

RE:

PanagiotisCharalampous said:

Hi there,

You can use the Stop() method.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 Hi, Thanks for your reply. It is not working. I am just a beginner in coding. Maybe I am doing something wrong. :(

protected override void OnTick()
        {
            //if account equity is more than equity take profit or less than equity stop loss, we close all positions
            if (Account.Equity > EquityTakeProfit || Account.Equity < EquityStopLoss)
                foreach (var position in Positions)
                    ClosePosition(position);
                    Stop();
        }

 


@ahadfirdosi