Changeset 3


Ignore:
Timestamp:
May 26, 2008, 2:16:05 PM (17 years ago)
Author:
george
Message:
 
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • Test.mq4

    r2 r3  
    1212extern double MaximumRisk        = 0.02;
    1313extern double DecreaseFactor     = 3;
    14 extern double MovingPeriod       = 14;
     14extern double MovingPeriod       = 30;
    1515extern double MovingShift        = 0;
    1616extern double MinDerivation      = 0.0002;
     17extern double MinimumDistance    = 0.04;
    1718
    1819int MathSign(double Value)
     
    2324}
    2425
    25 void CheckForOpen()
     26void Check()
    2627{
    2728  double MovingAverage;
     
    3233  static bool LastChangeDirection = false;
    3334  static int SameDirectionCount = 0;
     35  static double LastChangeMovingAverage;
    3436 
    3537  // Go trading only for first tiks of new bar
     
    4547    LastChangeDirection = true;
    4648    SameDirectionCount = 0;
     49    LastChangeMovingAverage = MovingAverage;
    4750  }
    4851
    4952  // 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 conditions
    72 
    7353  for(int i=0; i < OrdersTotal(); i++)
    7454  {
     
    7858    if(OrderType() == OP_BUY)
    7959    {
    80       if(MathSign(LastDerivation) > MathSign(Derivation)
     60      if(LastChangeDirection
    8161        OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
    8262    }
    8363    if(OrderType() == OP_SELL)
    8464    {
    85       if(MathSign(LastDerivation) < MathSign(Derivation)
     65      if(LastChangeDirection
    8666        OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
    8767    }
    8868  }
     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 
    8979  LastMovingAverage = MovingAverage;
    9080  LastDerivation = Derivation;
    9181}
    92  
    9382int init()
    9483{
     
    10493{
    10594  if((Bars < 100) || (IsTradeAllowed() == false)) return;
    106   CheckForOpen();
    107   CheckForClose();
     95  Check();
    10896  return(0);
    10997}
Note: See TracChangeset for help on using the changeset viewer.