Leman_Trall

Author: Martingeil� 2011,
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
Leman_Trall
//+----------------------------------------------------------------------------------------+
//|                                                                        Leman_Trall.mq4 |
//|                                                                      Martingeil© 2011, |
//|                                                                          fx.09@mail.ru |
//+----------------------------------------------------------------------------------------+
#property copyright "Martingeil© 2011,"
#property link      "fx.09@mail.ru"
//Òðàë îñíîâàí ïî ñèñòåìå LeManSystem ñ ñàéòå ÌÊË http://codebase.mql4.com/ru/5990
//------------------------------------------------------------------------------------------
extern int N        = 12;   //ïîèñê õàÿ è ëîó â ïðîìåæóòêå áàðîâ
extern int TF       = 3;    //0=òåêóùèé òô,1=Ì1,2=Ì5,3=Ì15,4=Ì30,5=Í1,6=Í4,7=D1,8=W1,9=MN.
extern int Distance = 3;    //äèñòàíöèÿ îò óðîâíÿ Õàÿ è Ëîó
//------------------------------------------------------------------------------------------
double StopUp,StopDn,Tick;
int mper[10]={0,1,5,15,30,60,240,1440,10080,43200};
int q = 1;
//-----------------------------------------------------------------------------------------
int init(){
if(Digits==3 || Digits==5) q=10; 
Distance = Distance * q;
Tick = MarketInfo(Symbol(), MODE_TICKSIZE);
return(0);}
//-----------------------------------------------------------------------------------------
int start()
  {
   StopUp = iLow(Symbol(),mper[TF],iLowest(Symbol(),mper[TF],MODE_LOW,N,1));
   StopDn = iHigh(Symbol(),mper[TF],iHighest(Symbol(),mper[TF],MODE_HIGH,N,1));
   
   for(int i=0;i<OrdersTotal();i++){if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
   if (OrderSymbol()==Symbol()){
   TrailingStop();}}}

   return(0);
  }
//----------------------------------------------------------------------------------------  
void TrailingStop() {

int Stlev;   
double Up,Dn,Sl,B_,A_;

  Stlev  = MarketInfo(Symbol(),MODE_STOPLEVEL);
  Up = NormalizeDouble(StopUp-Distance*Tick,Digits); Dn = NormalizeDouble(StopDn+Distance*Tick,Digits);   
  Sl = NormalizeDouble(Stlev*Tick,Digits);

  if(OrderType()==OP_BUY) {
    RefreshRates();
    B_ = NormalizeDouble(Bid,Digits);
    if(OrderOpenPrice()<Up && OrderStopLoss()<Up && B_-Sl>Up) {
    
    OrderModify(OrderTicket(),OrderOpenPrice(),Up,OrderTakeProfit(),0,Violet);
    return;
    }}
  
  if(OrderType()==OP_SELL) {
    RefreshRates();
    A_ = NormalizeDouble(Ask,Digits);
    if(OrderOpenPrice()>Dn && OrderStopLoss()>Dn && A_+Sl<Dn) {
      
    OrderModify(OrderTicket(),OrderOpenPrice(),Dn,OrderTakeProfit(),0,Violet);
    return;
    }}
}
//----------------------------------------------------------------------------------------  

Comments