Topics
16 Feb 2016, 07:16
 7179
 7
15 Aug 2015, 14:47
 5218
 15
28 Apr 2015, 14:20
 8041
 18
26 Feb 2015, 07:19
 2968
 2
23 Oct 2014, 13:52
 2284
 2
05 Sep 2014, 00:08
 0
 3115
 3
19 Aug 2014, 13:23
 2662
 3
Replies

hiba7rain
31 Jul 2014, 12:47

RE:

 :) any suggestions 

hiba7rain said:

Hi All, 

am looking for your support, how can i get the higher high and lower low price for previous day?

Thanks 

 


@hiba7rain

hiba7rain
23 Jul 2014, 11:28

RE: RE: RE: RE: RE:

Thanks ... do you have any other link where I can read about on how to use bars?

Invalid said:

Hi hiba7rain.

CBots are run on the client side (your machine), not on server. You can use VPS in order to keep cbot running on the server (but it will cost some money). Take a look here.

If you need to get some idea about C# language than you can read this post. You don't have to read everything there, just what you consider to be useful for you.

 

 

 

hiba7rain said:

Hi Invalid,

Thanks again, yes its working fine now after i have change it as you advise me  :) it was helpful to point the missing functions to me , for the moment I will do some modifications and additions before testing the robot live and ill update you , by the way why robots stop functioning once you log out form calgo or ctrader platforms?

 

 


@hiba7rain

hiba7rain
23 Jul 2014, 09:22

RE: RE: RE:

Hi Invalid,

Thanks again, yes its working fine now after i have change it as you advise me  :) it was helpful to point the missing functions to me , for the moment I will do some modifications and additions before testing the robot live and ill update you , by the way why robots stop functioning once you log out form calgo or ctrader platforms?

 

Invalid said:

Hi hiba7rain.

You don't understand smth fundamental yet.

Positions - it's a collection of all of your positions.

if you execute next code:

 foreach (var position in Positions)
{
      ClosePosition(position); 
}

it will close all your positions. If you need to close specific positions, than do as you did to get them and pass them to ClosePosition method.

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                var positionsToClose = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
                foreach (var position in positionsToClose)
                {
                    ClosePosition(position);
                }
            }
        }

hiba7rain said:

hanks for your reply  in fact I also got some help for friends here and I used the following method but am still having a problem that if i use the method all other positions will be closed which i dont want it to happen

the method I use is

protected override void OnTick()
        {
            CheckForEMA();
            var positions = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 

MRSV said:

 

This was an example of how to use the Close() method.

If(SMA.Result.LastValue > 1)

Close();

 

It is the same as the method for opening a position, but insted of opening a position it closes it.

So you have for your criteria for closing a position that is the IF("something") then close.

 

In the example i used all positions would close when the Simple Moving Average hit 1.

If you want the position to close when EMA is equal or less the the as you write it like this:

If(EMA.Result.LastValue <= Symbol.Ask)
Close();

 

 

 

 

 

 


@hiba7rain

hiba7rain
22 Jul 2014, 10:45

RE: RE: RE:

Hey Invalid,

hope all things fine with you, and thanks again, yes its a bit confusion for me understanding the functions around calgo, but any way I think I did apply the same method you described below and it didnt work with me as I remember .... actually am not sure, I will apply it again and let you know the results

Invalid said:

Hi hiba7rain.

You don't understand smth fundamental yet.

Positions - it's a collection of all of your positions.

if you execute next code:

 foreach (var position in Positions)
{
      ClosePosition(position); 
}

it will close all your positions. If you need to close specific positions, than do as you did to get them and pass them to ClosePosition method.

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                var positionsToClose = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
                foreach (var position in positionsToClose)
                {
                    ClosePosition(position);
                }
            }
        }

hiba7rain said:

hanks for your reply  in fact I also got some help for friends here and I used the following method but am still having a problem that if i use the method all other positions will be closed which i dont want it to happen

the method I use is

protected override void OnTick()
        {
            CheckForEMA();
            var positions = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 

MRSV said:

 

This was an example of how to use the Close() method.

If(SMA.Result.LastValue > 1)

Close();

 

It is the same as the method for opening a position, but insted of opening a position it closes it.

So you have for your criteria for closing a position that is the IF("something") then close.

 

In the example i used all positions would close when the Simple Moving Average hit 1.

If you want the position to close when EMA is equal or less the the as you write it like this:

If(EMA.Result.LastValue <= Symbol.Ask)
Close();

 

 

 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 21:45

RE: RE: RE: RE: RE:

am I doing something wrong in the following method as am still having the same problem all positions get closed as I run the Robot , positions that the root not assigned to

protected override void OnTick()
        {
            CheckForEMA();
            var positions = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 

Spotware said:

is there any link or source might be useful to understand the codes and variables to be used if I would like to work on a robot using bars

OnBar - you can use it to execute you logic on each incoming Bar.

but with a major problem if I operate the robot it close all other opened positions with

It closes all positions because you iterate through all positions and call ClosePosition. It's up to you what positions should be closed.

 

hiba7rain said:

Thanks its working perfectly but with a major problem if I operate the robot it close all other opened positions with

if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

Any suggestions??

Regards,

Spotware said:

 

one is via stop loss parameter 

You set the stoploss on executing market order. So no extra actions needed there.

 ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);

 

other by value of ask price against EMA is it possible to do so? if yes how to?

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

                }
            }

        } 

 

other by value of ask price against EMA

is it possible to do so? if yes how to?

 

hiba7rain said:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

 

Hi Spotware, 

what could be wrong with the following , my intention to create  two different methods to close position one is via stop loss parameter and other by value of ask price against EMA

is it possible to do so? if yes how to?

private void Open(TradeType tradType)
        {

            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);
            Print(LastResult.Position.TradeType);
        }


        private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);

            }

            if (ema1.Result.LastValue > Symbol.Ask)
            {
                Close();
            }

        } 

 

 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 21:28

RE:

hanks for your reply  in fact I also got some help for friends here and I used the following method but am still having a problem that if i use the method all other positions will be closed which i dont want it to happen

the method I use is

protected override void OnTick()
        {
            CheckForEMA();
            var positions = Positions.FindAll("calgooob", Symbol, TradeType.Buy);
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 

MRSV said:

 

This was an example of how to use the Close() method.

If(SMA.Result.LastValue > 1)

Close();

 

It is the same as the method for opening a position, but insted of opening a position it closes it.

So you have for your criteria for closing a position that is the IF("something") then close.

 

In the example i used all positions would close when the Simple Moving Average hit 1.

If you want the position to close when EMA is equal or less the the as you write it like this:

If(EMA.Result.LastValue <= Symbol.Ask)
Close();

 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 18:19

RE: RE: RE: RE: RE: RE: RE:

Thank you but no its still not working , i applied it as follows

private Position _position;





        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                _position = null;
            }
        }

    }
}

if I start the robot for example with GBPUSD and i opened a trade with other pair of currency say like AUDUSD it will be closed as soon as ema>symbol.ask condition with AUDUSD

applies which is weird  

Invalid said:

Take a look at guide. ExecuteMarketOrder returns an object with Position inside.

Quick sample:

        private Position _position;

        protected override void OnStart()
        {
           //....initialize ema1
            _position = ExecuteMarketOrder(TradeType.Sell, Symbol, 20000).Position;
        }

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                _position=null;
            }
        }

 

hiba7rain said:

 Thanks but how to make it (close position) assigned to a specific  executed market order trade type , I have tried to do it using closepositions.Find but I think I done something wrong and its not working with me 

 


@hiba7rain

hiba7rain
21 Jul 2014, 15:33

RE: RE: RE: RE: RE:

 Thanks but how to make it (close position) assigned to a specific  executed market order trade type , I have tried to do it using closepositions.Find but I think I done something wrong and its not working with me 

Spotware said:

is there any link or source might be useful to understand the codes and variables to be used if I would like to work on a robot using bars

OnBar - you can use it to execute you logic on each incoming Bar.

but with a major problem if I operate the robot it close all other opened positions with

It closes all positions because you iterate through all positions and call ClosePosition. It's up to you what positions should be closed.

 

hiba7rain said:

Thanks its working perfectly but with a major problem if I operate the robot it close all other opened positions with

if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

Any suggestions??

Regards,

Spotware said:

 

one is via stop loss parameter 

You set the stoploss on executing market order. So no extra actions needed there.

 ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);

 

other by value of ask price against EMA is it possible to do so? if yes how to?

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

                }
            }

        } 

 

other by value of ask price against EMA

is it possible to do so? if yes how to?

 

hiba7rain said:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

 

Hi Spotware, 

what could be wrong with the following , my intention to create  two different methods to close position one is via stop loss parameter and other by value of ask price against EMA

is it possible to do so? if yes how to?

private void Open(TradeType tradType)
        {

            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);
            Print(LastResult.Position.TradeType);
        }


        private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);

            }

            if (ema1.Result.LastValue > Symbol.Ask)
            {
                Close();
            }

        } 

 

 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 12:55

RE: RE: RE:

Thanks its working perfectly but with a major problem if I operate the robot it close all other opened positions with

if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

Any suggestions??

Regards,

Spotware said:

 

one is via stop loss parameter 

You set the stoploss on executing market order. So no extra actions needed there.

 ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);

 

other by value of ask price against EMA is it possible to do so? if yes how to?

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

                }
            }

        } 

 

other by value of ask price against EMA

is it possible to do so? if yes how to?

 

hiba7rain said:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

 

Hi Spotware, 

what could be wrong with the following , my intention to create  two different methods to close position one is via stop loss parameter and other by value of ask price against EMA

is it possible to do so? if yes how to?

private void Open(TradeType tradType)
        {

            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);
            Print(LastResult.Position.TradeType);
        }


        private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);

            }

            if (ema1.Result.LastValue > Symbol.Ask)
            {
                Close();
            }

        } 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 10:22

RE: RE: RE:

Thanks for your reply

ill change it as you advice me and keep you updated

is there any link or source might be useful to understand the codes and variables to be used if I would like to work on a robot using bars

 

Spotware said:

 

one is via stop loss parameter 

You set the stoploss on executing market order. So no extra actions needed there.

 ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);

 

other by value of ask price against EMA is it possible to do so? if yes how to?

        protected override void OnTick()
        {
            CheckForEMA();
        }

        private void CheckForEMA()
        {
            if (ema1.Result.LastValue > Symbol.Ask)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);

                }
            }

        } 

 

other by value of ask price against EMA

is it possible to do so? if yes how to?

 

hiba7rain said:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

 

Hi Spotware, 

what could be wrong with the following , my intention to create  two different methods to close position one is via stop loss parameter and other by value of ask price against EMA

is it possible to do so? if yes how to?

private void Open(TradeType tradType)
        {

            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);
            Print(LastResult.Position.TradeType);
        }


        private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);

            }

            if (ema1.Result.LastValue > Symbol.Ask)
            {
                Close();
            }

        } 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 10:18

RE: RE: RE: RE: RE:

thanks again,

ill work on it and update you if succeeded.

Invalid said:

The code is the same for EMA

       private ExponentialMovingAverage ema;

        protected override void OnStart()
        {
            ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 14);
        }

        protected override void OnBar()
        {
            if (MarketSeries.Close.Last(1) < ema.Result.Last(1))
                ClosePosition(_position);
        }

 

hiba7rain said:

Invalid said:

Thank Invalid,

is the EMA codes and variables different from using SMA?

 


@hiba7rain

hiba7rain
21 Jul 2014, 10:03

RE: RE: RE:

Invalid said:

Thank Invalid,

is the EMA codes and variables different from using SMA?

 

Hi. May by next could help to get an idea

        private SimpleMovingAverage sma;

        protected override void OnStart()
        {
            sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 14);
        }

        protected override void OnBar()
        {
            if (MarketSeries.Close.Last(1) < sma.Result.Last(1))
                ClosePosition(_position);
        }

 

hiba7rain said:

modarkat said:

 

hey modarkat

thank you for the comment, I have a question with regards to using bars, is it possible to close opened position if for example the bar value became less than for example moving average?

if yes how to do it?

thanks

here you go:

        int GetBarsAgo(Position position)
        {
            for (var i = MarketSeries.OpenTime.Count - 1; i >= 0; i--)
            {
                if (position.EntryTime > MarketSeries.OpenTime[i])
                    return MarketSeries.OpenTime.Count - 1 - i;
            }
            return -1;
        }

        protected override void OnTick()
        {
            var barsAgo = GetBarsAgo(position);

            if (barsAgo > 5)
            {
                ClosePosition(position);
            }
        }

 

 

 

 


@hiba7rain

hiba7rain
21 Jul 2014, 00:24

RE:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

 

Hi Spotware, 

what could be wrong with the following , my intention to create  two different methods to close position one is via stop loss parameter and other by value of ask price against EMA

is it possible to do so? if yes how to?

private void Open(TradeType tradType)
        {

            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "calgoo", StopLossInPips, TakeProfitInPips);
            Print(LastResult.Position.TradeType);
        }


        private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);

            }

            if (ema1.Result.LastValue > Symbol.Ask)
            {
                Close();
            }

        } 

 


@hiba7rain

hiba7rain
20 Jul 2014, 20:24

RE:

MRSV said:

Add this to you code

private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);
            }
        }

 

And when you want to close a position add Close()

Like this:

If(SMA.Result.LastValue > 1)

Close();

Hope it helped

I did as you mentioned but still the positions are closed on the stop loss parameter

any suggestions?


@hiba7rain

hiba7rain
20 Jul 2014, 19:42

RE:

MRSV said:

Add this to you code

private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);
            }
        }

 

And when you want to close a position add Close()

Like this:

If(SMA.Result.LastValue > 1)

Close();

Hope it helped

Thanks 

but do you mean I have to add if (EMA.Result.LastValue > 1) 

Close(0; 

in place of ClosePosition(position);


@hiba7rain

hiba7rain
20 Jul 2014, 14:06

RE:

modarkat said:

 

hey modarkat

thank you for the comment, I have a question with regards to using bars, is it possible to close opened position if for example the bar value became less than for example moving average?

if yes how to do it?

thanks

here you go:

        int GetBarsAgo(Position position)
        {
            for (var i = MarketSeries.OpenTime.Count - 1; i >= 0; i--)
            {
                if (position.EntryTime > MarketSeries.OpenTime[i])
                    return MarketSeries.OpenTime.Count - 1 - i;
            }
            return -1;
        }

        protected override void OnTick()
        {
            var barsAgo = GetBarsAgo(position);

            if (barsAgo > 5)
            {
                ClosePosition(position);
            }
        }

 

 


@hiba7rain