1 #property copyright "Zarko Asenov"
\r
2 #property link "jaltoh.6x.to"
\r
4 /* General functionality settings */
\r
5 extern int Slippage = 3;
\r
6 extern double LotSize = 0.12;
\r
7 extern double PipStep = 16.0; // For variable spread brokers keep it at the average guaranteed spread
\r
8 extern bool InitialBuyOrder = true;
\r
9 extern int MagicNumber = 1771611;
\r
10 extern double Close_All_Profit = 10.0;
\r
11 extern bool Clear_Stops = true;
\r
12 extern double Order_Lifetime_Days = 0.2;
\r
13 extern bool Add_Spread_to_PipStep = false; // For fixed spread brokers - be sure about this!
\r
14 extern bool Add_MinStop_to_PipStep = true;
\r
15 extern double Max_spread = 22.0;
\r
16 extern double Hours_Bring_Even = 0.0;
\r
17 extern double Multi_Coef = 1.0; // multiplies LotSize PipStep Close_All_Profit Min_Bands
\r
18 extern bool Debug_Print = false;
\r
20 extern double LTS_LotSize = 0.0; /* Leave 0 for no Long Term Strategy trading */
\r
21 extern double LTS_Close_All_Profit = 10.0;
\r
22 extern int Max_LTS_Positions = 1;
\r
23 extern int Grid_Base_Period = PERIOD_M5;
\r
25 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
27 /* Bollinger bands */
\r
28 extern int Bands_Days = 10;
\r
29 extern int Bands_Deviations = 4;
\r
30 extern double Min_Bands = 0.017;
\r
31 extern int Num_Bands = 2;
\r
34 /* Stochastic oscillator */
\r
35 extern bool Check_Stoch = true;
\r
36 extern int Stoch_K = 6;
\r
37 extern int Stoch_D = 4;
\r
38 extern int Stoch_Slow = 3;
\r
39 extern int Stoch_num_pos = 2;
\r
40 extern double Stoch_border = 40.0;
\r
41 extern int Stochastic_Period = PERIOD_H4;
\r
44 extern bool Check_MACD = true;
\r
45 extern int MACD_fast = 5;
\r
46 extern int MACD_slow = 34;
\r
47 extern int MACD_signal = 12;
\r
48 extern int MACD_num_pos = 2;
\r
49 extern double MACD_floor = 0.0;
\r
50 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
52 /* Average Directional Movement Index */
\r
53 extern bool Check_ADX = true;
\r
54 extern int ADX_positions_to_check = 2;
\r
55 extern int ADX_period_in_days = 4;
\r
56 extern double ADX_min = 37.0;
\r
58 /* Average True Range */
\r
59 extern double ATR_Floor = 0.0055;
\r
60 extern int ATR_period_in_days = 35;
\r
61 extern int ATR_positions_to_check = 3;
\r
63 extern int ATR_Period = PERIOD_H4;
\r
65 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
67 /* Globals variables */
\r
68 int longOrderCount = 0;
\r
69 int shortOrderCount = 0;
\r
70 double startPrice = 0.0;
\r
72 bool initOrdersDone = false;
\r
73 double spread = 0.0;
\r
74 double pipstep_adjusted = 0.0;
\r
75 double current_adx = 0.0;
\r
77 double neg_adx_min = 0.0;
\r
78 double neg_stoch_border = 0.0;
\r
80 double current_macd = 0.0;
\r
81 double neg_adx_min = 0.0;
\r
82 double neg_macd_floor = 0.0;
\r
83 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
84 double current_atr = 0.0;
\r
85 int order_lifetime = 0;
\r
86 double time_bring_even = 0.0;
\r
87 double bandwidth = 0.0;
\r
88 double adjustedLotSize = 0.0;
\r
89 double adjustedPipStep = 0.0;
\r
90 double adjustedClose_All_Profit = 0.0;
\r
91 double adjustedMin_Bands = 0.0;
\r
92 double tick_value = 0.0;
\r
93 double total_spread_loss = 0.0;
\r
95 int prev_signal = 0;
\r
96 int lts_magic_number = -1;
\r
97 int lts_long_positions = 0;
\r
98 int lts_short_positions = 0;
\r
99 double current_stoch_k = 0.0;
\r
100 double current_stoch_d = 0.0;
\r
103 #define SIG_NO_TREND 0
\r
104 #define SIG_IN_TREND 1
\r
105 #define SIG_GO_BUY 2
\r
106 #define SIG_GO_SELL 3
\r
108 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
114 if (Stoch_border > 100.0) Stoch_border = 100.0;
\r
116 neg_stoch_border = 100.0 - Stoch_border;
\r
117 neg_adx_min = -1.0 * ADX_min;
\r
119 order_lifetime = MathRound(Order_Lifetime_Days * 86400);
\r
120 time_bring_even = 3600 * Hours_Bring_Even;
\r
121 lts_magic_number = MagicNumber + 1;
\r
123 adjustedLotSize = LotSize * Multi_Coef;
\r
124 adjustedPipStep = PipStep;
\r
125 adjustedClose_All_Profit = Close_All_Profit * Multi_Coef;
\r
126 adjustedMin_Bands = Min_Bands;
\r
128 neg_adx_min = -1.0 * ADX_min;
\r
129 neg_macd_floor = -1.0 * MACD_floor;
\r
130 order_lifetime = MathRound(Order_Lifetime_Days * 86400);
\r
131 time_bring_even = 3600 * Hours_Bring_Even;
\r
133 adjustedLotSize = LotSize * Multi_Coef;
\r
134 adjustedPipStep = PipStep * Multi_Coef;
\r
135 adjustedClose_All_Profit = Close_All_Profit * Multi_Coef;
\r
136 adjustedMin_Bands = Min_Bands * Multi_Coef;
\r
137 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
139 tick_value = MarketInfo(Symbol(), MODE_TICKVALUE);
\r
140 digits = MarketInfo(Symbol(), MODE_DIGITS);
\r
142 Print("Digits: " + digits + " Negative ADX floor: " + neg_adx_min);
\r
147 double get_minstop()
\r
149 return( MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0 );
\r
159 current_adx = iADX(NULL, PERIOD_D1, ADX_period_in_days, PRICE_CLOSE, MODE_MAIN, index);
\r
160 ADX1 = iADX(NULL, PERIOD_D1, ADX_period_in_days, PRICE_CLOSE, MODE_PLUSDI, index);
\r
161 ADX2 = iADX(NULL, PERIOD_D1, ADX_period_in_days, PRICE_CLOSE, MODE_MINUSDI, index);
\r
163 current_adx = iADX(NULL, PERIOD_H4, ADX_period_in_days, PRICE_CLOSE, MODE_MAIN, index);
\r
164 ADX1 = iADX(NULL, PERIOD_H4, ADX_period_in_days, PRICE_CLOSE, MODE_PLUSDI, index);
\r
165 ADX2 = iADX(NULL, PERIOD_H4, ADX_period_in_days, PRICE_CLOSE, MODE_MINUSDI, index);
\r
166 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
169 return(current_adx);
\r
171 return(-1.0 * current_adx);
\r
175 adx_is_sell(int num_pos)
\r
177 if (Check_ADX == false) return (true);
\r
180 for (int i = 0; i < num_pos; i++) {
\r
182 if (get_adx(i) > neg_adx_min) return (false);
\r
184 if (get_adx(i) > -ADX_min) return (false);
\r
185 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
192 adx_is_buy(int num_pos)
\r
194 if (Check_ADX == false) return (true);
\r
196 for (int i = 0; i < num_pos; i++) {
\r
197 current_adx = get_adx(i);
\r
198 if (current_adx < ADX_min) return (false);
\r
206 stoch_is_buy(int num_pos)
\r
208 if (Check_Stoch == false) return (true);
\r
210 for (int i = 0; i < num_pos; i++) {
\r
211 current_stoch_k = iStochastic(NULL, Stochastic_Period, 6, 4, 3, MODE_EMA, 0, MODE_MAIN, i);
\r
212 current_stoch_d = iStochastic(NULL, Stochastic_Period, 6, 4, 3, MODE_EMA, 0, MODE_SIGNAL, i);
\r
214 if (current_stoch_k > Stoch_border) return(false);
\r
215 // if (current_stoch_k < current_stoch_d) return (false);
\r
217 double Stoch_border = 40.0;
\r
218 double neg_stoch_border = 60.0;
\r
219 double current_stoch_k = 0.0;
\r
220 double current_stoch_d = 0.0;
\r
223 macd_is_sell(int num_pos)
\r
225 if (Check_MACD == false) return (true);
\r
227 // for (int i = 0; i < MACD_num_pos; i++) {
\r
228 // current_macd = iMACD(NULL, PERIOD_H4, MACD_fast, MACD_slow, MACD_signal, PRICE_CLOSE, MODE_MAIN, i);
\r
229 // if (current_macd > neg_macd_floor) return(false);
\r
231 for (int i = 0; i < num_pos; i++) {
\r
232 current_stoch_k = iCustom(NULL, PERIOD_M15, "Ehlers Fisher transform histo", 12, 4, 5, i);
\r
233 current_stoch_d = iCustom(NULL, PERIOD_M15, "Ehlers Fisher transform histo", 12, 4, 4, i);
\r
234 if (current_stoch_k > 0.0 || current_stoch_d > 0.0) return (false);
\r
235 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
243 stoch_is_sell(int num_pos)
\r
245 if (Check_Stoch == false) return (true);
\r
247 for (int i = 0; i < num_pos; i++) {
\r
248 current_stoch_k = iStochastic(NULL, Stochastic_Period, 6, 4, 3, MODE_EMA, 0, MODE_MAIN, i);
\r
249 current_stoch_d = iStochastic(NULL, Stochastic_Period, 6, 4, 3, MODE_EMA, 0, MODE_SIGNAL, i);
\r
251 if (current_stoch_k < neg_stoch_border) return(false);
\r
252 // if (current_stoch_k > current_stoch_d) return (false);
\r
258 macd_is_buy(int num_pos)
\r
260 if (Check_MACD == false) return (true);
\r
262 for (int i = 0; i < MACD_num_pos; i++) {
\r
263 // current_macd = iMACD(NULL, PERIOD_H4, MACD_fast, MACD_slow, MACD_signal, PRICE_CLOSE, MODE_MAIN, i);
\r
264 // if (current_macd < MACD_floor) return(false);
\r
268 for (int i = 0; i < num_pos; i++) {
\r
269 current_stoch_k = iCustom(NULL, PERIOD_M15, "Ehlers Fisher transform histo", 12, 4, 5, i);
\r
270 current_stoch_d = iCustom(NULL, PERIOD_M15, "Ehlers Fisher transform histo", 12, 4, 4, i);
\r
271 if (current_stoch_k < 0.0 || current_stoch_d < 0.0) return (false);
\r
275 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
280 atr_is_go(int num_pos)
\r
282 for (int i = 0; i < num_pos; i++) {
\r
284 current_atr = iATR(NULL, ATR_Period, ATR_period_in_days, i);
\r
286 current_atr = iCustom(NULL, PERIOD_M15, "ATR ratio", 8, 35, 1.0, 1, i);
\r
287 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
288 if (current_atr < ATR_Floor) return (false);
\r
297 double presult = 0.0;
\r
298 total_spread_loss = 0.0;
\r
299 tick_value = MarketInfo(Symbol(), MODE_TICKVALUE);
\r
301 for (int i = 0; i < OrdersTotal(); i++) {
\r
302 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
304 if ((OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) &&
\r
305 OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
\r
307 double spread_loss = tick_value * OrderLots() * spread;
\r
308 presult += (OrderProfit() - spread_loss);
\r
309 total_spread_loss += spread_loss;
\r
319 if (LTS_LotSize == 0 || lts_magic_number == -1 ||
\r
320 lts_long_positions + lts_short_positions < 1) return;
\r
322 double presult = 0.0;
\r
323 total_spread_loss = 0.0;
\r
324 tick_value = MarketInfo(Symbol(), MODE_TICKVALUE);
\r
326 for (int i = 0; i < OrdersTotal(); i++) {
\r
327 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
329 if ((OrderSymbol() != Symbol() || OrderMagicNumber() != lts_magic_number) &&
\r
330 OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
\r
332 double spread_loss = tick_value * OrderLots() * spread;
\r
333 presult += (OrderProfit() - spread_loss);
\r
334 total_spread_loss += spread_loss;
\r
341 getBandwidth(int pos)
\r
343 bandwidth = iBands(NULL, Grid_Base_Period, Bands_Days, Bands_Deviations, 0, PRICE_CLOSE, MODE_UPPER, pos) -
\r
344 iBands(NULL, Grid_Base_Period, Bands_Days, Bands_Deviations, 0, PRICE_CLOSE, MODE_LOWER, pos);
\r
346 getBandwidth(int pos)
\r
348 bandwidth = iBands(NULL, PERIOD_M15, Bands_Days, Bands_Deviations, 0, PRICE_CLOSE, MODE_UPPER, pos) -
\r
349 iBands(NULL, PERIOD_M15, Bands_Days, Bands_Deviations, 0, PRICE_CLOSE, MODE_LOWER, pos);
\r
350 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
352 return (bandwidth);
\r
358 for (int i = 0; i < Num_Bands; i++)
\r
359 if (getBandwidth(i) < adjustedMin_Bands)
\r
368 return ( atr_is_go(ATR_positions_to_check) && inBands() );
\r
375 return ( adx_is_buy(ADX_positions_to_check) && stoch_is_buy(Stoch_num_pos) );
\r
377 return ( adx_is_buy(ADX_positions_to_check) && macd_is_buy(MACD_num_pos) );
\r
378 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
385 return ( adx_is_sell(ADX_positions_to_check) && stoch_is_sell(Stoch_num_pos) );
\r
389 get_current_signal() {
\r
391 bool in_trend = in_trend();
\r
393 if ( in_trend && go_buy() )
\r
394 return(SIG_GO_BUY);
\r
395 else if ( in_trend && go_sell() )
\r
396 return(SIG_GO_SELL);
\r
397 else if ( in_trend == true)
\r
398 return(SIG_IN_TREND);
\r
400 return(SIG_NO_TREND);
\r
402 return ( adx_is_sell(ADX_positions_to_check) && macd_is_sell(MACD_num_pos) );
\r
403 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
409 if(startPrice == 0.0) {
\r
411 startPrice = iOpen(NULL, Grid_Base_Period, 0);
\r
412 if (Debug_Print) Print("startPrice: " + startPrice);
\r
414 startPrice = MarketInfo(Symbol(), MODE_ASK);
\r
416 Print("startPrice: " + startPrice);
\r
417 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
420 pipstep_adjusted = adjustedPipStep;
\r
422 if (Add_Spread_to_PipStep)
\r
423 pipstep_adjusted += spread / MarketInfo(Symbol(), MODE_POINT);
\r
425 if (Add_MinStop_to_PipStep)
\r
426 pipstep_adjusted += get_minstop();
\r
429 if ( !initOrdersDone && in_trend() ) {
\r
434 placeInitBuyOrder();
\r
436 } else if (go_sell()) {
\r
439 placeInitSellOrder();
\r
443 initOrdersDone = true;
\r
447 int current_signal = get_current_signal();
\r
449 if(iClose(NULL, Grid_Base_Period, 0) > startPrice + pipstep_adjusted * Point) {
\r
451 startPrice = iClose(NULL, Grid_Base_Period, 0);
\r
454 if(MarketInfo(Symbol(), MODE_ASK) > startPrice + pipstep_adjusted * Point) {
\r
456 startPrice = MarketInfo(Symbol(), MODE_ASK);
\r
457 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
460 Print("Go buy ,new startPrice:" + startPrice);
\r
462 // need to set the sl to BE of last order
\r
463 moveSellOrderToBE();
\r
465 moveHitBuyOrdersToBE();
\r
469 if ( current_signal == SIG_GO_BUY ) {
\r
473 } else if (iClose(NULL, Grid_Base_Period, 0) < startPrice - pipstep_adjusted * Point) {
\r
475 startPrice = iClose(NULL, Grid_Base_Period, 0);
\r
477 if ( in_trend() && go_buy() ) placeBuyOrder();
\r
480 } else if (MarketInfo(Symbol(), MODE_BID) < startPrice - pipstep_adjusted * Point) {
\r
482 startPrice = MarketInfo(Symbol(), MODE_BID);
\r
483 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
486 Print("Go sell, new startPrice: " + startPrice);
\r
488 // need to set the sl to BE of last order
\r
489 moveBuyOrderToBE();
\r
491 moveHitSellOrdersToBE();
\r
493 // place sell stops
\r
495 if ( current_signal == SIG_GO_SELL ) {
\r
501 /* Long Term Strategy */
\r
502 if (LTS_LotSize != 0.0) {
\r
503 if (calc_profit_lts() > LTS_Close_All_Profit) close_all_lts();
\r
504 else if (current_signal == SIG_GO_SELL && prev_signal != SIG_GO_SELL) place_lts_sell();
\r
505 else if (current_signal == SIG_GO_BUY && prev_signal != SIG_GO_BUY) place_lts_buy();
\r
506 else if (current_signal == SIG_GO_BUY && lts_short_positions > 0) close_all_lts();
\r
507 else if (current_signal == SIG_GO_SELL && lts_long_positions > 0) close_all_lts();
\r
508 prev_signal = current_signal;
\r
512 if ( in_trend() && go_sell() ) placeSellOrder();
\r
516 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
518 spread = Point * MarketInfo(Symbol(), MODE_SPREAD);
\r
519 double current_profit = calc_profit();
\r
523 "SpeedTrain Forte\nby DrZed 2011\n" +
\r
524 "Symbol: " + Symbol() + "\n" +
\r
525 "Spread: " + spread + "\n" +
\r
526 "Bandwidth: " + bandwidth + "\n" +
\r
527 "ADX difference: " + current_adx + "\n" +
\r
529 "Stoch base: " + current_stoch_k + "\n" +
\r
530 "Stoch signal: " + current_stoch_d + "\n" +
\r
531 "ATR value: " + current_atr + "\n" +
\r
532 "Pipstep adjusted: " + pipstep_adjusted + "\n" +
\r
533 "Last orders price: " + startPrice + "\n" +
\r
534 "Current close M15 price: " + iClose(NULL, Grid_Base_Period, 0) + "\n" +
\r
536 "MACD base: " + current_stoch_k + "\n" +
\r
537 "ATR value: " + current_atr + "\n" +
\r
538 "Pipstep adjusted: " + pipstep_adjusted + "\n" +
\r
539 "Last orders price: " + startPrice + "\n" +
\r
540 "Current close M15 price: " + iClose(NULL, PERIOD_M15, 0) + "\n" +
\r
541 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
542 "Profit: " + current_profit + " USD\n" +
\r
543 "Total spread loss: " + total_spread_loss + " USD\n"
\r
547 if (current_profit > adjustedClose_All_Profit && spread < Max_spread) {
\r
550 Print("Closing orders on profit " + current_profit +
\r
551 " total spread loss: " + total_spread_loss +
\r
552 " spread: " + spread + " pips.");
\r
554 for (int i = 0; i < OrdersTotal(); i++) {
\r
556 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
558 if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
\r
560 switch ( OrderType() ) {
\r
563 OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Blue);
\r
567 OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Red);
\r
572 OrderDelete( OrderTicket() );
\r
577 Print("Uknown order type " + OrderType() + " of order #" + OrderTicket() );
\r
581 shortOrderCount = 0;
\r
582 longOrderCount = 0;
\r
591 if (LTS_LotSize == 0.0 || lts_magic_number == -1 ||
\r
592 lts_long_positions + lts_short_positions > Max_LTS_Positions) {
\r
593 if (Debug_Print) Print("Long Term trading Stradegy disabled!");
\r
597 double ask = MarketInfo(Symbol(), MODE_ASK) ;
\r
599 if (Debug_Print) Print("LTS Placing buy order at " + ask);
\r
601 int ticketlong = OrderSend(
\r
605 NormalizeDouble(ask, digits),
\r
609 "Long Speed Train LTS",
\r
614 if (ticketlong < 0) {
\r
616 Print("LTS Long OrderSend failed with error #", GetLastError());
\r
620 if (Debug_Print) Print("LTS Buy order placed with ticket " + ticketlong + " at " + ask);
\r
622 lts_long_positions++;
\r
628 if (LTS_LotSize == 0.0 || lts_magic_number == -1 ||
\r
629 lts_long_positions + lts_short_positions > Max_LTS_Positions) {
\r
630 if (Debug_Print) Print("Long Term trading Stradegy disabled!");
\r
634 double bid = MarketInfo(Symbol(), MODE_BID);
\r
635 double sellSL = bid + pipstep_adjusted * Point;
\r
637 if (Debug_Print) Print("Placing LTS sell order at " + bid);
\r
639 int ticketshort = OrderSend(
\r
643 NormalizeDouble(bid, digits),
\r
647 "Short Speed Train LTS",
\r
652 if (ticketshort < 0) {
\r
653 if (Debug_Print) Print("Short OrderSend failed with error #", GetLastError());
\r
658 if (Debug_Print) Print("Sell order placed with ticket " + ticketshort + " at " + bid);
\r
660 lts_short_positions++;
\r
666 for (int i = 0; i < OrdersTotal(); i++) {
\r
668 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
\r
670 if (OrderSymbol() != Symbol() || OrderMagicNumber() != lts_magic_number) continue;
\r
672 switch ( OrderType() ) {
\r
675 OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Blue);
\r
679 OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Red);
\r
684 OrderDelete( OrderTicket() );
\r
688 if (Debug_Print) Print("Uknown LTS order type " + OrderType() + " of order #" + OrderTicket() );
\r
692 lts_short_positions = 0;
\r
693 lts_long_positions = 0;
\r
697 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
701 double ask = MarketInfo(Symbol(), MODE_ASK) ;
\r
703 double buyPrice = ask + pipstep_adjusted * Point;
\r
704 double buySL = ask;
\r
707 Print("Placing buy stop order at " + buyPrice+" with SL at " + buySL);
\r
709 int ticketlong = OrderSend(
\r
713 NormalizeDouble(buyPrice, digits),
\r
715 NormalizeDouble(buySL, digits),
\r
717 "Long Speed Train",
\r
719 order_lifetime + TimeCurrent(),
\r
722 if (ticketlong < 0) {
\r
723 Print("Long OrderSend failed with error #", GetLastError());
\r
728 Print("Buy stop order placed with ticket " + ticketlong + " at " + buyPrice);
\r
736 double bid = MarketInfo(Symbol(), MODE_BID) ;
\r
738 double sellPrice = bid - pipstep_adjusted * Point;
\r
739 double sellSL = bid;
\r
743 Print("Placing sell stop order at " + sellPrice + " with SL at " + sellSL);
\r
745 int ticketshort = OrderSend(
\r
749 NormalizeDouble(sellPrice, digits),
\r
751 NormalizeDouble(sellSL, digits),
\r
753 "Short Speed Train",
\r
755 order_lifetime + TimeCurrent(),
\r
758 if (ticketshort < 0) {
\r
759 Print("Short OrderSend failed with error #", GetLastError());
\r
764 Print("Sell stop order placed with ticket " + ticketshort + " at " + sellPrice);
\r
770 placeInitBuyOrder()
\r
772 double ask = MarketInfo(Symbol(), MODE_ASK) ;
\r
774 double buySL = ask - pipstep_adjusted * Point;
\r
778 Print("Placing buy order at " + ask + " with SL at " + buySL);
\r
780 Print("Placing buy stop order at " + ask + " with SL at " + buySL);
\r
781 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
783 int ticketlong = OrderSend(
\r
787 NormalizeDouble(ask, digits),
\r
789 NormalizeDouble(buySL, digits),
\r
791 "Long Speed Train",
\r
796 if (ticketlong < 0) {
\r
798 Print("Long OrderSend failed with error #", GetLastError());
\r
804 Print("Buy order placed with ticket " + ticketlong + " at " + ask);
\r
806 Print("Buy stop order placed with ticket " + ticketlong + " at " + ask);
\r
807 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
814 placeInitSellOrder()
\r
817 double bid = MarketInfo(Symbol(), MODE_BID);
\r
818 double sellSL = bid + pipstep_adjusted * Point;
\r
822 Print("Placing sell order at "+bid+" with SL at "+sellSL);
\r
824 Print("Placing sell stop order at "+bid+" with SL at "+sellSL);
\r
825 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
827 int ticketshort = OrderSend(
\r
831 NormalizeDouble(bid, digits),
\r
833 NormalizeDouble(sellSL, digits),
\r
835 "Short Speed Train",
\r
840 if (ticketshort < 0) {
\r
842 Print("Short OrderSend failed with error #", GetLastError());
\r
849 Print("Sell order placed with ticket " + ticketshort + " at " + bid);
\r
851 Print("Sell stop order placed with ticket " + ticketshort + " at " + bid);
\r
852 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
854 shortOrderCount++;
\r
859 double Panic_Profit = -200.0;
\r
861 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
863 moveHitBuyOrdersToBE()
\r
865 for(int j = 0; j < OrdersTotal(); j++)
\r
867 OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
\r
869 if (OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY &&
\r
870 TimeCurrent() - OrderOpenTime() > time_bring_even)
\r
875 bool res = OrderModify(
\r
876 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
880 OrderTakeProfit(),
\r
881 OrderExpiration(),
\r
887 if ( false) res = OrderModify(
\r
890 OrderOpenPrice() - Point * get_minstop(),
\r
891 OrderTakeProfit(),
\r
892 OrderExpiration(),
\r
895 if (OrderProfit() < Panic_Profit) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Blue);
\r
897 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
902 moveHitSellOrdersToBE()
\r
904 for(int j = 0; j < OrdersTotal(); j++)
\r
906 OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
\r
908 if (OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL &&
\r
909 TimeCurrent() - OrderOpenTime() > time_bring_even)
\r
914 bool res = OrderModify(
\r
915 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
919 OrderTakeProfit(),
\r
920 OrderExpiration(),
\r
925 if ( false) res = OrderModify(
\r
928 OrderOpenPrice() + Point * get_minstop(),
\r
929 OrderTakeProfit(),
\r
930 OrderExpiration(),
\r
933 if (OrderProfit() < Panic_Profit)
\r
934 OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Red);
\r
936 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
943 int lastTicket = 0;
\r
945 for(int j = 0; j < OrdersTotal(); j++)
\r
947 OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
\r
950 if (OrderMagicNumber() == MagicNumber && OrderType() == OP_BUYSTOP)
\r
952 int ticketId = OrderTicket() ;
\r
953 if (ticketId > lastTicket) lastTicket = ticketId;
\r
957 if(lastTicket > 0) {
\r
960 if (OrderMagicNumber() != MagicNumber || OrderType() != OP_BUYSTOP) continue;
\r
962 int ticketId = OrderTicket();
\r
963 if (ticketId > lastTicket) lastTicket = ticketId;
\r
967 if(lastTicket > 0) {
\r
968 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
969 OrderSelect(lastTicket, SELECT_BY_TICKET, MODE_TRADES);
\r
972 Print("Moving long order number " + lastTicket + " to BE at " + OrderOpenPrice() );
\r
975 int ticketlong = OrderModify(
\r
979 OrderTakeProfit(),
\r
980 OrderExpiration(),
\r
984 if (ticketlong < 0 && Debug_Print)
\r
985 Print("Long SL2BE order failed with error #", GetLastError());
\r
988 bool res = OrderModify(
\r
992 OrderTakeProfit(),
\r
993 OrderExpiration(),
\r
997 if (!res && Debug_Print)
\r
998 Print("Long SL2BE order failed with error #", GetLastError());
\r
1001 res = OrderModify(
\r
1003 OrderOpenPrice(),
\r
1004 OrderOpenPrice() - Point * get_minstop(),
\r
1005 OrderTakeProfit(),
\r
1006 OrderExpiration(),
\r
1010 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
1014 void moveSellOrderToBE()
\r
1018 for(int j = 0; j < OrdersTotal(); j++) {
\r
1019 OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
\r
1022 if (OrderMagicNumber() == MagicNumber && OrderType() == OP_SELLSTOP)
\r
1024 int ticketId = OrderTicket();
\r
1025 if(ticketId > lastTicket) lastTicket = ticketId;
\r
1028 if (OrderMagicNumber() != MagicNumber || OrderType() != OP_SELLSTOP) continue;
\r
1030 int ticketId = OrderTicket();
\r
1031 if(ticketId > lastTicket) lastTicket = ticketId;
\r
1033 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
1037 if(lastTicket > 0) {
\r
1038 OrderSelect(lastTicket, SELECT_BY_TICKET, MODE_TRADES);
\r
1041 Print("Moving short order number " + lastTicket+ " to BE at " + OrderOpenPrice());
\r
1044 int ticketshort = OrderModify(
\r
1046 bool res = OrderModify(
\r
1047 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
1049 OrderOpenPrice(),
\r
1050 OrderOpenPrice(),
\r
1051 OrderTakeProfit(),
\r
1052 OrderExpiration(),
\r
1056 if (ticketshort < 0)
\r
1057 if (Debug_Print) Print("Short SL2BE order failed with error #",GetLastError());
\r
1061 if (Debug_Print) Print("Short SL2BE order failed with error #",GetLastError());
\r
1062 res = OrderModify(
\r
1064 OrderOpenPrice(),
\r
1065 OrderOpenPrice() + Point * get_minstop(),
\r
1066 OrderTakeProfit(),
\r
1067 OrderExpiration(),
\r
1071 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9