Topics
20 Jul 2018, 22:20
 1339
 1
02 Jul 2018, 12:25
 2879
 4
22 Mar 2018, 17:18
 1550
 5
06 Jan 2018, 13:53
 2252
 4
05 Jul 2016, 18:57
 3024
 3
09 Mar 2016, 17:25
 3262
 3
01 Aug 2015, 15:06
 3229
 3
Replies

tradermatrix
13 Sep 2015, 19:38 ( Updated at: 23 Jan 2024, 13:16 )

Hello
I already asked this question..et the answer here:

[/forum/calgo-support/6054]


cordially


@tradermatrix

tradermatrix
14 Aug 2015, 17:51

look what interests you ..

 

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

        [Parameter("One Cancels Other", DefaultValue = true)]
        public bool Oco { get; set; }

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

        [Parameter("distance pips", DefaultValue = 20)]
        public double PipsAway { get; set; }

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

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

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




        protected override void OnStart()
        {

            string text = "Ssalp By TraderMatriX";

            base.ChartObjects.DrawText("Scalp By TraderMatriX", text, StaticPosition.TopCenter, new Colors?(Colors.Lime));




            StopOrders();
            Positions.Closed += OnPositionsClosed1;
            Positions.Closed += OnPositionsClosed2;
            Positions.Opened += OnPositionOpened;



        }


        protected override void OnTick()
        {


            var netProfit = 0.0;


            foreach (var openedPosition in Positions)
            {

                netProfit += openedPosition.NetProfit + openedPosition.Commissions;


            }

            ChartObjects.DrawText("a", netProfit.ToString(), StaticPosition.BottomRight, new Colors?(Colors.Lime));

        }



        private void StopOrders()
        {


            var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;

            ChartObjects.DrawHorizontalLine("sell target", sellOrderTargetPrice, Colors.Lime, 1, LineStyle.Solid);

            PlaceStopOrder(TradeType.Sell, Symbol, InitialVolume, sellOrderTargetPrice, "Scalp", StopLoss, TakeProfit);



            var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;

            ChartObjects.DrawHorizontalLine("buy target", buyOrderTargetPrice, Colors.Lime, 1, LineStyle.Solid);

            PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, buyOrderTargetPrice, "Scalp", StopLoss, TakeProfit);




        }


        private void OnPositionsClosed1(PositionClosedEventArgs args)
        {



            if (StartAutomate3 == true)
            {


                Print("Closed");

                var position = args.Position;

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



                StopOrders();

            }

        }


        private void OnPositionsClosed2(PositionClosedEventArgs args)
        {

            if (StartAutomate3 == false)
            {


                Print("Closed");

                var position = args.Position;

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

        }


        private void OnPositionOpened(PositionOpenedEventArgs args)
        {

            if (Oco == true)
            {
                var position = args.Position;


                if (position.Label == "Scalp" && position.SymbolCode == Symbol.Code)
                {




                    foreach (var order in PendingOrders)
                    {

                        if (order.Label == "Scalp" && order.SymbolCode == Symbol.Code)
                        {
                            CancelPendingOrderAsync(order);

                            ChartObjects.RemoveObject("sell target");
                            ChartObjects.RemoveObject("buy target");


                        }

                    }

                }

            }

        }


    }
}




et aussi "FireBote" de  breakermind

/forum/cbot-support/1397

https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/FireBot

 

 

1 //================================================================================ 
2 //                                                                  SimpleWeekRobo 
3 // Start at Week start(Day start 00:00) 
4 // (M15-M30 regression(2000,2,3)(1.8,2,2000)) 
5 // 100Pips levels, suport or resistance 
6 // Simple Monday-Friday script without any security with close when earn 
7 // If CloseWhenEarn == 0 then dont close positions 
8 // If TP or SL == 0 dont modifing positions 
9 // If TrailingStop > 0  ==> BackStop == 0 
10 // Multi positions yes or no 
11 //================================================================================ 
12 using System; 
13 using cAlgo.API; 
14 using cAlgo.API.Indicators; 
15 using cAlgo.Indicators; 
16   
17 namespace cAlgo.Robots 
18 { 
19     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] 
20     public class Fire : Robot 
21     { 
22 //================================================================================ 
23 //                                                                    Parametrs 
24 //================================================================================ 
25   
26         private Position _position; 
27         private double WeekStart; 
28         private double LastProfit = 0; 
29         private double StopMoneyLoss = 0; 
30   
31         [Parameter(DefaultValue = true)] 
32         public bool SetBUY { get; set; } 
33   
34         [Parameter(DefaultValue = true)] 
35         public bool SetSELL { get; set; } 
36   
37         [Parameter(DefaultValue = 300000, MinValue = 1000)] 
38         public int Volume { get; set; } 
39   
40         [Parameter(DefaultValue = true)] 
41         public bool MultiVolume { get; set; } 
42   
43         [Parameter(DefaultValue = 10, MinValue = 5)] 
44         public int Spacing { get; set; } 
45   
46         [Parameter(DefaultValue = 30, MinValue = 1)] 
47         public int HowMuchPositions { get; set; } 
48   
49         [Parameter("TakeProfitPips", DefaultValue = 0, MinValue = 0)] 
50         public int TP { get; set; } 
51   
52         [Parameter("StopLossPips", DefaultValue = 0, MinValue = 0)] 
53         public int SL { get; set; } 
54   
55         [Parameter(DefaultValue = 0, MinValue = 0)] 
56         public int BackStop { get; set; } 
57   
58         [Parameter(DefaultValue = 5, MinValue = 0)] 
59         public int BackStopValue { get; set; } 
60   
61         [Parameter(DefaultValue = 0, MinValue = 0)] 
62         public int TrailingStop { get; set; } 
63   
64         // close when earn 
65         [Parameter(DefaultValue = 0, MinValue = 0)] 
66         public int CloseWhenEarn { get; set; } 
67   
68         // safe deposit works when earn 100% 
69         [Parameter(DefaultValue = false)] 
70         public bool MoneyStopLossOn { get; set; } 
71   
72         [Parameter(DefaultValue = 1000, MinValue = 100)] 
73         public int StartDeposit { get; set; } 
74   
75         [Parameter(DefaultValue = 50, MinValue = 10, MaxValue = 100)] 
76         public int StopLossPercent { get; set; } 
77   
78         [Parameter(DefaultValue = 2, MinValue = 1, MaxValue = 100)] 
79         public int OnWhenDepositX { get; set; } 
80   
81   
82         private int Multi = 0; 
83         private int VolumeBuy = 0; 
84         private int VolumeSell = 0; 
85 //================================================================================ 
86 //                                                                      OnStart 
87 //================================================================================ 
88         protected override void OnStart() 
89         { 
90             VolumeSell = Volume; 
91             VolumeBuy = Volume; 
92             WeekStart = Symbol.Ask; 
93   
94             // set pending up(BUY) 
95             if (SetBUY) 
96             { 
97                 for (int i = 1; i < HowMuchPositions; i++) 
98                 { 
99   
100                     Multi = Multi + Spacing; 
101                     if (MultiVolume == true) 
102                     { 
103                         if (Multi > 100) 
104                         { 
105                             VolumeBuy = VolumeBuy + Volume; 
106                         } 
107                         if (Multi > 200) 
108                         { 
109                             VolumeBuy = VolumeBuy + Volume; 
110                         } 
111                         if (Multi > 300) 
112                         { 
113                             VolumeBuy = VolumeBuy + Volume; 
114                         } 
115                     } 
116                     PlaceStopOrder(TradeType.Buy, Symbol, VolumeBuy, Symbol.Ask + Spacing * i * Symbol.PipSize); 
117                 } 
118             } 
119   
120             // set pending down(SELL) 
121             if (SetSELL) 
122             { 
123                 Multi = 0; 
124                 for (int j = 1; j < HowMuchPositions; j++) 
125                 { 
126   
127                     Multi = Multi + Spacing; 
128                     if (MultiVolume == true) 
129                     { 
130                         if (Multi > 100) 
131                         { 
132                             VolumeSell = VolumeSell + Volume; 
133                         } 
134                         if (Multi > 200) 
135                         { 
136                             VolumeSell = VolumeSell + Volume; 
137                         } 
138                         if (Multi > 300) 
139                         { 
140                             VolumeSell = VolumeSell + Volume; 
141                         } 
142                     } 
143                     PlaceStopOrder(TradeType.Sell, Symbol, VolumeSell, Symbol.Bid - Spacing * j * Symbol.PipSize); 
144                 } 
145             } 
146         } 
147   
148 //================================================================================ 
149 //                                                                       OnTick 
150 //================================================================================ 
151         protected override void OnTick() 
152         { 
153             var netProfit = 0.0; 
154   
155             // Take profit 
156             if (TP > 0) 
157             { 
158                 foreach (var position in Positions) 
159                 { 
160   
161                     // Modifing position tp 
162                     if (position.TakeProfit == null) 
163                     { 
164                         Print("Modifying {0}", position.Id); 
165                         ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TP)); 
166                     } 
167   
168                 } 
169   
170             } 
171   
172             // Stop loss 
173             if (SL > 0) 
174             { 
175                 foreach (var position in Positions) 
176                 { 
177   
178                     // Modifing position sl and tp 
179                     if (position.StopLoss == null) 
180                     { 
181                         Print("Modifying {0}", position.Id); 
182                         ModifyPosition(position, GetAbsoluteStopLoss(position, SL), position.TakeProfit); 
183                     } 
184   
185                 } 
186   
187             } 
188   
189   
190   
191             foreach (var openedPosition in Positions) 
192             { 
193                 netProfit += openedPosition.NetProfit; 
194             } 
195   
196             if (MoneyStopLossOn == true) 
197             { 
198                 // safe deposit works when earn 100% 
199                 if (LastProfit < Account.Equity && Account.Equity > StartDeposit * OnWhenDepositX) 
200                 { 
201                     LastProfit = Account.Equity; 
202                 } 
203   
204                 if (Account.Equity > StartDeposit * 3) 
205                 { 
206                     //StopLossPercent = 90; 
207                 } 
208   
209                 StopMoneyLoss = LastProfit * (StopLossPercent * 0.01); 
210                 Print("LastProfit: ", LastProfit); 
211                 Print("Equity: ", Account.Equity); 
212                 Print("StopLossMoney: ", StopMoneyLoss); 
213   
214                 if (Account.Equity < StopMoneyLoss) 
215                 { 
216                     //open orders 
217                     foreach (var openedPosition in Positions) 
218                     { 
219                         ClosePosition(openedPosition); 
220                     } 
221                     // pending orders 
222                     foreach (var order in PendingOrders) 
223                     { 
224                         CancelPendingOrder(order); 
225                     } 
226                     Stop(); 
227                 } 
228             } 
229   
230             if (netProfit >= CloseWhenEarn && CloseWhenEarn > 0) 
231             { 
232                 // open orders 
233                 foreach (var openedPosition in Positions) 
234                 { 
235                     ClosePosition(openedPosition); 
236                 } 
237                 // pending orders 
238                 foreach (var order in PendingOrders) 
239                 { 
240                     CancelPendingOrder(order); 
241                 } 
242                 Stop(); 
243             } 
244   
245   
246             //===================================================== Back Trailing 
247             if (BackStop > 0) 
248             { 
249                 foreach (var openedPosition in Positions) 
250                 { 
251                     Position Position = openedPosition; 
252                     if (Position.TradeType == TradeType.Buy) 
253                     { 
254                         double distance = Symbol.Bid - Position.EntryPrice; 
255   
256                         if (distance >= BackStop * Symbol.PipSize) 
257                         { 
258                             double newStopLossPrice = Math.Round(Symbol.Bid - BackStopValue * Symbol.PipSize, Symbol.Digits); 
259   
260                             if (Position.StopLoss == null) 
261                             { 
262                                 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 
263                             } 
264                         } 
265                     } 
266                     else 
267                     { 
268                         double distance = Position.EntryPrice - Symbol.Ask; 
269   
270                         if (distance >= BackStop * Symbol.PipSize) 
271                         { 
272   
273                             double newStopLossPrice = Math.Round(Symbol.Ask + BackStopValue * Symbol.PipSize, Symbol.Digits); 
274   
275                             if (Position.StopLoss == null) 
276                             { 
277                                 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 
278                             } 
279                         } 
280                     } 
281                 } 
282             } 
283   
284             //===================================================== Trailing 
285             if (TrailingStop > 0 && BackStop == 0) 
286             { 
287                 foreach (var openedPosition in Positions) 
288                 { 
289                     Position Position = openedPosition; 
290                     if (Position.TradeType == TradeType.Buy) 
291                     { 
292                         double distance = Symbol.Bid - Position.EntryPrice; 
293   
294                         if (distance >= TrailingStop * Symbol.PipSize) 
295                         { 
296                             double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits); 
297   
298                             if (Position.StopLoss == null || newStopLossPrice > Position.StopLoss) 
299                             { 
300                                 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 
301                             } 
302                         } 
303                     } 
304                     else 
305                     { 
306                         double distance = Position.EntryPrice - Symbol.Ask; 
307   
308                         if (distance >= TrailingStop * Symbol.PipSize) 
309                         { 
310   
311                             double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits); 
312   
313                             if (Position.StopLoss == null || newStopLossPrice < Position.StopLoss) 
314                             { 
315                                 ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); 
316                             } 
317                         } 
318                     } 
319                 } 
320             } 
321   
322   
323   
324   
325   
326   
327   
328   
329   
330         } 
331   
332 //================================================================================ 
333 //                                                             OnPositionOpened 
334 //================================================================================ 
335         protected override void OnPositionOpened(Position openedPosition) 
336         { 
337             int BuyPos = 0; 
338             int SellPos = 0; 
339   
340             foreach (var position in Positions) 
341             { 
342                 // Count opened positions 
343                 if (position.TradeType == TradeType.Buy) 
344                 { 
345                     BuyPos = BuyPos + 1; 
346                 } 
347                 if (position.TradeType == TradeType.Sell) 
348                 { 
349                     SellPos = SellPos + 1; 
350                 } 
351             } 
352   
353             Print("All Buy positions: " + BuyPos); 
354             Print("All Sell positions: " + SellPos); 
355   
356   
357         } 
358         // end OnPositionOpened 
359   
360 //================================================================================ 
361 //                                                                        OnBar 
362 //================================================================================ 
363         protected override void OnBar() 
364         { 
365   
366         } 
367 //================================================================================ 
368 //                                                             OnPositionClosed 
369 //================================================================================ 
370         protected override void OnPositionClosed(Position closedPosition) 
371         { 
372   
373         } 
374   
375 //================================================================================ 
376 //                                                                       OnStop 
377 //================================================================================ 
378         protected override void OnStop() 
379         { 
380   
381         } 
382   
383 //================================================================================ 
384 //                                                                     Function 
385 //================================================================================ 
386         private void Buy() 
387         { 
388             ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "", 1000, 1000); 
389         } 
390   
391         private void Sell() 
392         { 
393             ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "", 1000, 1000); 
394         } 
395   
396         private void ClosePosition() 
397         { 
398             if (_position != null) 
399             { 
400                 ClosePosition(_position); 
401                 _position = null; 
402             } 
403         } 
404   
405   
406         //================================================================================ 
407         //                                                                modify SL and TP 
408         //================================================================================ 
409         private double GetAbsoluteStopLoss(Position position, int stopLossInPips) 
410         { 
411             //Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); 
412             return position.TradeType == TradeType.Buy ? position.EntryPrice - (Symbol.PipSize * stopLossInPips) : position.EntryPrice + (Symbol.PipSize * stopLossInPips); 
413         } 
414   
415         private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips) 
416         { 
417             //Symbol Symbol = MarketData.GetSymbol(position.SymbolCode); 
418             return position.TradeType == TradeType.Buy ? position.EntryPrice + (Symbol.PipSize * takeProfitInPips) : position.EntryPrice - (Symbol.PipSize * takeProfitInPips); 
419         } 
420 //================================================================================ 
421 //                                                                    Robot end 
422 //================================================================================ 
423     } 
424 } 

 


@tradermatrix

tradermatrix
14 Aug 2015, 14:09

RE:

upen1234 said:

 Hi,

 

How I can place pending orders in one click instead of manually crating one by one.

 

Any help Appreciated..

/algos/cbots/show/192

I added pending order ... you can select this option to "PayBack" ..ajouter martingale .. etc ..
Best regards


@tradermatrix

tradermatrix
03 Aug 2015, 13:41

RE:

Spotware said:

Dear Trader,

We recommend you to uninstall the application, clear your ClickOnce cache and try to install the application again.

To clear your ClickOnce cache, please perform the following steps:

  1. Hold down the Win key and press R. The Run box should appear.

  2. Into the Open field, enter %LOCALAPPDATA%\Apps for Windows 8.1, Windows 7, and Windows Vista or %USERPROFILE%\Local Settings\Application Data\Apps for Windows XP

  3. Then click OK.

  4. This will open Windows Explorer.

  5. Delete the folder names 2.0

  6. Reinstall the application.

Thank you
Now everything is working normally
Best regards


@tradermatrix

tradermatrix
27 Jul 2015, 14:23 ( Updated at: 21 Dec 2023, 09:20 )


@tradermatrix

tradermatrix
27 Jul 2015, 14:15 ( Updated at: 21 Dec 2023, 09:20 )

it is now two months that backtest tick data releases.
impossible to make a valid backtest since early June.
in reality the robot works well
I rule out some robots anterior calendar June 1, 2015.
there is a runaway gains after that date by a multiplication of orders ...
you have an idea of the problem
I have practiced your method without success;C:\Users\%UserName%\AppData\Roaming\%Broker Name% cAlgo\BacktestingCache

it's the same problem and the same date for all brokers


Best regards

 


@tradermatrix

tradermatrix
15 Jun 2015, 16:16

yes thank you
but sometimes some traders give solutions.
I too am doing to help others.
regarding my application I found a solution.
and I managed to improve the performance of my robots.
multiplying SL and TP and the volume but way less that a classic martingale (the risk is smaller)
I work in real account
cordially.


@tradermatrix

tradermatrix
13 Jun 2015, 20:39

RE:

Neptune said:

In cTrader you are able to double and reverse a position. How can you do that via code? Here's what I've coded so far but I would like to double the position keeping it as one trade at the point I wrote "//double position"

protected override void OnTick()
        {

            if (Positions.Count < 1)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, 10000);
            }
            else
            {
                foreach (var position in Positions)
                {
                    if (position.Pips > 5)
                    {
                        ClosePosition(position);
                    }
                    else
                    {
                    if (position.Pips < -10)
                    {
                    //double position
                    }
                    }
                }
            }


        }

Thanks in advance for you help ;)

you can not build your robot in this way ..
you reduce to 1 order (if Positions.Count <1)"  you can not place another reverse order (count = 2)

if takeprofit sell order is executed first:
must cancel order buy X2.

I do not know the code of your robot and what you want to do.
but look if my sample can help.

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

        protected override void OnStart()
        {
            ordre1();
            Positions.Closed += OnPositionsClosed;
        }
        private void ordre1()
        {
            ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "robot1", null, 5);

            var buyOrderTargetPrice = Symbol.Ask + 10 * Symbol.PipSize;

            PlaceStopOrder(TradeType.Buy, Symbol, 10000 * 2, buyOrderTargetPrice, "robot2", null, 30);

        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            {
                Print("Closed");

                var position = args.Position;

                if (position.Label != "robot1" || position.SymbolCode != Symbol.Code)

                    return;

                foreach (var pendingOrder in PendingOrders)
                {

                    CancelPendingOrder(pendingOrder);


                }
            }
        }
    }
}

 


@tradermatrix

tradermatrix
11 Jun 2015, 13:15

RE:

icmar said:

Hi, I am looking for a  Martingale type robot.

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

 

Example = Buy with tp 30 and sl 30 , when TP is Hit start a trade in the same direction

When SL is hit trade double in the other direction until the Tp is hit from there start with step 1 in the same direction the TP is hit

 

 

Thanks

 

/algos/cbots/show/192


@tradermatrix

tradermatrix
05 Jun 2015, 13:36

RE: RE:

tradertowin said:

stevefromnaki said:

Thanks for the update nobulart,

 

Looks like it is an issue for a few of us, but not all of us cAlgo users, hope there is a solution on its way :)

I got the same error here, the message is very general, the data must be wrong, just start to learn calgo and the ticker backtesting is not working at the moment, bad luck for me.

 

there is a failure on the"Spotware cAlgo" tick start May 1st .... and do not work
 


@tradermatrix

tradermatrix
04 Jun 2015, 13:44

RE: Confirmed

nobulart said:

Same problem here. Stopped working sometime in the past few hours. Occurred on multiple platforms (WinXP and Win7).

gros probleme.
baktesting tick data = One or more errors occurred....??!!

also when I duplicate a robot...Yet everything works on the original...!

 


@tradermatrix

tradermatrix
31 May 2015, 16:45

RE:

9607367 said:

I want to reduce "Take Profit" if the loss.

Please tell me how it will look this condition:

 

If a loss then "Take Profit" / 2

hello
 like that;

 
        [Parameter(DefaultValue = 20)]
        public double TakeProfit1 { get; set; }

       [Parameter(DefaultValue = 10)]
        public double TakeProfit2 { get; set; }

       

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

  private void OnPositionsClosed(PositionClosedEventArgs args)
        {


            if (takeprofit2 == true)
            {

                Print("Closed");

                var position = args.Position;

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




                if (position.GrossProfit < 0)
                {




                    ExecuteMarketOrder(position.TradeType, Symbol, Volume , label, StopLoss, TakeProfit2);
                }

            }
        }

if you want the operation is only performed just once;
we must add label2.

exemple;

 private const string label1 = "Sample Trend cBot";

private const string label2 = "TakeProfit 2";

      ExecuteMarketOrder(position.TradeType, Symbol, Volume , label2, StopLoss, TakeProfit2);

 

 


 if you have a problem, write your code I would correct you.


 cordially


@tradermatrix

tradermatrix
24 May 2015, 21:26

RE:

botmaster said:

Is backtesting only available when the trading session is active?     My button play-button is grayed out.   

 

 

 

 

 

 

no .... it's a failure or an update (this morning) ...
it works with some brokers ..
cordially


@tradermatrix

tradermatrix
17 May 2015, 19:27

thank you,
it's a shame that the stopwatch system is not considered in backtesting(delayed backtesting) and optimization.il is very simple to use.
cordially.


@tradermatrix

tradermatrix
17 May 2015, 19:15



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

        //parameters

        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

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

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

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

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01)]
        public double lots { get; set; }

        [Parameter("TakeProfitPips", DefaultValue = 200)]
        public int tp { get; set; }

        [Parameter("StopLossPips", DefaultValue = 30)]
        public int sl { get; set; }

        [Parameter("trigger ", DefaultValue = 0)]
        public int Trigger { get; set; }

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


        private MovingAverage slowMa;

        private MovingAverage fastMa;

        private const string label = "Trend Trailing";



        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);

        }

        protected override void OnTick()
        {

            TRAILING();
            int volume = (int)(lots * 100000);

            //declaring variables during ticks
            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);

            // when buy signal is called
            if (previousSlowMa > previousFastMa && currentSlowMa < currentFastMa && longPosition == null)
            {
                //if theres a short position in playy
                if (shortPosition != null)

                    ClosePosition(shortPosition);

                ExecuteMarketOrder(TradeType.Buy, Symbol, volume, label, sl, tp);
            }

            //when short signal is called

            else if (previousSlowMa < previousFastMa && currentSlowMa > currentFastMa && shortPosition == null)
            {
                // if there are long positions in play
                if (longPosition != null)

                    ClosePosition(longPosition);

                ExecuteMarketOrder(TradeType.Sell, Symbol, volume, label, sl, tp);

            }

        }



        private void TRAILING()
        {
            if (Trailing > 0 && Trigger > 0)
            {

                Position[] positions = Positions.FindAll(label, Symbol);

                foreach (Position position in positions)
                {

                    if (position.TradeType == TradeType.Sell)
                    {

                        double distance = position.EntryPrice - Symbol.Ask;

                        if (distance >= Trigger * Symbol.PipSize)
                        {

                            double newStopLossPrice = Symbol.Ask + Trailing * Symbol.PipSize;

                            if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
                            {

                                ModifyPosition(position, newStopLossPrice, position.TakeProfit);

                            }
                        }
                    }

                    else
                    {

                        double distance = Symbol.Bid - position.EntryPrice;

                        if (distance >= Trigger * Symbol.PipSize)
                        {

                            double newStopLossPrice = Symbol.Bid - Trailing * Symbol.PipSize;

                            if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
                            {

                                ModifyPosition(position, newStopLossPrice, position.TakeProfit);

                            }
                        }
                    }
                }
            }
        }



    }
}





good trades


@tradermatrix

tradermatrix
07 May 2015, 22:19

RE: RE:

mindbreaker said:

tradermatrix said:

"Use < insert code>  button when You add cBot code:"

ok leader...

My code works but:

optimizer with my code is impossible....!!

 

It looks nicer :D:D:D

I dont know, maybe support know it?

 

ok I ask "admin" a solution.

I managed to include the code in other robots and c is good (except bascktesting)

thank you again


@tradermatrix

tradermatrix
07 May 2015, 20:37

"Use < insert code>  button when You add cBot code:"

ok leader...

My code works but:

optimizer with my code is impossible....!!

 


@tradermatrix

tradermatrix
07 May 2015, 19:04

Hello and thank you ..
 thanks to you, I found this solution;

using System.Diagnostics;
using System.Threading;

[Parameter("minute", DefaultValue = 1)]
        public int Minute { get; set; }

   protected override void OnStart()

{

 var stopwatch = Stopwatch.StartNew();
            System.Threading.Thread.Sleep(Minute * 60000);
            Console.WriteLine(stopwatch.ElapsedMilliseconds);

......

it works well,

.but I am having a problem ...
I can not make Bactesting (endless), or optimization.

do you think that there is a solution?

I'll give you an example with sample martingale.
I have changed the code to delay between winning trades.


it works very well in demo or real, but backtesting impossible ...
 cordially

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

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot 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
//
//    The "Sample Martingale cBot" 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 cBot 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;
using System.Diagnostics;
using System.Threading;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleMartingalecBot : Robot
    {
        [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("delay minute", DefaultValue = 1)]
        public int Minute { get; set; }

        private Random random = new Random();

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

            Order1();
        }
        private void Order1()
        {
            var stopwatch = Stopwatch.StartNew();
            System.Threading.Thread.Sleep(Minute * 60000);
            Console.WriteLine(stopwatch.ElapsedMilliseconds);


            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.Pips > 0)
                    Order1();

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


@tradermatrix

tradermatrix
06 May 2015, 15:45

RE:

Andrew_Elia said:

what i need is to need to end the codding of cbot


hello
I think you should remove two "}" and add one to the end
otherwise post all the code here or on my email ..I corrects you.


@tradermatrix

tradermatrix
04 May 2015, 13:06

RE: RE: RE:

mindbreaker said:

        protected override void OnTick()
        {

            double earn = 0;

            foreach (var pos in Positions)
            {
                if (pos.TradeType == TradeType.Buy)
                {
                    // if You write pos and hit dot you have got tips for positions in calgo                    
                    //pos.NetProfit;
                    //pos.Pips;
                    //...
                    earn += pos.GrossProfit;
                }
            }
            if (earn > 100)
            {
                foreach (var pos in Positions)
                {
                    if (pos.TradeType == TradeType.Buy)
                    {
                        ClosePosition(pos);
                    }
                }
            }

        }

 

thank you very much mindbreaker
the error was; GrosProfit .. !!! GrossProfit.
for the info I have written;
 

 

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

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

 

 

 protected override void OnTick()
        {
            gainsBuy();
            gainsSell();

}

  private void gainsBuy()
        {

double earn = 0;



            foreach (var pos in Positions)
            {
                if (pos.TradeType == TradeType.Buy)
                {
                    earn += pos.NetProfit;
                }

            }


            if (earn > totalBuy)
            {
                foreach (var pos in Positions)

                    if (pos.TradeType == TradeType.Buy)
                    {
                        ClosePosition(pos);
                    }
            }

        }

        private void gainsSell()
        {

double earn = 0;


            foreach (var pos in Positions)
            {
                if (pos.TradeType == TradeType.Sell)
                {
                    earn += pos.NetProfit;
                }

            }


            if (earn > totalSell)
            {
                foreach (var pos in Positions)

                    if (pos.TradeType == TradeType.Sell)
                    {
                        ClosePosition(pos);
                    }
            }
        }



bons trades


@tradermatrix