Changeset 3
- Timestamp:
- May 26, 2008, 2:16:05 PM (17 years ago)
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Test.mq4
r2 r3 12 12 extern double MaximumRisk = 0.02; 13 13 extern double DecreaseFactor = 3; 14 extern double MovingPeriod = 14;14 extern double MovingPeriod = 30; 15 15 extern double MovingShift = 0; 16 16 extern double MinDerivation = 0.0002; 17 extern double MinimumDistance = 0.04; 17 18 18 19 int MathSign(double Value) … … 23 24 } 24 25 25 void Check ForOpen()26 void Check() 26 27 { 27 28 double MovingAverage; … … 32 33 static bool LastChangeDirection = false; 33 34 static int SameDirectionCount = 0; 35 static double LastChangeMovingAverage; 34 36 35 37 // Go trading only for first tiks of new bar … … 45 47 LastChangeDirection = true; 46 48 SameDirectionCount = 0; 49 LastChangeMovingAverage = MovingAverage; 47 50 } 48 51 49 52 // Sell conditions 50 if(LastChangeDirection && (SameDirectionCount > 2))51 {52 if(MathSign(Derivation) == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, "", MAGICMA, 0, Red);53 if(MathSign(Derivation) == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, "", MAGICMA, 0, Blue);54 LastChangeDirection = false;55 }56 LastMovingAverage = MovingAverage;57 LastDerivation = Derivation;58 }59 60 void CheckForClose()61 {62 double MovingAverage;63 static double LastMovingAverage;64 static double LastDerivation;65 double Derivation;66 67 if(Volume[0] > 1) return;68 MovingAverage = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 0);69 Derivation = MovingAverage - LastMovingAverage;70 71 // Sell conditions72 73 53 for(int i=0; i < OrdersTotal(); i++) 74 54 { … … 78 58 if(OrderType() == OP_BUY) 79 59 { 80 if( MathSign(LastDerivation) > MathSign(Derivation))60 if(LastChangeDirection) 81 61 OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); 82 62 } 83 63 if(OrderType() == OP_SELL) 84 64 { 85 if( MathSign(LastDerivation) < MathSign(Derivation))65 if(LastChangeDirection) 86 66 OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); 87 67 } 88 68 } 69 70 // Order conditions 71 //if(LastChangeDirection && (SameDirectionCount > 2)) 72 if(LastChangeDirection && (MathAbs(MovingAverage - LastChangeMovingAverage) > MinimumDistance)) 73 { 74 if(MathSign(Derivation) == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, "", MAGICMA, 0, Red); 75 if(MathSign(Derivation) == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, "", MAGICMA, 0, Blue); 76 LastChangeDirection = false; 77 } 78 89 79 LastMovingAverage = MovingAverage; 90 80 LastDerivation = Derivation; 91 81 } 92 93 82 int init() 94 83 { … … 104 93 { 105 94 if((Bars < 100) || (IsTradeAllowed() == false)) return; 106 CheckForOpen(); 107 CheckForClose(); 95 Check(); 108 96 return(0); 109 97 }
Note:
See TracChangeset
for help on using the changeset viewer.