Changeset 5


Ignore:
Timestamp:
Jun 16, 2008, 3:24:03 PM (16 years ago)
Author:
george
Message:

Přidáno: Omezení minimální prodlevy mezi obchody pro odstranění obchodů při kmitání průměrů kolem sebe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MovingAverageCrossing.mq4

    r4 r5  
    1010
    1111extern double Lots               = 0.1;
    12 extern double MaximumRisk        = 0.02;
    13 extern double DecreaseFactor     = 3;
    14 extern double ShortMovingPeriod       = 5;
     12extern double ShortMovingPeriod       = 10;
    1513extern double ShortMovingShift        = 0;
    16 extern double LongMovingPeriod       = 20;
     14extern double LongMovingPeriod       = 60;
    1715extern 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;
     16extern double BaseTrailingStop  = 100;
    2217extern double TrailingStopPart  = 0.6;
     18extern int MinBarsBetweenOrders = 10;
    2319
     20/*
    2421int MathSign(double Value)
    2522{
     
    2825  else return(0);
    2926}
     27*/
    3028
    3129void Check()
     
    4139  static int SameDirectionCount = 0;
    4240  static int LastPolarity;
     41  static bool FirstStart = true;
    4342  double TrailingStop;
     43  static datetime TimeLastOrder;
    4444 
    4545  // Go trading only for first tiks of new bar
     
    5050  LongMovingAverage = iMA(NULL, 0, LongMovingPeriod, LongMovingShift, MODE_SMA, PRICE_MEDIAN, 0);
    5151  if(ShortMovingAverage > LongMovingAverage) Polarity = 1; else Polarity = -1;
    52   if(LastPolarity != Polarity) PolarityChanged = true;
     52  if((LastPolarity != Polarity) && (FirstStart == false)) PolarityChanged = true;
    5353 
    5454/*
     
    9696  // Order conditions
    9797  //if(LastChangeDirection && (SameDirectionCount > 2)) 
    98   if(PolarityChanged)
     98  if(PolarityChanged && ((TimeCurrent() - TimeLastOrder) > MinBarsBetweenOrders * (Time[0] - Time[1])))
    9999  {
    100100    if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + BaseTrailingStop * Point, 0, "", MAGICMA, 0, Red);
    101101    if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - BaseTrailingStop * Point, 0, "", MAGICMA, 0, Blue);
    102     PolarityChanged = false;
     102    TimeLastOrder = TimeCurrent();
    103103  }
     104  PolarityChanged = false;
    104105 
    105106  //LastShortMovingAverage = ShortMovingAverage;
    106107  //LastLongMovingAverage = LongMovingAverage;
    107108  LastPolarity = Polarity;
     109  FirstStart = false;
    108110}
    109111int init()
Note: See TracChangeset for help on using the changeset viewer.