Topics
30 Aug 2012, 16:09
 3541
 2
Replies

daemon
27 Jan 2014, 17:49

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);

        }

    }
}

 


@daemon

daemon
27 Jan 2014, 16:27

Which values are you looking at exactly on the chart? You can use the market snapshot tool and look at the value for the Histogram Main. The signal would be the line not the histogram.  Maybe test the previous value since the last value would be the current value which constantly changes with new ticks. You can confirm the price by testing the previous bar value. 


@daemon

daemon
21 Jan 2014, 14:02

It seems I have the wrong files because I cannot move the lines prior to submit. But anyway, I don't think I can code it. I can just calculate the lot based on risk and SL/TP input.


@daemon

daemon
21 Jan 2014, 12:51

Maybe I'm missing something in the usage or perhaps I don't have the right files. I don't get how the lot size is calculated from the dragable lines. Only the SL and TP are modified if I drag the lines.


@daemon

daemon
21 Jan 2014, 10:31

Do you want the lot calculation or the whole system because with cTrader you can modify the sl/tp by dragging the lines with out scripts. I think I can make a robot to place trades based on that and then you can use cTrader to drag the sl/tp lines or price for pending orders. Let me know if there is something I missed.

Quote from forexfactory:

I made this simple tool to give me the ability to specify sl/tp for new order by using mouse (dragging line object). Input sl/tp manually is a boring task, especially for lazy trader.
It also monitor existing trade sl/tp, which means it will modify existing sl/tp and open price (for pending order) when it detected a different value between order's sl/tp and the corresponding sl/tp line object.
Other feature : 
- lot size calculated automatically based on the specified risk.
- a simple popup menu that allows you to quickly close an order based on ticket number
Unlike most line object based trading tools, this program doesn't use EA for monitoring lines object every tick, or a script which uses continuous looping with certain delay. It detects mouse dragging activities (hence why it uses dll) and fire the necessary script. All script will return once its job (opening new order / modifying existing orders) finished.


@daemon

daemon
31 Dec 2013, 09:36

 ChartObjects.DrawHorizontalLine("line", Symbol.Bid, Colors.Red);

/api/reference/internals/chartobjects/drawhorizontalline-738f


@daemon

daemon
31 Dec 2013, 09:24 ( Updated at: 21 Dec 2023, 09:20 )

RE:

cogs said:

I get this error, any suggestions?

Remove the first column and probably the first row.

The example in the first page is:

2003.06.18,16:01,1.11423,1.11428,1.11332,1.11374,19
2003.06.18,16:02,1.11364,1.11436,1.11361,1.11405,7
2003.06.18,16:03,1.11402,1.11455,1.11400,1.11440,5
2003.06.18,16:04,1.11446,1.11461,1.11401,1.11447,14


@daemon

daemon
27 Dec 2013, 14:51 ( Updated at: 21 Dec 2023, 09:20 )

You can right click -> Format Cells (highlight the column) the choose the format with the period.


@daemon

daemon
10 Dec 2013, 09:29

RE:

it should be the way hichem said. Commisions and swap are negative.

 

Cerunnos said:

Shouldn't be:

sum += position.NetProfit - position.Swap

or

sum += position.GrossProfit - position.Commissions - position.Swap


Or not?

 

 


@daemon

daemon
09 Dec 2013, 18:06

Wait, Shouldn't it be:

sum += position.NetProfit - position.Commisions - positions.Swap;

 


@daemon

daemon
09 Dec 2013, 18:04

thanks :)


@daemon

daemon
09 Dec 2013, 17:34

something like this:

        double sum;

        protected override void OnTick()
        {
            sum = 0;

            foreach (var position in Positions)
            {
                sum += position.NetProfit;
            }

            if (sum > 0)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }
        }

 


@daemon

daemon
20 Nov 2013, 12:19

RE: Using the Pipe - please help admin!!

jhtrader said:

// I want an example where a principal robot creates a named pipe that communicates a string at the end of 10 min bar "Server says hello"

//Another robot "the second robot" will connect to the pipe and listen when the string is sent the second robot will print the message from the string

//Another robot "the third robot" will connect to the pipe and listen when the string is sent the third robot will print the message "the server said what?"
 

I don't think you can use anonymous pipes for this. 
 

// I want to use named pipe so that any robot that is running on the local machine not connected to the principal robot can listen.. as I understand it unnamed pipes can only be used between parent and child robots. 
 

Anonymous pipes can be used for local inter-process communication. Child classes inherit functionality from parent classes. Named pipes are used for network communication...


This means that if I have distinct robots all wanting to get the string it might not work.

Why not write to a file which the other robots read from? 

When I run the code as you have it.. I get the following error:

15/11/2013 21:17:05.385 | Robot’s "Pipes" initialization process has begun.
15/11/2013 21:17:05.744 | Crashed in OnStart with Win32Exception: The system cannot find the file specified

The error clearly says cannot find the file specified. Did you follow the example instructions on msdn? 
This is where the server (as written above) expects to find the client exe: Environment.SpecialFolder.CommonDocuments
That is the public documents folder. 


15/11/2013 21:17:05.760 | Robot "Pipes" was stopped for NZDUSD, h1.

I tried to create a file pipeClient.exe in several locations but crashed..

Please provide the code for this simple example above and I can then extend it!!

many thanks..

The code for the client is in the msdn link that was provided in the example. 
But I don't think you need this for what you are trying to do anyway.

Good Luck.

 


@daemon

daemon
13 Nov 2013, 09:44

RE: I understand what you mean... but.

jhtrader said:

 

Changing the class by adding

using System;
using cAlgo.API;

namespace TestClass
{
    [Robot()]
    public class Portfolio : Robot
    {  //...
    }

}

 

Will compile but this doesnt make sense why do I need to make the class a robot?  What is the implications of declaring it a Robot?

You don't have to, it will compile without the robot attribute. Just ignore the message. 


@daemon

daemon
12 Nov 2013, 09:55

RE: Not sure that is what I want

jhtrader said:

I am trying to build a generic reference class not a robot.

The example above given does not include the [Robot()] attribute to fxPortfolioClass, this would defeat the purpose.

 

You do need to include cAlgo.API because that is where Position is defined.
You don't need to add the robot attribute. But you will get Unable to load assembly message. 


@daemon

daemon
11 Nov 2013, 10:12

I'm not 100% sure about this but I think you can only initialize indicators in the Initialize method.

 


@daemon

daemon
11 Nov 2013, 09:54

You need to include cAlgo.API and attach the [Robot()] attribute to fxPortfolioClass


@daemon

daemon
05 Nov 2013, 10:09

RE: RE:

kricka said:

Spotware said:

Right now text is drawn on top of trend bars. Is it correct that sometimes you want to draw text behind trend bars?

No, the draw text should be on top, at some times I've noticed that the bars do place them self on top over the draw text. Maybe it has to do with not enough ram memory at the time. I will check more into it if it occurs again. Would like an option though to have the draw text in a box with changeable backgrounds so the text can come forward separated from the main background color on the chart. 

Textboxes would be nice.


@daemon

daemon
05 Nov 2013, 10:02

You need to fix your GetIndexByDate method. 
It should be like this:

        private int GetIndexByDate(DateTime argDateTime)
        {
            for (int i = SecondSeries.Close.Count - 1; i > 0; i--)
            {
                if (argDateTime == SecondSeries.OpenTime[i])
                    return i;
            }
            return -1;
        }

 


@daemon

daemon
19 Jun 2013, 13:07

Try using period 1:

 Functions.HasCrossedBelow(MarketSeries.Close,WELL.Result,1)




@daemon