Need a bit of code for robot

Created at 10 Dec 2013, 15:53
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RC

rcc25

Joined 04.01.2013

Need a bit of code for robot
10 Dec 2013, 15:53


hi all if somebody can help me i need a bit of code 

that makes trade every 50 pips for example or  with parameter "range" so  i could setup distance between trades

now i will explain what i want

robot starts makes trade ( tradesize adjustable)  for example buy (can choose)

then when price move 50 pips positive open another trade same size same type but do not close the first one  

it would be nice if i could change that 50 pips range in robot settings

 

thx sorry for my english

 

RAF


@rcc25
Replies

rcc25
13 Dec 2013, 16:14

hi again

nobody can help me?

just need a code which opens trade every 50 pips for example

or just point me how i can code it
 


@rcc25

adaled
13 Dec 2013, 16:39

Hi you can start with this

 

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class StarterRobot : Robot
    {
        [Parameter(DefaultValue = 50.0)]
        public double PipsDistance { get; set; }

        [Parameter(DefaultValue = true)]
        public bool TradeTypeBuy { get; set; }

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

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

        [Parameter(DefaultValue = 100)]
        public double StopLossPips { get; set; }

        protected TradeType TradeType
        {
            get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; }
        }

        protected override void OnStart()
        {
            // Put your initialization logic here
            var result = ExecuteMarketOrder(TradeType, Symbol, Volume, Label, StopLossPips, null);
            if (!result.IsSuccessful)
            {
                Print("Error {0} Stopping Robot", result.Error);
                Stop();
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
            var positions = Positions.FindAll(Label, Symbol, TradeType);
            if (positions.Length == 0)
                return;

            var position = positions[positions.Length - 1];
            if ((position.TradeType == TradeType.Buy && Symbol.Bid - position.EntryPrice >= PipsDistance * Symbol.PipSize)
                || (position.TradeType == TradeType.Sell && position.EntryPrice - Symbol.Ask >= PipsDistance * Symbol.PipSize))
            {
                TradeResult result = ExecuteMarketOrder(TradeType, Symbol, Volume, Label, StopLossPips, null);
                if (!result.IsSuccessful)
                {
                    Print("Error {0} Stopping Robot", result.Error);
                    Stop();
                }
            }
        }

    }
}

 


@adaled

rcc25
13 Dec 2013, 17:55

thx mate very much !!!

works perfect

 i will add take profit for all positions

that is what i was looking for

i owe you

thx RAF 
 


@rcc25