Replies

t4fast
04 Oct 2013, 09:43

Hi !

thanks for your time and effort,
yes, code is working fine now , without any problems.


@t4fast

t4fast
02 Oct 2013, 21:23

RE:

fzlogic said:

You were probably logged in with different accounts. 

 

I am not. 

 


@t4fast

t4fast
01 Oct 2013, 23:48

HI

the Robot below, modifies the TP+SL and calculates the average price for the trades that are placed manually.

however, if i place orders from CTrader, it doesn't update/modify the open potions , unless, I move/switch the screen to cAlgo !!

is there a fix for it through coding? or it is not designed to do that ?!

 



// -------------------------------------------------------------------------------
//
//    Modify all TakeProfit and StopLoss by Average Price. "Aggressive Trading"
//    salr22@hotmail.com, www.borsat.net
//    AggressiveModifyPostions.v1
// -------------------------------------------------------------------------------


using System;
using cAlgo.API;



namespace cAlgo.Robots
{
    [Robot()]
    public class AggressiveModifyPostions : Robot
    {

        [Parameter("TakeProfit (pips)", DefaultValue = 10.0)]
        public int _takeProfit { get; set; }

        [Parameter("StopLoss (pips)", DefaultValue = 50.0)]
        public int _stopLoss { get; set; }

        [Parameter("TakeProfit_Buy (price)", DefaultValue = 0)]
        public double _takeProfitPrBuy { get; set; }

        [Parameter("StopLoss_Buy (price)", DefaultValue = 0)]
        public double _stopLossPrBuy { get; set; }

        [Parameter("TakeProfit_Sell (price)", DefaultValue = 0)]
        public double _takeProfitPrSell { get; set; }

        [Parameter("StopLoss_Sell (price)", DefaultValue = 0)]
        public double _stopLossPrSell { get; set; }


        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            double _avrgB = 0;
            double _avrgS = 0;
            double _lotsB = 0;
            double _lotsS = 0;

            double _tpB = 0;
            double _slB = 0;
            double _tpS = 0;
            double _slS = 0;

            // get average 
            foreach (var position1 in Account.Positions)
            {

                if (Symbol.Code == position1.SymbolCode)
                {

                    if (position1.TradeType == TradeType.Buy)
                    {
                        _avrgB = _avrgB + (position1.Volume * position1.EntryPrice);
                        _lotsB = _lotsB + position1.Volume;
                    }

                    if (position1.TradeType == TradeType.Sell)
                    {
                        _avrgS = _avrgS + (position1.Volume * position1.EntryPrice);
                        _lotsS = _lotsS + position1.Volume;
                    }

                }

            }

            _avrgB = Math.Round(_avrgB / _lotsB, Symbol.Digits);
            _avrgS = Math.Round(_avrgS / _lotsS, Symbol.Digits);

            string text = string.Format("{0}", "\n\n" + "Average Buy:  " + _avrgB + "\n\n" + "Average Sell:  " + _avrgS);
            ChartObjects.DrawText("avrg", text.PadLeft(10), StaticPosition.TopLeft, Colors.White);

            if (_takeProfit != 0)
            {
                _tpB = Math.Round(_avrgB + Symbol.PipSize * _takeProfit, Symbol.Digits);
                _tpS = Math.Round(_avrgS - Symbol.PipSize * _takeProfit, Symbol.Digits);
            }
            if (_stopLoss != 0)
            {
                _slB = Math.Round(_avrgB - Symbol.PipSize * _stopLoss, Symbol.Digits);
                _slS = Math.Round(_avrgS + Symbol.PipSize * _stopLoss, Symbol.Digits);
            }

            if (_takeProfitPrBuy != 0)
            {
                _tpB = _takeProfitPrBuy;
            }
            if (_stopLossPrBuy != 0)
            {
                _slB = _stopLossPrBuy;
            }
            if (_takeProfitPrSell != 0)
            {
                _tpS = _takeProfitPrSell;
            }
            if (_stopLossPrSell != 0)
            {
                _slS = _stopLossPrSell;
            }



            // modify 
            foreach (var position in Account.Positions)
            {
                if (Symbol.Code == position.SymbolCode && position.TradeType == TradeType.Buy)
                {
                    // md tp
                    if (_tpB != 0 && position.TakeProfit != _tpB)
                    {
                        Trade.ModifyPosition(position, position.StopLoss, _tpB);
                    }
                    if (_tpB == 0 && position.TakeProfit != _tpB)
                    {
                        Trade.ModifyPosition(position, position.StopLoss, null);
                    }

                    //md sl
                    if (_slB != 0 && position.StopLoss != _slB)
                    {
                        Trade.ModifyPosition(position, _slB, position.TakeProfit);
                    }
                    if (_slB == 0 && position.StopLoss != _slB)
                    {
                        Trade.ModifyPosition(position, null, position.TakeProfit);
                    }
                }



                if (Symbol.Code == position.SymbolCode && position.TradeType == TradeType.Sell)
                {

                    // md tp
                    if (_tpS != 0 && position.TakeProfit != _tpS)
                    {
                        Trade.ModifyPosition(position, position.StopLoss, _tpS);
                    }
                    if (_tpS == 0 && position.TakeProfit != _tpS)
                    {
                        Trade.ModifyPosition(position, position.StopLoss, null);
                    }


                    // md sl
                    if (_slS != 0 && position.StopLoss != _slS)
                    {
                        Trade.ModifyPosition(position, _slS, position.TakeProfit);
                    }
                    if (_slS == 0 && position.StopLoss != _slS)
                    {
                        Trade.ModifyPosition(position, null, position.TakeProfit);
                    }

                }

            }


        }

    }
}

 


@t4fast

t4fast
31 Aug 2013, 10:14

should i try the jobs sections ?

I would like to know if it is possible prior posting a job !


@t4fast