Topics
24 Jul 2014, 21:39
 2716
 1
24 Jul 2014, 21:10
 3997
 3
Replies

Ancalagon
25 Jul 2014, 12:51

RE:

tradermatrix said:

   protected override void OnStart()
        {
            ichimoku = Indicators.GetIndicator(periodFast, periodMedium, periodSlow, DisplacementCloud);
        }

i have program with private ichoku cloud

cannot find the ichimokucloud


@Ancalagon

Ancalagon
24 Jul 2014, 21:53

RE:

this not works for me

daemon said:

Hi This is how to open a long position. The rest of the code for the short is similar. You can also find examples on trailing stop and break even here on the forum.

I used the Ichimoku Cloud from here. 

/*
 *  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).
 */

using cAlgo.API;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class IchimokouBot : Robot
    {
        private IchimokuCloud ichimoku;
        [Parameter(DefaultValue = 9)]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26)]
        public int periodMedium { get; set; }

        [Parameter(DefaultValue = 52)]
        public int periodSlow { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementCloud { get; set; }

        [Parameter(DefaultValue = "MyLabel")]
        public string MyLabel { get; set; }

        [Parameter(DefaultValue = 10000)]
        public int Volume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 25, MinValue = 0, MaxValue = 100)]
        public int StopLossPips { get; set; }

        [Parameter("Take Profit", DefaultValue = 20, MinValue = 0, MaxValue = 100)]
        public int TakeProfitPips { get; set; }


        protected override void OnStart()
        {
            ichimoku = Indicators.GetIndicator(periodFast, periodMedium, periodSlow, DisplacementCloud);
        }

        protected override void OnBar()
        {
            var closedAbove = MarketSeries.Close.Last(1) > ichimoku.SenkouSpanA.Last(1);
            var openedInsideKumo = MarketSeries.Open.Last(1) <= ichimoku.SenkouSpanA.Last(1) &&
                                   MarketSeries.Open.Last(1) >= ichimoku.SenkouSpanB.Last(1);
            var distanceFromKumo = (MarketSeries.Close.LastValue - ichimoku.SenkouSpanA.LastValue)/Symbol.PipSize;

            if (closedAbove && openedInsideKumo && distanceFromKumo <= 30)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, MyLabel, StopLossPips, TakeProfitPips);

        }

    }
}

 

 


@Ancalagon

Ancalagon
24 Jul 2014, 21:11

RE:

Ancalagon said:

 

stop los need to be a take proift sorry i cannot setup a take profit can someone please helpe me

hallo how can i had a stop los with this mod?

 

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//
//    The "Sample RSI cBot" will create a buy order when the Relative Strength Index indicator crosses the  level 30, 
//    and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in 
//    the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level 
//    and sell orders are closed when RSI crosses the 30 level). 
//
//    The cBot can generate only one Buy or Sell order at any given time.
//
// -------------------------------------------------------------------------------------------------

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

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

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

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        protected override void OnTick()
        {
            if (rsi.Result.LastValue < 30)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.LastValue > 70)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("SampleRSI", Symbol, tradeType);

            if (position == null)
                ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI");
        }
    }
}

 


@Ancalagon