Changeset 4
- Timestamp:
- May 30, 2008, 2:13:47 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MovingAverageCrossing.mq4
r3 r4 7 7 #property link "" 8 8 9 #define MAGICMA 200506109 #define MAGICMA 1000000 10 10 11 11 extern double Lots = 0.1; … … 14 14 extern double ShortMovingPeriod = 5; 15 15 extern double ShortMovingShift = 0; 16 extern double LongMovingPeriod = 100;16 extern double LongMovingPeriod = 20; 17 17 extern double LongMovingShift = 0; 18 extern double PricePeriod = 2; 18 19 extern double MinDerivation = 0.0002; 19 20 extern double MinimumDistance = 0.04; 21 extern double BaseTrailingStop = 50; 22 extern double TrailingStopPart = 0.6; 20 23 21 24 int MathSign(double Value) … … 38 41 static int SameDirectionCount = 0; 39 42 static int LastPolarity; 43 double TrailingStop; 40 44 41 45 // Go trading only for first tiks of new bar … … 59 63 } 60 64 */ 61 65 RefreshRates(); 66 62 67 // Sell conditions 63 68 for(int i=0; i < OrdersTotal(); i++) … … 68 73 if(OrderType() == OP_BUY) 69 74 { 70 if(PolarityChanged && (Polarity == -1)) 71 OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); 75 TrailingStop = (Bid - OrderOpenPrice()) * TrailingStopPart + BaseTrailingStop * Point; 76 Print("TrailingStop: " + TrailingStop + ", OpenPrice: " + OrderOpenPrice() + ", Bid: " + Bid); 77 if(Bid > OrderStopLoss() + TrailingStop) 78 { 79 OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop, OrderTakeProfit(), 0, Green); 80 } 81 //if(PolarityChanged && (Polarity == -1)) 82 // OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); 72 83 } 73 84 if(OrderType() == OP_SELL) 74 85 { 75 if(PolarityChanged && (Polarity == 1)) 76 OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); 86 TrailingStop = (OrderOpenPrice() - Ask) * TrailingStopPart + BaseTrailingStop * Point; 87 if(Ask < OrderStopLoss() - TrailingStop) 88 { 89 OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop, OrderTakeProfit(), 0, Green); 90 } 91 //if(PolarityChanged && (Polarity == 1)) 92 // OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); 77 93 } 78 94 } … … 82 98 if(PolarityChanged) 83 99 { 84 if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, "", MAGICMA, 0, Red);85 if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, "", MAGICMA, 0, Blue);100 if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + BaseTrailingStop * Point, 0, "", MAGICMA, 0, Red); 101 if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - BaseTrailingStop * Point, 0, "", MAGICMA, 0, Blue); 86 102 PolarityChanged = false; 87 103 }
Note:
See TracChangeset
for help on using the changeset viewer.