Changeset 4


Ignore:
Timestamp:
May 30, 2008, 2:13:47 PM (16 years ago)
Author:
george
Message:

Upraveno: Podmínka pro uzavírání pokynů upravena na dynamické trailing stopy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MovingAverageCrossing.mq4

    r3 r4  
    77#property link      ""
    88
    9 #define MAGICMA  20050610
     9#define MAGICMA  1000000
    1010
    1111extern double Lots               = 0.1;
     
    1414extern double ShortMovingPeriod       = 5;
    1515extern double ShortMovingShift        = 0;
    16 extern double LongMovingPeriod       = 100;
     16extern double LongMovingPeriod       = 20;
    1717extern double LongMovingShift        = 0;
     18extern double PricePeriod       = 2;
    1819extern double MinDerivation      = 0.0002;
    1920extern double MinimumDistance    = 0.04;
     21extern double BaseTrailingStop  = 50;
     22extern double TrailingStopPart  = 0.6;
    2023
    2124int MathSign(double Value)
     
    3841  static int SameDirectionCount = 0;
    3942  static int LastPolarity;
     43  double TrailingStop;
    4044 
    4145  // Go trading only for first tiks of new bar
     
    5963  }
    6064*/
    61 
     65  RefreshRates();
     66 
    6267  // Sell conditions
    6368  for(int i=0; i < OrdersTotal(); i++)
     
    6873    if(OrderType() == OP_BUY)
    6974    {
    70       if(PolarityChanged && (Polarity == -1)) 
    71         OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
     75      TrailingStop = (Bid - OrderOpenPrice()) * TrailingStopPart + BaseTrailingStop * Point;
     76      Print("TrailingStop: " + TrailingStop + ", OpenPrice: " + OrderOpenPrice() + ", Bid: " + Bid);
     77      if(Bid > OrderStopLoss() + TrailingStop)
     78      {
     79        OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop, OrderTakeProfit(), 0, Green);
     80      }
     81      //if(PolarityChanged && (Polarity == -1)) 
     82      //  OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
    7283    }
    7384    if(OrderType() == OP_SELL)
    7485    {
    75      if(PolarityChanged && (Polarity == 1)) 
    76         OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
     86      TrailingStop = (OrderOpenPrice() - Ask) * TrailingStopPart + BaseTrailingStop * Point;
     87      if(Ask < OrderStopLoss() - TrailingStop)
     88      {
     89        OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop, OrderTakeProfit(), 0, Green);
     90      }
     91      //if(PolarityChanged && (Polarity == 1)) 
     92      //  OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
    7793    }
    7894  }
     
    8298  if(PolarityChanged)
    8399  {
    84     if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, "", MAGICMA, 0, Red);
    85     if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, "", MAGICMA, 0, Blue);
     100    if(Polarity == -1) res = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + BaseTrailingStop * Point, 0, "", MAGICMA, 0, Red);
     101    if(Polarity == 1) res = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - BaseTrailingStop * Point, 0, "", MAGICMA, 0, Blue);
    86102    PolarityChanged = false;
    87103  }
Note: See TracChangeset for help on using the changeset viewer.