Changeset 2
Legend:
- Unmodified
- Added
- Removed
-
Test.mq4
r1 r2 14 14 extern double MovingPeriod = 14; 15 15 extern double MovingShift = 0; 16 extern double MinDerivation = 0.0002; 16 17 17 18 int MathSign(double Value) … … 29 30 static double LastDerivation; 30 31 double Derivation; 32 static bool LastChangeDirection = false; 33 static int SameDirectionCount = 0; 31 34 32 35 // Go trading only for first tiks of new bar … … 36 39 MovingAverage = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0); 37 40 Derivation = MovingAverage - LastMovingAverage; 38 41 Print("Derivation: " + Derivation); 42 Comment("SameDirectionCount: " + SameDirectionCount); 43 if(MathSign(LastDerivation) == MathSign(Derivation)) SameDirectionCount++; 44 else { 45 LastChangeDirection = true; 46 SameDirectionCount = 0; 47 } 48 39 49 // Sell conditions 40 if( MathSign(LastDerivation) != MathSign(Derivation))50 if(LastChangeDirection && (SameDirectionCount > 2)) 41 51 { 42 Print("Derivation: " + Derivation);43 Comment("Derivation: " + Derivation);44 52 if(MathSign(Derivation) == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, "", MAGICMA, 0, Red); 45 53 if(MathSign(Derivation) == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, "", MAGICMA, 0, Blue); 54 LastChangeDirection = false; 46 55 } 47 56 LastMovingAverage = MovingAverage;
Note:
See TracChangeset
for help on using the changeset viewer.