Changeset 5
- Timestamp:
- Jun 16, 2008, 3:24:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MovingAverageCrossing.mq4
r4 r5 10 10 11 11 extern double Lots = 0.1; 12 extern double MaximumRisk = 0.02; 13 extern double DecreaseFactor = 3; 14 extern double ShortMovingPeriod = 5; 12 extern double ShortMovingPeriod = 10; 15 13 extern double ShortMovingShift = 0; 16 extern double LongMovingPeriod = 20;14 extern double LongMovingPeriod = 60; 17 15 extern double LongMovingShift = 0; 18 extern double PricePeriod = 2; 19 extern double MinDerivation = 0.0002; 20 extern double MinimumDistance = 0.04; 21 extern double BaseTrailingStop = 50; 16 extern double BaseTrailingStop = 100; 22 17 extern double TrailingStopPart = 0.6; 18 extern int MinBarsBetweenOrders = 10; 23 19 20 /* 24 21 int MathSign(double Value) 25 22 { … … 28 25 else return(0); 29 26 } 27 */ 30 28 31 29 void Check() … … 41 39 static int SameDirectionCount = 0; 42 40 static int LastPolarity; 41 static bool FirstStart = true; 43 42 double TrailingStop; 43 static datetime TimeLastOrder; 44 44 45 45 // Go trading only for first tiks of new bar … … 50 50 LongMovingAverage = iMA(NULL, 0, LongMovingPeriod, LongMovingShift, MODE_SMA, PRICE_MEDIAN, 0); 51 51 if(ShortMovingAverage > LongMovingAverage) Polarity = 1; else Polarity = -1; 52 if( LastPolarity != Polarity) PolarityChanged = true;52 if((LastPolarity != Polarity) && (FirstStart == false)) PolarityChanged = true; 53 53 54 54 /* … … 96 96 // Order conditions 97 97 //if(LastChangeDirection && (SameDirectionCount > 2)) 98 if(PolarityChanged )98 if(PolarityChanged && ((TimeCurrent() - TimeLastOrder) > MinBarsBetweenOrders * (Time[0] - Time[1]))) 99 99 { 100 100 if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + BaseTrailingStop * Point, 0, "", MAGICMA, 0, Red); 101 101 if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - BaseTrailingStop * Point, 0, "", MAGICMA, 0, Blue); 102 PolarityChanged = false;102 TimeLastOrder = TimeCurrent(); 103 103 } 104 PolarityChanged = false; 104 105 105 106 //LastShortMovingAverage = ShortMovingAverage; 106 107 //LastLongMovingAverage = LongMovingAverage; 107 108 LastPolarity = Polarity; 109 FirstStart = false; 108 110 } 109 111 int init()
Note:
See TracChangeset
for help on using the changeset viewer.