Placing Pending order for cTrader

Created at 10 Aug 2015, 14:11
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
IN

Indiv

Joined 11.03.2014

Placing Pending order for cTrader
10 Aug 2015, 14:11


 Hi,

 

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

 

Any help Appreciated..


@Indiv
Replies

.ics
11 Aug 2015, 02:01

Check out their YouTube channel. They have some movie content what explains the feature what you are looking for.
@.ics

Indiv
11 Aug 2015, 02:41

RE:

.ics said:

Check out their YouTube channel. They have some movie content what explains the feature what you are looking for.

Thanks for reply.. it will be great if you recommend some good cBolt so that when I execute it for certain pair .. it automatically create pending order based on some basic parameters.

 

Thanks


@Indiv

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

Indiv
14 Aug 2015, 15:27

RE: RE:

tradermatrix said:

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

 

Thanks

 

It will be great help if you could write a specific code for 'only placing STOP Buy/Sell Pending orders

 

Thanks


@Indiv

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

tgjobscv
24 Apr 2019, 20:19

RE:

tradermatrix said:

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 } 

 

Error CS0116: A namespace cannot directly contain members such as fields or methods

errors 83


@tgjobscv

tgjobscv
24 Apr 2019, 20:52

cboot calgo - only stop buy and sell order pending ?


@tgjobscv