Delphima's avatar
Delphima
Delphima's avatar

Info

Username:Delphima
Name:Delphima
Member since: 09 May 2020

About

None

Signature

None

Last Forum Posts

@How to avoid onTick() running 'too quick' to place 'duplicate orders':  05 Mar 2021, 17:53


DonaldD said:

Hi Delphima, 

I am not sure if this the case, because I cannot easily reproduce it, but if it is, a way to solve it is to keep your own counter of expected open positions and execute an order only when the count of positions meets that counter e.g.

            if (Symbol.Bid >= BidAnchor && positionsCounter == Positions.Count) 
            { 
               positionsCounter++;
.
.
.

of course you will need to manage the counter accordingly e.g. decrease it when a position is closed.

Hi Donald,

Thanks for your idea. Yes, it is easier to reproduce the situation when the market price moving quickly. As my screenshot shows below:

I set 1.1921 as the entry price when the price bounced up passing quickly, there're 3 OnTick() run in a very short time, and BidAnchor has not updated yet, so 3 positions have been opened. After a few seconds, as I suppose, BidAnchor has been updated, and while the price passed 1.1923 again very quickly, 2 orders were sent...

Well, I just find a temporary solution, if we update BidAnchor just after sending the order, it will surely quicker than the next OnTick(), and it also make sure the next sell price 2 pips higher than this order send e.g Symbol.Bid. 

        if (Symbol.Bid >= BidAnchor) 
            { 
                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000);  
                BidAnchor = Symbol.Bid + 0.0002;
             ...

As another screenshot shows below: entry at 1.1915, every 2 pips added one order, some order's gap is higher than 2 pips, due to market orders executed according to the market price.

Thanks.

@How to avoid onTick() running 'too quick' to place 'duplicate orders':  04 Mar 2021, 18:27


Hello,

I have a simple cBots here, to place a market sell order when the market price moving up every 2 spread/pips. But I found a tech problem that, onTick() running 'too quick' to place 'duplicate orders'. I suspect it is because that the key variable 'BidAnchor' is not updated according to the newly built position. Please help correct the code to make it run as my original purpose.

Thanks,

Lei

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 AutoSellEvery2Spreads : Robot
    {   
        [Parameter("Start Sell Position:", Group = "SELL Position", DefaultValue = 1.2100 )]
         public double BidAnchor{ get; set; }        
        
        protected override void OnStart(){}

        protected override void OnTick()
        {
            var shortpositions = Positions.FindAll("", Symbol.Name, TradeType.Sell);
            foreach (var position in shortpositions)
            {
                if (position.EntryPrice > BidAnchor)
                {
                    BidAnchor = position.EntryPrice + 0.0002;  
                    //Define next entry price to sell a position
                }
            }

            if (Symbol.Bid >= BidAnchor) 
            { 
                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000);  

                /*
                 * Problem is: when market price moving quickly, BidAnchor has not 
                 * been updated according to a new position. While another OnTick has been 
                 * already on the way, which makes 1.2102 or above, eg. 1.21021 another 
                 * position would be added.
                 *
                 * Question is: how to avoid the 'Too quick' running of OnTick() before 
                 * variable BidAnchor's updates.
                 *
                 * Thank you.
                 */

            }
        } 

        protected override void OnStop(){}

    }
}

@Lock price scale:  15 Sep 2020, 21:12


Yes, totally support damian8's idea.  I would like to see price scale locking function in cTrader as well.

@How to preset source in RSI indicator for a cBots, without manually setting?:  02 Jul 2020, 12:31


PanagiotisCharalampous said:

Hi Delphima,

Try the below

            rsi_O = Indicators.RelativeStrengthIndex(Bars.OpenPrices, Periods);
            rsi_C = Indicators.RelativeStrengthIndex(Bars.ClosePrices, Periods);
            rsi_H = Indicators.RelativeStrengthIndex(Bars.HighPrices, Periods);
            rsi_L = Indicators.RelativeStrengthIndex(Bars.LowPrices, Periods);

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

This works well. Thank you very much.:)

Lei

@How to preset source in RSI indicator for a cBots, without manually setting?:  01 Jul 2020, 23:52


Hello,

I have below testing code, it will return last 1st bar's RSI values based on Open/Close/High/Low price. 

Now I want to preset sources for all the dataseries, but obviously I can't put string "Open" to replace Source_O, (in the highlighted area). What should I do to simplify the parameter setting area, to put all parameters preset in the coding stage rather than leave them for manually set?

Thank you again,

Lei

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 TestingRSI : Robot
    {
        [Parameter("Source Open",  Group = "RSI")] public DataSeries Source_O { get; set; }
        [Parameter("Source Close", Group = "RSI")] public DataSeries Source_C { get; set; }
        [Parameter("Source High",  Group = "RSI")] public DataSeries Source_H { get; set; }
        [Parameter("Source Low",   Group = "RSI")] public DataSeries Source_L { get; set; }

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

        private RelativeStrengthIndex rsi_O;
        private RelativeStrengthIndex rsi_C;
        private RelativeStrengthIndex rsi_H;
        private RelativeStrengthIndex rsi_L;

        protected override void OnStart()
        {
            rsi_O = Indicators.RelativeStrengthIndex(Source_O, Periods);
            rsi_C = Indicators.RelativeStrengthIndex(Source_C, Periods);
            rsi_H = Indicators.RelativeStrengthIndex(Source_H, Periods);
            rsi_L = Indicators.RelativeStrengthIndex(Source_L, Periods);            
        }

        protected override void OnBar()
        {   
            Print("rsi_O.Result.Last(1) : {0}", rsi_O.Result.Last(1));
            Print("rsi_L.Result.Last(1) : {0}", rsi_L.Result.Last(1));
            Print("rsi_H.Result.Last(1) : {0}", rsi_H.Result.Last(1));
            Print("rsi_C.Result.Last(1) : {0}", rsi_C.Result.Last(1));
        }
    }
}

@RSI Last method, what's the value exactly mean?:  01 Jul 2020, 16:05


PanagiotisCharalampous said:

Hi Delphima,

 I want to know the code below return RSI value based on last bar, but depend on which moment in the bar. Is it open price or high/close/low?

This value is calculated using the final bar values after the bar closes.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you Panagiotis,

I got the reason, I need to set RSI parameter to open/close/high/low to get what I want from: rsi.Result.Last(1) 

Happy to learn new details from you.

Cheers,

Lei

@RSI Last method, what's the value exactly mean?:  01 Jul 2020, 15:08


PanagiotisCharalampous said:

Hi Delphima,

The method has the same function for indicator data series as well. You code has a logical mistake though. It prints the last value when a bar is created but then compares this value with the value the indicator when the bar closed. The value of the indicator can change in the meanwhile.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Yes, we are quite close to the focus of my concern.

As you said, below code 'It prints the last value when a bar is created' and 'The value of the indicator can change'. I want to know the code below return RSI value based on last bar, but depend on which moment in the bar. Is it open price or high/close/low? I didn't figure it out in the comparison. Please give more information.  Thanks.

Print("rsi.Result.Last(1) : {0}", rsi.Result.Last(1));

@RSI Last method, what's the value exactly mean?:  01 Jul 2020, 14:29


PanagiotisCharalampous said:

Hi Delphima,

Last(x) uses x as a backwards index counter.  Last(1) will return the value for the previous bar, Last(2) for two bars before etc.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Thanks for replying. 

Yes, I know Last(x) method could be used to get bars' high/low/open/close value. I wonder if it can also be used to get indicator's history value, in my example to get RSI's history value?

And, I tested with above code, it can return some value, but it's not what I expected. Can you have a look again?

Thanks,

Lei

@RSI Last method, what's the value exactly mean?:  30 Jun 2020, 23:24


Hello,

I have the code below, which intent to get RSI value based on the previous bar's close price, or past 2nd's 3rd's etc.. I understand rsi.Result.LastValue return the current moment RSI value in the bar. So, I can set a double RsiPreviousBarOpen to record it each time when a new bar start.

But I want to test Last method, like rsi.Result.Last(1) or rsi.Result.Last(3)... to get all data I need in the first run of OnBar(). Amazingly, the rsi.Result.Last(1) didn't get the same value as RsiPreviousBarOpen recorded. 

My question is based on the close price of the last bar how can I get RSI value via Last method, if it is possible? And what exactly rsi.Result.Last(1) return means?

Thanks,

Lei

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 TestingRSI : Robot
    {
        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

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

        public double RsiPreviousBarOpen;

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            
            Print("rsi.Result.Last(0)    : {0}", rsi.Result.Last(0));
            Print("rsi.Result.LastValue: {0}", rsi.Result.LastValue);
            
            RsiPreviousBarOpen = rsi.Result.LastValue;
        }

        protected override void OnBar()
        {   
            Print("rsi.Result.Last(0)    : {0}", rsi.Result.Last(0));
            Print("rsi.Result.LastValue: {0}", rsi.Result.LastValue);

            Print("rsi.Result.Last(1)  : {0}", rsi.Result.Last(1));
            Print("RsiPreviousBarOpen  : {0}", RsiPreviousBarOpen);
            
            RsiPreviousBarOpen = rsi.Result.LastValue;
       }

    }
}

@How to get bar's high and low? Help please:  23 Jun 2020, 16:45


PanagiotisCharalampous said:

Hi Delphima,

See below

        protected override void OnBar()
        {
            Print("LastHigh: " + Bars.HighPrices.Last(1) + " LastLow: " + Bars.LowPrices.Last(1));
        }

Best Regards,

Panagiotis 

Join us on Telegram

Thanks Panagiotis,

I may have more questions to put to the forum, this is a great place to learn and having fun.

Thanks again.

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.