Topics
Replies

firemyst
24 Nov 2022, 05:59

RE:

vvictord said:

Still looking for someone with these skills hehe

All you have to do is similar to the following:

 

//Create your parameter
 [Parameter("Max Num of Open Positions", DefaultValue = 3)]
        public int MaxNumberOfAllowedOpenTrades { get; set; }



//And in your code, do the check:

if (Positions.Count <= MaxNumberOfAllowedOpenTrades)
{
    //do your stuff
}
else
{
   Print ("Too many positions already opened.");
}

 


@firemyst

firemyst
04 Nov 2022, 11:02

RE: RE:

MongolTrader said:

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.  

What I would consider doing then is:

1) in your OnStart do the while loop and find the last overbought/sold

2) create a class variable and store the index of the last overbought bar index in it

3) for every onbar event, check the stoch. If it's overbough/sold, update the global variation with the new bar number.

 

When you want bots running fast to respond to the market,  so no need to execute a loop every single time a new bar or tick occurs.


@firemyst

firemyst
03 Nov 2022, 11:01

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


@firemyst

firemyst
03 Nov 2022, 01:45

Hi there,

Looks like you've made good progress!

This is correct - well done!

_marketSeries2 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
_marketSeries1 = MarketData.GetBars(TimeFrame.Minute15, Symbol.Name);
macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);

 

If you're unsure that you're getting the values you are expecting, then put Print statements in your code to print out the values and you can compare against having MACD indicators on your charts.

Example Print statement:

Print("MACD1 Value {0}, MACD1 Prev {1}", MACDLine1, PrevMACDLine1);


@firemyst

firemyst
02 Nov 2022, 16:51

Are you in any trading groups or anything like that where you could ask people?


@firemyst

firemyst
02 Nov 2022, 16:28

If you're a programmer doing what you want isn't too difficult:


@firemyst

firemyst
02 Nov 2022, 16:22

RE:

valerijabramov24 said:

I have created my own cBot code and applied multiple instruments but it does not all work all the instruments parallelly. Only it is placing the order in active chart.

It does not work non interactive charts. is that expected ?

 I am running multiple bots with multiple bot instances and they all place trades when they should -- not just on an active chart if I have an active chart (because when you run bots you don't necessarily have to have a chart open)


@firemyst

firemyst
01 Nov 2022, 13:06

Keep in mind that when using reflection in C#, those operations are costly and relatively slow, so use sparingly. If you need your cBot to run and react fast to market conditions, you'd want to limit the amount of reflection you use in your code.


@firemyst

firemyst
01 Nov 2022, 00:59

Your code isn't going to work, because you're not creating the marketseries variables correctly:

 

_marketSeries2 = MarketData.GetBars(macd2, Symbol.Name);
            _marketSeries1 = MarketData.GetBars(macd1, Symbol.Name);

 

The method is "GetBars", so why are you passing in the macd indicators? The first parameter of the GetBars method is the TIMEFRAME, not an indicator.

 

You are also not creating/initializing the MACD indicator as I showed you in my example -- the first parameter should be the data series, not the long period.

Please go back and reread my example making sure you understand it.

Spotware also has an example on their website which should help:

https://help.ctrader.com/ctrader-automate/indicator-code-samples/#multiple-timeframes

 


@firemyst

firemyst
31 Oct 2022, 13:51 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Alwin123 said:

How to use 2 macd different timeframe

 

I can't get past this.

anyone who can improve the script?
Both macd must indicate the same sentiment before opening a trade.

Preferably above or below the zero line

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
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 PullbackStrategy : Robot
    {

        [Parameter("Sentiment: Buy", Group = "Sentiment", DefaultValue = true)]
        public bool Buy { get; set; }

        [Parameter("Sentiment: Sell", Group = "Sentiment", DefaultValue = true)]
        public bool Sell { get; set; }

        [Parameter("Another Time Frame MACD ", Group = "Strategy", DefaultValue = "Hour")]
        public TimeFrame Multitimeframe { get; set; }

        [Parameter("Source", Group = "RSI")]
        public DataSeries SourceRSI { get; set; }

        [Parameter("Periods", Group = "RSI", DefaultValue = 19)]
        public int PeriodsRSI { get; set; }

        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Stop Loss ", Group = "Risk Managment", DefaultValue = 100)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Risk Managment", DefaultValue = 100)]
        public int TakeProfit { get; set; }


        public ExponentialMovingAverage i_MA_slow;
        public ExponentialMovingAverage i_MA_standart;
        public ExponentialMovingAverage i_MA_fast;
        private RelativeStrengthIndex rsi;
        private MacdCrossOver macd;
        private MacdCrossOver MultitimeframeMACD;
        private double volumeInUnits;
        private Position position;


        protected override void OnStart()

        {
            i_MA_slow = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 50);
            i_MA_standart = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 20);
            i_MA_fast = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 8);
            rsi = Indicators.RelativeStrengthIndex(SourceRSI, PeriodsRSI);
            macd = Indicators.MacdCrossOver(26, 12, 9);
            MultitimeframeMACD = Indicators.MacdCrossOver(26, 12, 9);
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;
        }

        void OnPositionsClosed(PositionClosedEventArgs obj)
        {
            position = null;
        }

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            position = obj.Position;
        }
                    
                                  
        [Obsolete]
        protected override void OnBar()
        {
        var MACDLine  = macd.MACD.Last(1);
        var PrevMACDLine = macd.MACD.Last(2);
        var Signal  = macd.Signal.Last(1);
        var PrevSignal= macd.Signal.Last(2);

            // both macd must be above the zero line for an entry buy or sell
            var MultitimeframeMACD = MarketData.GetSeries(Multitimeframe);
            var Multitimeframe = MultitimeframeMACD.MACD.Last(1);
            var PrevMACDLineMultiTF = MultitimeframeMACD.MACD.Last(2);
            var SignalMultiTF = MultitimeframeMACD.Signal.Last(1);
            var PrevSignalMultiTF = MultitimeframeMACD.Signal.Last(2);

            if (position != null)
                return;
            {
                if (rsi.Result.LastValue > 25 && rsi.Result.LastValue < 70)
                {
                    
                        int index = MarketSeries.Close.Count;

                    if   (MACDLine > Signal & PrevMACDLine <PrevSignal & default==Sell 
                        & Multitimeframe > SignalMultiTF & PrevMACDLineMultiTF < PrevSignalMultiTF & default == Sell
                        & i_MA_fast.Result[index - 2] > MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] < MarketSeries.Close[index - 1]
                        & i_MA_fast.Result.LastValue < i_MA_standart.Result.LastValue
                        & i_MA_fast.Result.LastValue < i_MA_slow.Result.LastValue
                        & i_MA_standart.Result.LastValue < i_MA_slow.Result.LastValue)
               {         
                        
                      ExecuteMarketOrder( TradeType.Buy, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  }
                        
                        else if (MACDLine < Signal & PrevMACDLine >PrevSignal & default== Buy
                        & Multitimeframe > SignalMultiTF & PrevMACDLineMultiTF < PrevSignalMultiTF & default == Buy
                        & i_MA_fast.Result[index - 2] < MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] > MarketSeries.Close[index - 1]
                        & i_MA_fast.Result.LastValue > i_MA_standart.Result.LastValue
                        & i_MA_fast.Result.LastValue > i_MA_slow.Result.LastValue
                        & i_MA_standart.Result.LastValue > i_MA_slow.Result.LastValue)

                        {
                                        
                     ExecuteMarketOrder( TradeType.Sell, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  
                            }
                }
               

                } 
           
         }
                   
       
           protected override void OnStop()
        {
        }
                  
        }
    }
     


        
   
    
    

HI @Alwin123:

Your code isn't going to work, because you have to pass in a different time frame series when you create the MACD indicator.

It'll be something like this:
 

private Bars _marketSeriesH1;
MacdCrossOver macd;

//In the OnStart method, do something like this. This will get the data for the H1 timeframe:
_marketSeriesH1 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);

//This gets the MACD with the above time frame set (eg, H1 in this case):
macd = Indicators.MacdCrossOver(_marketSeriesH1.ClosePrices, LongPeriod, ShortPeriod, SignalPeriod);



@firemyst

firemyst
31 Oct 2022, 13:50

RE:

PanagiotisChar said:

Hi Waxy,

Did you try

[Parameter("Color", DefaultValue = "Red")] public MyColors Color { get; set; }

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

HI @PanagiotisChar:

I believe it's broken in the latest cTrader release, because the code below doesn't work for me any more either. It always comes up with a default value of "Yesterday" instead of "Three_Weeks":

     public enum LoadFromData
        {
            Yesterday,
            Today,
            Two_Days,
            Three_Days,
            One_Week,
            Two_Weeks,
            Three_Weeks,
            Monthly,
            Custom
        }
        [Parameter("Amount of Historic Data to Load:", DefaultValue = LoadFromData.Three_Weeks)]
        public LoadFromData LoadFromInput { get; set; }

 


@firemyst

firemyst
31 Oct 2022, 13:45

HI @Alwin123:

Your code isn't going to work, because you have to pass in a different time frame series when you create the MACD indicator.

It'll be something like this:
 

private Bars _marketSeriesH1;
MacdCrossOver macd;

//In the OnStart method, do something like this. This will get the data for the H1 timeframe:
_marketSeriesH1 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);

//This gets the MACD with the above time frame set (eg, H1 in this case):
macd = Indicators.MacdCrossOver(_marketSeriesH1.ClosePrices, LongPeriod, ShortPeriod, SignalPeriod);


 


@firemyst

firemyst
27 Oct 2022, 12:16

Google is your friend:

 


@firemyst

firemyst
27 Oct 2022, 12:11 ( Updated at: 21 Dec 2023, 09:23 )

RE:

mindfulness said:

Hello,

 

even with using the memory manager, the used memory is increasing overtime and i have to restart the bot after maybe two days. Is there another way to handle it?

For example on one VPS there are running two ctrade instances. One with 37 pairs/bots and one with 15. The VPS has 4 cores and 8 GB RAM. Here the usage after one day.

How much writing to the log does the bot do? Eg, PRINT statements? You can't clear the log programmatically, and constantly writing to it will suck up memory.


@firemyst

firemyst
25 Oct 2022, 06:42

Do you mean programmatically and for a custom indicator?

You can always set your own version and description in the code as constants (or something similar)


@firemyst

firemyst
20 Oct 2022, 09:09

RE:

PanagiotisCharalampous said:

 

As far as developer support is concerned, I am 100% sure that we have the best community team out there!

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

There's definitely room for improvement. I don't think you've ever used the platform "ProRealTime" and/or visited their "ProRealCode" forums or code libraries?:-)

They have dedicated employees not only writing code/custom indicators, but also responding to queries in the forums on a daily basis, in multiple languages, for both their "ProRealTime" product and their custom "ProRealCode" coding.

@Spotware is nowhere near as interactive in its cTrader forums.


@firemyst

firemyst
18 Oct 2022, 14:43

Yes, develop these options.

 

cTrader already downloads the O/H/L/C information -- just alter the servers so they keep track of this as well to feed the data to cTrader clients.

 

Thank you.


@firemyst

firemyst
18 Oct 2022, 14:39

RE: RE:

Shares4us said:

what do you mean by Renko tails?
Wicks?

 

Yes, but on Renko Charts they're known as "tails" because they can only have them on the back end (eg, the end opposite the way the bar closed) whereas "wicks" you can have at both ends.


@firemyst

firemyst
13 Oct 2022, 15:50

RE:

PanagiotisChar said:

Hi firemyst,

I cannot think of an accurate way to do so without tick data.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Thank you @PanagiotisChar

 

And congratulations on your new positions. :-)


@firemyst

firemyst
04 Oct 2022, 03:25

You could just try reading online documentation provided by Spotware, such as:

https://help.ctrader.com/ctrader-automate/creating-and-running-a-cbot/

 

or here:

https://help.ctrader.com/ctrader-automate/guides/

 

or even the higher level link:

https://help.ctrader.com/ctrader-automate/

 


@firemyst