Topics

Forum Topics not found

Replies

behkam21
06 Oct 2018, 19:46

RE:

lucian said:

Last value means last closed bar (if you use OnBar)

According to Time Frame setting, the last bar represent the last 1 Hour bar, or the last 1 minute bar, etc.

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 9)]
        public int tenkanSenPeriods { get; set; }
        [Parameter(DefaultValue = 25)]
        public int kijunSenPeriods { get; set; }
        [Parameter(DefaultValue = 32)]
        public int senkouSpanBPeriods { get; set; }
        private IchimokuKinkoHyo ichimokuKinkoHyo;

        protected override void OnStart()
        {
            ichimokuKinkoHyo = Indicators.IchimokuKinkoHyo(tenkanSenPeriods, kijunSenPeriods, senkouSpanBPeriods);
        }
        protected override void OnBar()
        {
            Print("KijunSen Value = {0}", ichimokuKinkoHyo.KijunSen.LastValue);
            Print("SenkouSpanA Value = {0}", ichimokuKinkoHyo.SenkouSpanA.LastValue);
            Print("SenkouSpanB Value = {0}", ichimokuKinkoHyo.SenkouSpanB.LastValue);
            Print("TenkanSen Value = {0}", ichimokuKinkoHyo.TenkanSen.LastValue);

        }

    }
}

If you don't feel confident with the above code try this:
The   count-2 represent the last closed bar.

 

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 9)]
        public int tenkanSenPeriods { get; set; }
        [Parameter(DefaultValue = 25)]
        public int kijunSenPeriods { get; set; }
        [Parameter(DefaultValue = 32)]
        public int senkouSpanBPeriods { get; set; }
        private IchimokuKinkoHyo ichimokuKinkoHyo;

        protected override void OnStart()
        {
            ichimokuKinkoHyo = Indicators.IchimokuKinkoHyo(tenkanSenPeriods, kijunSenPeriods, senkouSpanBPeriods);
        }
        protected override void OnBar()
        {
            int index = MarketSeries.Close.Count - 2;

            Print("KijunSen Value = {0}", ichimokuKinkoHyo.KijunSen[index]);
            Print("SenkouSpanA Value = {0}", ichimokuKinkoHyo.SenkouSpanA[index]);
            Print("SenkouSpanB Value = {0}", ichimokuKinkoHyo.SenkouSpanB[index]);
            Print("TenkanSen Value = {0}", ichimokuKinkoHyo.TenkanSen[index]);

        }

    }
}

 

 


@behkam21

behkam21
06 Oct 2018, 19:46

RE:

OOSilgjerd said:

Hi, I'm a complete beginner in programming so please excuse my lack of knowledge.

 

I am attempting to make a cBot that enters a long position if:

  • The last candle closed above the kumo (cloud)

But only if:

  • It opened inside or on the opposite side of the kumo and
  • It is currently no more than 30 pips away from the kumo.

(Opposite requirements for a short position).

I know a lot is wrong with this code, I need to be pointed in the right direction and taught some code on how to do a few things. I'm not asking you to make my entire bot although it would have been awfully nice if somebody could do maybe a little bit for me ;)  

I need help on:

  • The buy and sell signals (and then make it execute the orders)
  • Setting SL and TP (make two positions, SL 25 pips on both, TP 20 pips on one, 30 pip trailing stop triggered when @ 30 pip profit on the other)
  • Make the SL move to break even when the 20 pip SL is hit on the first trade.
//#reference: ..\Indicators\Ichimoku_cloud2.algo
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)]
    public class IchimokuBreakoutBot : Robot
    {

        private Ichimoku_cloud2 Ichi;

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

        protected override void OnStart()
        {
            Ichi = Indicators.GetIndicator<Ichimoku_cloud2>();
        }

        protected override void OnBar()
        {
            if (HasCrossedAbove(Ichi.SenkouSpanA, Ichi.SenkouSpanB && MarketSeries.Close > Ichi.SenkouSpanA))
                ;
            {
                OpenPosition(TradeType.Buy);
            }
        }

 

 


@behkam21