Replies

Aiki1000
05 Sep 2019, 18:29

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

See below how to do this

            if (BarColor == FormationType.DownClose)
            {
                DotAbove[index] = High + (DotSpacing * Symbol.PipSize);
            }

Best Regards,

Panagiotis

 

Hello again - Just tried your solution. If I use the code snippet pasted above,  I get plots over every bar.  

What, please, am I doing wrong?

 

Also, is there a way to enumerate (each of the enums) within the IF argyument? Or do I need to build an If/else chain for each enum individually? I have no idea, obviously, but I would have thought the code would have been something like:

 

if (BarColor == FormationType.XXX)
            {
                DotAbove[index] = High + (DotSpacing * Symbol.PipSize);
            }

 

with the XXX somehow calling the enum  currently selected in the parameter

 

Thx again for the help -

 

 

 


@Aiki1000

Aiki1000
05 Sep 2019, 17:21

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

See below how to do this

            if (BarColor == FormationType.DownClose)
            {
                DotAbove[index] = High + (DotSpacing * Symbol.PipSize);
            }

Best Regards,

Panagiotis

 

Thank you, sir!

And all other enum would follow as further If(s) or else(s), correct?

That's great, thank you - I really appreciate the help...!


@Aiki1000

Aiki1000
01 Aug 2019, 19:09

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

If you share the cBot code we might be able to point you to the right direction.

Best Regards,

Panagiotis

No probelem - thank you. Here you go:

 

 

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 CT_PlaceStopOrderLearn : Robot
    {
        #region User Supplied Parameters

        [Parameter("Volume", DefaultValue = 10000.0)]
        public int Volume { get; set; }

        [Parameter("Sop Loss (pips)", DefaultValue = 12)]
        public int StopLossPips { get; set; }

        [Parameter("Take Profit (pips)", DefaultValue = 30)]
        public int TakeProfitPips { get; set; }

        #endregion


        #region cTrader Events


        protected override void OnStart()
        {

        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {



            // Define Bars:

            //Define (last FORMING bar) OHLC - think of this as bar 0.
            double currOpen = MarketSeries.Open.LastValue;
            double currHigh = MarketSeries.High.LastValue;
            double currLow = MarketSeries.Low.LastValue;
            double currClose = MarketSeries.Close.LastValue;

            // Define Bar (last closed bar) OHLC
            double Open1 = MarketSeries.Open.Last(1);
            double High1 = MarketSeries.High.Last(1);
            double Low1 = MarketSeries.Low.Last(1);
            double Close1 = MarketSeries.Close.Last(1);

            // Define (1 Bars before last closed bar) bar OHLC
            double Open2 = MarketSeries.Open.Last(2);
            double High2 = MarketSeries.High.Last(2);
            double Low2 = MarketSeries.Low.Last(2);
            double Close2 = MarketSeries.Close.Last(2);

            // Define (2 Bars before last closed) bar OHLC
            double Open3 = MarketSeries.Open.Last(3);
            double High3 = MarketSeries.High.Last(3);
            double Low3 = MarketSeries.Low.Last(3);
            double Close3 = MarketSeries.Close.Last(3);

            // Define (3 Bars before last closed) bar OHLC
            double Open4 = MarketSeries.Open.Last(4);
            double High4 = MarketSeries.High.Last(4);
            double Low4 = MarketSeries.Low.Last(4);
            double Close4 = MarketSeries.Close.Last(4);


            if (Close1 < Open1 && Close2 < Open2 && Close3 > Open3)
            {

                PlaceStopOrder(TradeType.Buy, Symbol, 10000, MarketSeries.High.Last(1), "ctwm_StopTest", StopLossPips, TakeProfitPips);
                Print("The stop is: ", MarketSeries.High.Last(1));
            }


        }

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



    }

}



 


@Aiki1000

Aiki1000
30 Jul 2019, 18:47

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

Thanks for posting in our forum. If you need the last value of a DataSeries, use LastValue. If you need any value before the last value, use Last(x) with x counting backwards e.g. if you need the bar before the last value, use Last(1).

Best Regards,

Panagiotis

Thank you Sir!

That settles that...perfect. And this sytax is the same for either robots, or Indicators, correct?

Again, I really apprecaite the response.


@Aiki1000