Topics
20 Jul 2018, 22:20
 1255
 1
02 Jul 2018, 12:25
 2690
 4
22 Mar 2018, 17:18
 1473
 5
06 Jan 2018, 13:53
 2171
 4
05 Jul 2016, 18:57
 2942
 3
09 Mar 2016, 17:25
 3141
 3
01 Aug 2015, 15:06
 3143
 3
Replies

tradermatrix
03 May 2015, 21:22

RE:

mindbreaker said:

double earn = 0; foreach (var pos in Positions){ if (pos.TradeType == TradeType. Buy){ earn+= pos.GrosProfit; } } if (earn> 100){ foreach (var posin Positions){ ClosePosition (pos); } }

thank you
I find this error; GrosProfit;
 

   {


            double earn = 0;
            
            foreach (var pos in Positions)
            {
                if (pos.TradeType == TradeType.Buy)
                {
                    earn += pos.GrosProfit;

                }
            }
            if (earn > 100)
            {
                foreach (var pos in Positions)
                {
                    ClosePosition(pos);
                }
            }

        }

Error CS1061: 'cAlgo.API.Position' does not contain a definition for 'GrosProfit' and no extension method 'GrosProfit' accepting a first argument of type 'cAlgo.API.Position' could be found (are you missing a using directive or an assembly reference?)

have you an idea of the problem?
 thank you in advance

 

 


@tradermatrix

tradermatrix
29 Apr 2015, 12:38

RE:

hypertrader said:

Wow tradermatrix, thanks a lot. Multiplier feature is a great added bonus too.

Works really well in a volatile market and with support/resistance. Means I can get my life back instead of staring at a screen.

Do you have a paypal email, I'd like to send you a gift.

 

Kindest Regards

 

Andy

Andy hello
I am glad that this robot suits you.
my paypal email address is in my profile.
I have tested the robot last night in the demo, the idea is good, and I'll use the real account.
cordially
Marc


@tradermatrix

tradermatrix
28 Apr 2015, 22:49

RE:

hypertrader said:

Hi, I think this will be a Martingale type robot.

 

When I start the robot I want to be able to choose buy/sell, volume and TP/SL.

 

Take for example a 10K buy order with 30 pip SL and 30pip TP.

If TP is reached I want the robot to take no further action.

 

If SL is hit I want the robot to open a double volume in the opposite direction. (eg 20K sell with 30pip SL and 30pip TP.)

I want this to repeat doubling until TP is finally reached.

 

Any ideas peeps?

 

Andy

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 Martingaleinverse : Robot
    {

        [Parameter("Start Buy ", DefaultValue = false)]
        public bool Buy { get; set; }

        [Parameter("Start Sell ", DefaultValue = true)]
        public bool Sell { get; set; }

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

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

        [Parameter("Stop Loss", DefaultValue = 40)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 40)]
        public int TakeProfit { get; set; }


        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            buy();
            sell();
        }
        private void buy()
        {

            if (Buy == true)

                ExecuteOrder(InitialVolume, TradeType.Buy);

        }
        private void sell()
        {
            if (Sell == true)

                ExecuteOrder(InitialVolume, TradeType.Sell);


        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "X.inverse", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }


        private void OnPositionsClosed(PositionClosedEventArgs args)
        {



            Print("Closed");
            var position = args.Position;

            if (position.Label != "X.inverse" || position.SymbolCode != Symbol.Code)
                return;

            if (position.Pips > 0)

                Stop();


            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, position.TradeType);


            }


            else
            {

                ExecuteOrder((int)position.Volume * Multiplier, position.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy);


            }
        }
    }
}
 



bon trade


@tradermatrix

tradermatrix
21 Apr 2015, 15:47

RE: RE:

mindbreaker said:

tradermatrix said:

hello
for a robot I use this method to cut my positions (a total gains):

 

   [Parameter(DefaultValue = 30)]
    public double totalgains { get; set; }

  var netProfit = 0.0;


            foreach (var openedPosition in Positions)
            {

                netProfit += openedPosition.NetProfit + openedPosition.Commissions;

            }

          if (Math.Abs(netProfit) >= totalgains)


                if (netProfit >= totalgains && totalgains != 0)
                {

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

/////////////////////////////////////////////////////////////////////

in this method it cut all the buy and sell positions.
I would like a method that separately cut a total buy and sell total.

  [Parameter(DefaultValue = 30)]
    public double totalBuy { get; set; }

  [Parameter(DefaultValue = 30)]
    public double totalSell { get; set; }

 

thank you for your help
cordially

 

Hi,

 

if(openedPosition.TradeType.Buy){

// todo with buy positions

}else{

// todo with sell positions

}

 

Bye.

thank you
You can develop your idea by using my example because malgres your explanation I have a hard time implementing it.
cordially.


@tradermatrix

tradermatrix
14 Apr 2015, 20:15

RE:

eric said:

CALGO the Martingale strategy regardless of winning or losing, I hope are random orders, which is suppose to lose, he is still under the hand of doubling the number of orders, but the BUY / SELL random  can anybody  do this for me?? plz 

In other words, I want it to follow the Martingale strategy, once lost to redouble their value, but always random, assuming that buy order lost, than random, sell order lost is random too.

 

The following is Martin Heidegger policy C # program, in which part do I modify it?

I am Taiwanese, my English is not very good if the expression is unclear interesting again I wish to express

 

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This robot 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
//
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Martingale Robot" creates a random Sell or Buy order. If the Stop loss is hit, a new 
//    order of the same type (Buy / Sell) is created with double the Initial Volume amount. The robot will 
//    continue to double the volume amount for  all orders created until one of them hits the take Profit. 
//    After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount.
//
// -------------------------------------------------------------------------------------------------

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 40)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 40)]
        public int TakeProfit { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialVolume, GetRandomTradeType());
        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

change;

ExecuteOrder((int)position.Volume * 2, position.TradeType);

par;

 ExecuteOrder(position.Volume * 2, GetRandomTradeType());

 


@tradermatrix

tradermatrix
25 Mar 2015, 21:09

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SP500 : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

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

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

        [Parameter(DefaultValue = 3, MinValue = 0)]
        public int Volume { get; set; }

        [Parameter("Take Profit", DefaultValue = 300)]
        public int TakeProfit { get; set; }

        [Parameter("Stop Loss", DefaultValue = 40)]
        public int StopLoss { get; set; }

        [Parameter("Counter TP", DefaultValue = 300, MinValue = 10)]
        public int TakeProfitCounter { get; set; }

        [Parameter("Counter SL", DefaultValue = 40, MinValue = 0)]
        public int StopLossCounter { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;

        private const string label = "A2-1";
        private const string label2 = "counter";



        protected override void OnStart()
        {
            fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
            Positions.Opened += OnPositionsOpened;


        }

        protected override void OnBar()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            var lastIndex = SourceSeries.Count - 1;
            var valueClose = SourceSeries[lastIndex];



            if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLoss, TakeProfit);
            }
            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, StopLoss, TakeProfit);
            }

            //CLOSE POSITIONS******

            if (shortPosition != null && currentSlowMa <= currentFastMa && previousSlowMa > previousFastMa)
            {

                ClosePosition(shortPosition);
                //Stop();
            }
            else if (longPosition != null && currentSlowMa >= currentFastMa && previousSlowMa < previousFastMa)
            {

                ClosePosition(longPosition);
                //Stop();
            }

        }


        void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            var originalPosition = args.Position;
            if (originalPosition.Label == label)
            {
                var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
                ExecuteMarketOrder(tradeType, Symbol, originalPosition.Volume, label2, StopLossCounter, TakeProfitCounter);
            }
        }

    }
}



 


@tradermatrix

tradermatrix
22 Mar 2015, 21:59

RE:

cjdduarte said:

I have 2 robots. An optimized only to buy and the other just optimized to sell.
How are robots with different parameters, eventually happens the two buy / sell at the same time.

How do I get both to recognize and when a sell another wait to buy and vice versa?

did you try to give the same label your two robots ?

 


@tradermatrix

tradermatrix
27 Feb 2015, 13:39

RE:

Ian_Drummond said:

I'll be happy to share the code once it's developed, it's still full of comments and unused snippets at the minute....

Right now I'd just like to know if anyone has produced similar results and had to abandon development for some reason that I haven't factored in...?

For example, in the results chart you can see that up to 130 trades can be open at a time... Does anyone have any thoughts on this type of exposure?

 

hi and congratulations
can not you space the trades by modifying the code ..?
for example by adding "TradeDelay" or a timer or by spacing the trades of X pips.Il there would be fewer trades open for a good result as well as less risk.
best regards


@tradermatrix

tradermatrix
16 Dec 2014, 13:52

RE:

Alexander thank you
 I will optimize and configure all my robots according tick data.
 but with the indices optimization tick data does possible on - 2 months ...
 in real account  I' have found that  ICMarket offering the indices.
I note that the robots are performing with the indices ..
 best regards

 

 


@tradermatrix

tradermatrix
29 Nov 2014, 20:36

RE: RE:

did you find a solution ....?
 I have modified the code but the problem remains.
 best regards

Can I assume that this stock response means that the problem is with the code / logic at our end?

I understand that SpotWare can't spend their time fixing everyones code but it would be good to be reassured that there are no bugs in multi time frame backtesting / optimisation that cause this issue...

 

 

 

 


@tradermatrix

tradermatrix
24 Nov 2014, 19:16

RE: RE:

I understood my mistake
 replace;

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

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

@tradermatrix

tradermatrix
24 Nov 2014, 18:31

RE:

Spotware said:

I want to understand.
adjustment of the timer changes on a simple robot. (Timer detached from the graph)
the basketing and optimization are different ...
kind regards

EXEMPLE

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


[Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)]
public int StopLoss { get; set; }

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

private RelativeStrengthIndex rsi;

protected override void OnStart()
{
var _m30_series = MarketData.GetSeries(TimeFrame.Minute30);
rsi = Indicators.RelativeStrengthIndex(_m30_series.Close, 14);



}

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

 

 

 

 

 

 


@tradermatrix

tradermatrix
24 Nov 2014, 18:29

RE: RE:

I want to understand.
 adjustment of the timer changes on a simple robot. (Timer detached from the graph)
 the basketing and optimization are different ...
 kind regards

EXEMPLE

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


        [Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)]
        public int StopLoss { get; set; }

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

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            var _m30_series = MarketData.GetSeries(TimeFrame.Minute30);
            rsi = Indicators.RelativeStrengthIndex(_m30_series.Close, 14);



        }

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

 

 

 

 

 


@tradermatrix

tradermatrix
23 Nov 2014, 23:42

RE:

hello
 I think I have made improvements
 I have worked on the code but I still have the same problem;
 optimization impossible!
 can be an answer and a solution of SpotWare

continued success...

Well I'm completely stumped!

Can anyone from SpotWare offer any insight?

 


@tradermatrix

tradermatrix
22 Nov 2014, 22:38

RE: RE: RE: RE: RE:

ok, I have noticed that;  [Parameter("SI Limit Move", DefaultValue = 12)]
        public int LimitMove { get; set; }.

 DefaultValue = 12 or 120....no difference (error?)

also ;

 [Parameter("Ten MA Periods", DefaultValue = 150)]
        public int TenMAPeriods { get; set; }  ......... not active

to be activated;

add on

  if (Positions.Count < LimitPositions && Symbol.Ask > top && rsi.Result.LastValue < highRSI && triL > TrueRangeLimit && siCurrent > siLast && FortyFiveMa > DailyMa && TenMa >DailyMa)

  else if (Positions.Count < LimitPositions && Symbol.Bid < bottom && rsi.Result.LastValue > lowRSI && triL > TrueRangeLimit && siCurrent < siLast && FortyFiveMa < DailyMa &&  TenMa <DailyMa)

on all relevant lines...

 

 

 

 

 

 

 

 


@tradermatrix

tradermatrix
22 Nov 2014, 18:33

RE: RE: RE:

watching parameter by parameter
 the problem is daily
 by changing the code or by regulating   [Parameter ("Daily MA Periods" DefaultValue = 1)]
 everything returns to normal
 can you look?
 

 

 

 

 


@tradermatrix

tradermatrix
22 Nov 2014, 16:16

RE: RE:

keeping the same parameters (at 1 January 2014 to 5 minutes).
 Total trades 815 (backtesting)
 Total trades 377 (optimization)
 I do not understand

Thank you Tradermatrix...

Both are set to m1 bars from Server (open prices)... Could it be that my robot uses Close prices for Moving Average calculations and that could be messing with results?!?

 

tradermatrix said:

optimization setting that you choose, data: tick data  or m1 bar from server ?
make sure to use the same choice for optimization and backtesting.

 

 


@tradermatrix

tradermatrix
22 Nov 2014, 15:03

optimization setting that you choose, data: tick data  or m1 bar from server ?
make sure to use the same choice for optimization and backtesting.


@tradermatrix

tradermatrix
14 Nov 2014, 15:34

RE:

tradermatrix said:

no solution?

hello
 I have need your help to improve my robots.
 I am using a method of time to space trades.
 look at this example on this sample, the robot rule 1 minute.
 spacing trades = 1440 bars is 1440 minutes. Only after this time a trade can be opened.
 but it is possible that even after a long time space open trades have almost identical prices.
 c is why I want to replace this method with another.
 can you help me with my shopping space in pips (> + or - 30 pips).
 for example if the last trade Buy euro is 1.2500, the indicator accept the trade buy> 1.2530 ... <1.2470.
 I promise to post a profitable robot.
 kind regards

EURO/USD 1 Minute.

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Linq;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BB : Robot
    {
        const string Label = "BB";

        [Parameter(DefaultValue = 30)]
        public int Period { get; set; }

        [Parameter(DefaultValue = 2.5)]
        public double StandardDeviation { get; set; }

        [Parameter(DefaultValue = MovingAverageType.TimeSeries)]
        public MovingAverageType MAType { get; set; }

        [Parameter("Spacing Trades (X bars)", DefaultValue = 1440, MinValue = 0)]
        public int SpacingTrades { get; set; }

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

        [Parameter(DefaultValue = 80)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 80)]
        public int TakeProfit { get; set; }

        //////////////////////////////////////////////////////////////////////////////////////

        private TradeType _lastTradeType;
        private BollingerBands bb;
        private int Count = 0;

        protected override void OnStart()
        {

            bb = Indicators.BollingerBands(MarketSeries.High, Period, StandardDeviation, MAType);

        }


        protected override void OnBar()
        {

            Count++;
            var index = MarketSeries.Close.Count - 2;
            var position = Positions.Find(Label);

            if (Count > SpacingTrades && MarketSeries.Close[index] > bb.Top[index] && MarketSeries.Close[index - 1] <= bb.Top[index - 1] && _lastTradeType != TradeType.Sell)
            {

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, Label, StopLoss, TakeProfit);

                _lastTradeType = TradeType.Sell;

                Count = 0;
            }
            if (Count > SpacingTrades && MarketSeries.Close[index] < bb.Bottom[index] && MarketSeries.Close[index - 1] <= bb.Bottom[index - 1] && _lastTradeType != TradeType.Buy)
            {

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, Label, StopLoss, TakeProfit);

                _lastTradeType = TradeType.Buy;

                Count = 0;
            }
        }
    }
}

 


@tradermatrix

tradermatrix
30 Oct 2014, 11:50

RE:

AlexanderRC said:

You can compare EntryPrice of an opened position with Symbol.Bid or Symbol.Ask. To get the difference in pips you have to divide the delta between the two by Symbol.PipSize.

hello 
have an example in writing?


@tradermatrix