Topics
20 Jul 2018, 22:20
 1182
 1
02 Jul 2018, 12:25
 2529
 4
22 Mar 2018, 17:18
 1375
 5
06 Jan 2018, 13:53
 2088
 4
05 Jul 2016, 18:57
 2860
 3
09 Mar 2016, 17:25
 3007
 3
01 Aug 2015, 15:06
 3061
 3
Replies

tradermatrix
10 May 2013, 21:07

 We can also (forum) enjoy this robot?
it would be useful to help us improve our understanding ...
cordially.


@tradermatrix

tradermatrix
30 Apr 2013, 01:54

hello
can be like this:

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

namespace cAlgo.Robots

        {
        
        [Robot]
        public class Bollinger : Robot
        
        {
        
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }
        
        [Parameter(DefaultValue = 56)]
        public int period { get; set; }
        
        [Parameter(DefaultValue = 2)]
        public double std { get; set; }
        
        [Parameter("Volume", DefaultValue = 100000, MinValue = 10000)]
        public int Volume { get; set; }
        
        [Parameter("Stop Loss", DefaultValue = 40)]
        public int StopLossInPips { get; set; }
        
        [Parameter("Take Profit", DefaultValue = 40)]
        public int TakeProfitInPips { get; set;}
        
        private BollingerBands bb;
        
        protected override void OnStart()
        {
            bb = Indicators.BollingerBands(Source, period, std, MAType);
        }

        protected override void OnTick()
        
        {
        
        if (Trade.IsExecuting) return;
            
        if (bb.Top.LastValue < Symbol.Bid)
            
        {
            
        OpenPosition(TradeType.Sell);
        
        }
            
        else if (bb.Bottom.LastValue > Symbol.Ask)
            
        {
            
        OpenPosition(TradeType.Buy);
        
        }
        }
        
        private void OpenPosition(TradeType tradeType)
        
        {
        
        foreach (var position in Account.Positions)
        
        {
        
        if (position.Label == "Bollinger" && position.TradeType != tradeType)
        
        {
        
        Trade.Close(position);
        
        }
        }
        
        bool hasNeededPosition = Account.Positions.Any(position => position.Label == "Bollinger" && position.TradeType == tradeType);
        
        if (!hasNeededPosition)
        
        {
        
        var request = new MarketOrderRequest(tradeType, Volume)
        
        {
                         Label = "Bollinger",
                    StopLossPips = StopLossInPips,
                   TakeProfitPips = TakeProfitInPips
                   
         };

                           Trade.Send(request);
         }
            }
               }
                  }

 


@tradermatrix

tradermatrix
19 Apr 2013, 13:28

salut atrader

thank you very much,
I have thought I was crazy.


you are great !!! and generous ..


for that it works in differente currencies (without antagonizing) simply duplicate the robot and change the name;
for example EUR / USD:

[Parameter (DefaultValue = "Forex")]
public string LabelName {get; set;}

for USD / CHEF:

[Parameter (DefaultValue = "Forex2")]
public string LabelName {get; set;}

multiple robots can now work together.

this robot is now quite complete:
protection funds with "chekbalance"
and a "label" ...

 

good trade.

 

 


@tradermatrix

tradermatrix
17 Apr 2013, 12:03

bonjour,

Dans la journée ou en soirée je partagerais mon "scalper programmable".

Il fonctionne avec un déclencheur(trigger) et un stop suiveur(trailing stop).

Vous aurez le choix pour la stratégie . 

Vous pourrez l améliorer  selon vos désirs.

Je dois m absenter un moment.

@+


@tradermatrix

tradermatrix
07 Apr 2013, 12:21

RE:
lec0456 said:

Yup, its almost the same:

if(Account.PendingOrders.Count>2)



merçi beaucoup.

if(Account.PendingOrders.Count < 2)

bonne chance 

cordialement


@tradermatrix

tradermatrix
26 Mar 2013, 11:46

yes, C is for this robot.
C is by seeking a method to reverse the direction of the work of robot 2 and to work with 1 robot purchase and 1 robot sale or to bind the 2 robots in only one robot.
I am redu account that if I Copis the robot and that I regulate the orders
with L identical, robot 2 refuses to function.
the first neutralizes the identical robots.
all the other robots and all my robots can beings copied and to work together except robot forex
I do not understand why I cannot work with 2 identical robots forex.
there must be a writing (in robot forex) which prevents that.

cordialement


@tradermatrix

tradermatrix
28 Feb 2013, 12:48

thank you very much

c is much better now


@tradermatrix

tradermatrix
24 Jan 2013, 18:48

this formula closes all the positions (buy and sell) when the balance is negative:


if( Account.Equity - Account.Balance < - 10 )
{
foreach (var position in Account.Positions)
{
Trade.Close(position);
}
}
}
}
}

exemple

EXEMPLE RANGE ROBOT(or another robot)

ID Heure Symbole Volume Type Entrée T/P S/L Pips Swap Commissions EUR
195826 03/09/2012 14:39 EURUSD 10k Sell 1.25745     -0.3 0.00 -0.30 -0.24
195833 03/09/2012 14:42 EURUSD 10k Sell 1.25745     -0.3 0.00 -0.30 -0.24
195862 03/09/2012 15:15 EURUSD 10k Buy 1.25682     5.8 0.00 -0.30 4.61
195875 03/09/2012 15:21 EURUSD 10k Buy 1.25709     3.1 0.00 -0.30 2.47
195899 03/09/2012 15:51 EURUSD 10k Buy 1.25702     3.8 0.00 -0.30 3.02
195945 03/09/2012 16:28 EURUSD 10k Sell 1.25692     -5.6 0.00 -0.30 -9.45
195955 03/09/2012 16:36 EURUSD 20k Sell 1.25692     -5.6 0.00 -0.60 -8.91
195962 03/09/2012 16:41 EURUSD 10k Buy 1.25694     4.6 0.00 -0.30 3.66
195965 03/09/2012 16:44 EURUSD 20k Buy 1.25698     4.2 0.00 -0.60 6.68
195982 03/09/2012 16:49 EURUSD 10k Buy 1.25696     4.4 0.00 -0.30 -13.50
196035 03/09/2012 17:21 EURUSD 10k Sell 1.25742     -0.6 0.00 -0.30 -0.48

p&L= -10

when P & L =  -10, all positions are automatically sold

what I want:
a formula which adds only the negative positions.
and then, when the total (losing trade)) = - 500 euros is counted, all the losing positions are liquidated.
there thus remain the positive positions which continue to fluctuate  

thank you


@tradermatrix

tradermatrix
23 Jan 2013, 19:24

RE:
admin said:

It looks like the problem may be in the rest of the code.

If you have two positions or more open simultaneously then you need to use a list to store multiple positions. See list sample. Using one global field position will work only with one position open at a time.

Alternatively if your code has only two positions opened at a time, you may use two global fields one for sell and one for buy. Then you will need to check the TradeType in the OnPositionOpened and OnPositionClosed methods to assign the correct position object (from the parameter) to the corresponding global position field.

protected override void OnPositionOpened(Position openedPosition)
{
    if (openedPosition.TradeType == TradeType.Buy)
        _buyPosition = openedPosition;
    else
        _sellPosition = openedPosition;
}

protected override void OnPositionClosed(Position closedPosition)
{
    if (closedPosition.TradeType == TradeType.Buy)
        _buyPosition = null;
    else
        _sellPosition = null;
}

You would also have to adjust the rest of the code to replace the one field position using the same logic.

Let us know if you require additional help.

 

 

 

merci phamvanthanh et admin


I managed to create a good trailing stop on my robots.
guiding me with:
/forum/calgo-reference-samples/56
and also this very simple example of use (add robots):
/algos/show/134

thank you for your help ...

cordially.

 

 


@tradermatrix

tradermatrix
11 Jan 2013, 18:53

thank you
but it does not work
the robot refuse:

{Sell trailing stop block}

else

{Buy trailing stop block

but it is possible that I developed bad the rest.
cordially


@tradermatrix

tradermatrix
11 Jan 2013, 18:17

thank you Attrader
but there is a small error (backtest)
the robot works one day.
I would add more Buy (add to Sell)

 

Trade.CreateBuyStopOrder(Symbol, Volume, sellOrderTargetPrice,
                                              BuyOrderTargetPrice + StopLoss*Symbol.PipSize,
                                              BuyOrderTargetPrice - TakeProfit*Symbol.PipSize);

merci de votre aide.

 


@tradermatrix

tradermatrix
11 Jan 2013, 13:51

hello
I want to find the formula to ask orders one after the other (OnTick) every hour (or every hours 2,3.4)
continuously operating the robot every day.

for example;

protected override void OnTick ()

          {

"if ((int) Server.Time.Hour" ....................??? (or other solutions)
{
var = sellOrderTargetPrice Symbol.Bid - Symbol.PipSize;
                     Trade.CreateSellStopOrder (Symbol, Volume, sellOrderTargetPrice,
                         sellOrderTargetPrice + StopLoss * Symbol.PipSize, sellOrderTargetPrice - TakeProfit * Symbol.PipSize);

 

thank you for your help

cordially.

 


@tradermatrix

tradermatrix
07 Dec 2012, 13:37

RE:
admin said:

Thank you for the suggestion.  We will provide that option in the near future. Stay tuned!

 


hello
yes it is urgent to disable these notifications.
during the execution of trades and rapid multiple
the notifications hinders vision of the screen.
they eat a lot more virtual memory and slow down the execution of orders.
thank you in advance to consider this request.
cordially
 

@tradermatrix

tradermatrix
25 Oct 2012, 15:05

yes .. yes ...!!. c is what I've done on the robot.
c is a mistake on my previous message .. (I had not yet taken the vitamins !!)
thank you again ....

 

Tradermatrix


@tradermatrix

tradermatrix
25 Oct 2012, 12:52

ho ..! I understood my stupidity ...!

thank you very much for your patience

In fact,
if:
 
protected override void OnPositionClosed (Position closedPosition)
{
if (closedPosition.Volume% InitialVolume == 0)
...................................
................................
then:

  protected override void OnPositionOpened (Position openedPosition)
{
if (closedPosition.Volume% InitialVolume == 0)
.....................................
..................................

c is simple !!


I must be tired ...


I run to the pharmacy to buy vitamins and drugs.

Then, I'll try to build an infernal machine ....

 

tradermatrix


@tradermatrix

tradermatrix
24 Oct 2012, 17:14

hello
I have always the same problem
when stoploss (= 10) is executed it becomes stoplossInPips = 5
see you soon


@tradermatrix

tradermatrix
23 Oct 2012, 15:42

hello
the system works for TakeProfit and takeprofitInPips.
when trade is positive (green).

but when stoploss is executed. stoploss is reversed.
it becomes stoplossInPips.

eg

[Parameter ("StopLoss", DefaultValue = 10)]
public intStopLoss {get; set;}

[Parameter ("Take Profit", DefaultValue = 5)]
public intTakeProfitInPips {get; set;}


when stoploss (= 10) is executed it becomes stoplossInPips = 5

the statégie is thus lost.

thank you
__________________________________________________________________________

PAR EXEMPLE

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

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

        [Parameter("Take Profit", DefaultValue = 10)]
        public int TakeProfit { get; set; }
        [Parameter(" Volume", DefaultValue = 1000, MinValue = 0)]
        public int Volume { get; set; }
       
        [Parameter("Stop LossInPips", DefaultValue = 5)]
        public int StopLossInPips { get; set; }

        [Parameter("Take ProfitInPips", DefaultValue = 5)]
        public int TakeProfitInPips { get; set; }

      
        private Position position;

        protected override void OnStart()
       {
          
         ExecuteOrder(InitialVolume,TradeType.Buy );

   
       ExecuteOrder(InitialVolume, TradeType.Sell );

     
      
     ExecuteOrder(Volume,TradeType.Buy );

   
       ExecuteOrder(Volume, TradeType.Sell );
          
           
        }
 
     private void ExecuteOrder(int volume, TradeType tradeType)
        {
            Trade.CreateMarketOrder(tradeType, Symbol, volume);
           

        }
       
       protected override void OnPositionClosed(Position closedPosition)
       {
      // closedPosition.Volume is a multiple of InitialVolume
     
     
             if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero

{

           

 

                if (closedPosition.GrossProfit > 0)

 

                {

 

                    ExecuteOrder(InitialVolume, closedPosition.TradeType);

 

                }

 

                else

 

                {

 

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

 

                }

 

            }

 

            else // closedPosition.Volume is a multiple of Volume

 

            {

 

                if (closedPosition.GrossProfit > 0)

 

                {

 

                    ExecuteOrder(Volume, closedPosition.TradeType);

 

                }

 

                else

 

                {

 

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

 

                }

}

            }


        
           protected override void OnPositionOpened(Position openedPosition)
        {
            if (openedPosition.Volume == InitialVolume)
            {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize,
                                         Symbol.Ask + TakeProfit*Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize,
                                         Symbol.Bid - TakeProfit*Symbol.PipSize);
               

           
            }
            else
             {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLossInPips* Symbol.PipSize,
                                         Symbol.Ask +TakeProfitInPips * Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid +StopLossInPips * Symbol.PipSize,
                                         Symbol.Bid - TakeProfitInPips * Symbol.PipSize);
              }
            position = openedPosition ;

         }
       
}       
 }      
   

 


@tradermatrix

tradermatrix
23 Oct 2012, 15:30

RE:
admin said:

Hello again,


Do you need to differentiate if the closed position volume is a multiple of InitialVolume or a multiple of Volume?

If so, then:

 

            // closedPosition.Volume is a multiple of InitialVolume

 

            if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero

 

            {

 

                if (closedPosition.GrossProfit > 0)

 

                {

 

                    ExecuteOrder(InitialVolume, closedPosition.TradeType);

 

                }

 

                else

 

                {

 

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

 

                }

 

            }

 

            else // closedPosition.Volume is a multiple of Volume

 

            {

 

                if (closedPosition.GrossProfit > 0)

 

                {

 

                    ExecuteOrder(Volume, closedPosition.TradeType);

 

                }

 

                else

 

                {

 

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

 

                }

 

            }

 

The above code will work if InitialVolume = 10000 and Volume == 1000

If you modify these two variables, i.e. InitialVolume = 2000 and Volume == 1000 then the logic will fail. 

If you want to have the flexibility of adjusting the volume parameter to any value then I suggest using two different robots.

 

 

 


@tradermatrix

tradermatrix
22 Oct 2012, 12:56

hello

to build a robot progressive, I need to first:


combine two or more martingales (payback).
but with volumes (and takeprofit and stoploss) different.


for example, two martingales:

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

[Parameter("StopLoss",DefaultValue =20)]
public intStopLoss{get;set;}

[Parameter ("Take Profit",DefaultValue =20)]
public intTakeProfit{get;set;}

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

[Parameter("StopLoss",DefaultValue = 10)]
public intStopLossInPips{get;set;}

[Parameter ("Take Profit",DefaultValue = 10)]
public intTakeProfitInPips{get;set;}

privatePositionposition;


protected override void OnStart()
{

ExecuteOrder(InitialVolume, TradeType.Sell);
ExecuteOrder(InitialVolume, TradeType.Buy);

ExecuteOrder(Volume, TradeType.Sell);
ExecuteOrder(Volume, TradeType.Buy);

}

private void ExecuteOrder(int volume, TradeType tradeType)
        {
            Trade.CreateMarketOrder(tradeType, Symbol, volume);
           
        }
 protected override void OnPositionOpened(Position openedPosition)
        {
            if (openedPosition.Volume == InitialVolume)
            {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize,
                                         Symbol.Ask + TakeProfit*Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize,
                                         Symbol.Bid - TakeProfit*Symbol.PipSize);
               
            }

            else
           
             {
            if (openedPosition.Volume == Volume)

             {
                if (openedPosition.TradeType == TradeType.Buy)
                    Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLossInPips* Symbol.PipSize,
                                         Symbol.Ask +TakeProfitInPips * Symbol.PipSize);

                else if (openedPosition.TradeType == TradeType.Sell)
                    Trade.ModifyPosition(openedPosition, Symbol.Bid +StopLossInPips * Symbol.PipSize,
                                         Symbol.Bid - TakeProfitInPips * Symbol.PipSize);
               
            }
             position = openedPosition ;
        }

______________________________________________________________________________________________________________

my problem  arises here.


to combine the two volumes.

 

so that the two martingales operate separately :

 

protected override void OnPositionClosed(Position closedPosition)
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume , closedPosition.TradeType);

[ ExecuteOrder(Volume , closedPosition.TradeType); ........??????]


}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}

________________________________________________________________________

thank you for your understanding


excuse me for my english very Approximate

 


@tradermatrix

tradermatrix
20 Oct 2012, 00:23

HI

c is practically impossible to execute orders at the point.
because there are differences toujour of executions on the market.
improve the result :


good computer equipment

Minimum RAM memory: 8 GB
for speed of execution,and reduce the gap.

after two or three days when the gap widens, I choose the right time to close the robot.

for example when the sequence returns to buy 10k and sell .

I sold my positions and I restart the robot.

good luck

  Heure d'entrée Symbole Volume Type Prix d'entrée T/P S/L Prix de Clôture Heure de Clôture Commissions Swap EUR
  /10/2012 07:27 EURUSD 10k Acheter 1.28761 1.28961 1.28561 1.28565 10/2012 09:36 -0.60 0.00 -15.24
  /10/2012 07:27 EURUSD 10k Vendre 1.28759 1.28559 1.28959 1.28559 10/2012 09:36 -0.60 0.00

15.55


@tradermatrix