Кто сможет помочь в данном роботе разобраться со стоп лоссом

 

вроде в настройках есть использование тейка и стопа, но все равно не использует стоп, работает с устреднением, и регулированием по торговым сессиям, хотел вот узнать в коде прописан ли стоп, или же вместо стопа только настройка по рискам используется, пока выложу в исходном коде и прикреплю файлы, спасибо заранее за инфу, кто проконсультирует



#property copyright ""

#property link      ""

#define buy -2

#define sell 2

//---- input parameters

extern bool      use_daily_target=true;

double    daily_target=0;

extern double    daily_target1=10;       // daily target untuk session 1

extern double    daily_target2=20;       // daily target untuk session 2

extern double    daily_target3=30;       // daily target untuk session 3

extern bool      use_monthly_target=false;

extern double    monthly_target=300;

extern bool      trade_in_fri=true;

extern int       magic=1;

extern bool      lot_multiplier=true;

extern double    multiplier1=2;

extern double    multiplier2=1.59;

extern double    start_lot=0.1;

extern double    range=25;

extern int       level=10;

extern string LevelMargin1="--Level 1-2=TP1/ 3-9=TP2 --";

extern double    tp_in_money1=10.0;

extern double    tp_in_money2=10.0;

extern string resiko="--Money Protection in prosent--";

extern int       risk_money=50;

extern bool      use_sl_and_tp=false;

extern double    tp=15;

extern string trailing="--Trailing hanya untuk tading manual--";

extern bool   ProfitTrailing = True;  // 

extern int    TrailingStop   = 8;     //

extern int    TrailingStep   = 2;     // 

extern string set_countertrend="--Close all order if countertrend--";

extern bool  countertrend=false;

extern int  counterlevel=3;

extern int  multiplyRecovery=80;  // Pengali untuk mengembalikan lot

extern int  profitRecovery=80;  // Pengali untuk mengembalikan profit

bool      stealth_mode=true;

bool      use_bb=true;

extern string Indikator="--Monitor Indicator --";

extern int       bb_period=1;

extern int       bb_deviation=1;

extern int       bb_shift=0;

extern string stochastic="--k1=Stochastic1/ k2=Stochastic2 --";

bool      use_stoch=true;

extern int       k=34;

extern int       k2=12;

extern int       k3=5;

int       d=3;

int       slowing=3;

int       price_field=0;

int       stoch_shift=0;

extern int       up_level=80;

extern int       lo_level=20;

extern string RSI="--RSI1 = Period 1/RSI2 = Period 2 --";

bool      use_rsi=true;

extern int       rsi_period=14;

extern int       rsi_period2=8;

int       rsi_shift=0;

int       lower=25;

int       upper=75;

extern string MovingAverage="--Setting Moving Average--";

// MovingAverage 1 Slow Periode

int timeframe1=0;

extern int ma_periode1=13;

extern int ma_shift1=0;

extern int ma_method1=1;

extern int applied_price1=0;

extern int shift1=1;

bool      use_MACD=true;

extern bool   UseHourTrade   = true;

extern bool      session1=true;

extern int    StartHour      = 1;

extern int    EndHour        = 4;

extern bool      session2=true;

extern int    StartHour2      = 7;

extern int    EndHour2        = 11;

extern bool      session3=false;

extern int    StartHour3      = 17;

extern int    EndHour3        = 20;

extern bool   EndDayTradeCloseAll = false;

extern int    TimetoClose         = 23;

extern bool   Tradingmanual   = false;


double    sl=0;

double pt;

double minlot;

double stoplevel;

int prec=0;

int a=0;

int i=0;

int ticket=0; 

double point;

double range2=0;

double lprofit=0;

double target=0;

double target0=0;

double target1=0;

double target3=0;

double rageorder=0;

double Totalrageorder=0;

double increament=0.01;

string xsignal=" ";

string xorder=" ";

string xcounter=" ";

string xlongterm=" ";

string xoversignal=" ";

double start_lot0=0.01;

double tp_in_money0=0.01;

bool  countertrend0=true;

int maxloss=0;

int globalloss=0;

int longActive=0,  shortActive=0;

int longStop=0,    shortStop=0;

int longLimit=0,   shortLimit=0;

   

// Accumulative order types

   

int longPending=0, shortPending=0;

int allLong=0,     allShort=0;

int allActive=0,   allPending=0;

int grandTotal=0;   

   

   

double actualProfitMonitor=0;

double actualProfitMonitor_pip=0;


//+------------------------------------------------------------------+

//| expert initialization function                                   |

//+------------------------------------------------------------------+

int init()

  {

range2=range;

increament=start_lot;

start_lot0=start_lot;

tp_in_money0=tp_in_money1;


//----

   if(Digits==3 || Digits==5) pt=10*Point;

   else                          pt=Point;

   minlot   =   MarketInfo(Symbol(),MODE_MINLOT);

   stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);

   if(start_lot<minlot)      Print("lotsize is to small.");

   if(sl<stoplevel)   Print("stoploss is to tight.");

   if(tp<stoplevel) Print("takeprofit is to tight.");

   if(minlot==0.01) prec=2;

   if(minlot==0.1)  prec=1;

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit()

  {

//----

   

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| expert start function                                            |

//+------------------------------------------------------------------+

int start()

  {

  int balance = NormalizeDouble(AccountBalance(),point);

  int equity = NormalizeDouble(AccountEquity(),point);

  int Oporder = NormalizeDouble(total(),point);

   if(!trade_in_fri && DayOfWeek()==5 && total()==0)

   {

     Comment("\nstop trading in Friday.");

     return(0);

   }

   if(DayOfWeek()==0 && total()==0)

   {

     Comment("\nstop trading in Sunday.");

     return(0);

   }

//-----------------

if (UseHourTrade && (Hour() >= StartHour && Hour() <= EndHour) && session1) 

   {daily_target=daily_target1;}

if (UseHourTrade && (Hour() >= StartHour2 && Hour() <= EndHour2) && session2) 

   {daily_target=daily_target2;}

if (UseHourTrade && (Hour() >= StartHour3 && Hour() <= EndHour3) && session3) 

   {daily_target=daily_target3;}

//----------------

   if (UseHourTrade && EndDayTradeCloseAll && Hour() > TimetoClose)

      {

            closeall();

            closeall();

            closeall();

            a++;

            range=range2;

            if(total()==0) a=0;

            return (0);

      }

   if(total()==0)

   {

   findMyOrders();

        if((signal()==sell && counter()==sell)||(longterm()==sell && counter()==sell))

     {target0=Bid;

     //if((signal()==buy && counter()==buy)||(longterm()==buy && counter()==buy))

     //{ target0=Ask;

        if(stealth_mode)

        {

        if(use_daily_target && dailyprofit()>=daily_target) {}

         else

         {

         if(use_monthly_target && monthlyprofit()>=monthly_target){}

           else

           if (!UseHourTrade) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,0,Ask+tp*pt,"",magic,0,Blue);

           else  if(!Tradingmanual) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,        0,        0,"",magic,0,Blue);

           }

           if (UseHourTrade && (Hour() >= StartHour && Hour() <= EndHour) && session1) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,0,Ask+tp*pt,"",magic,0,Blue);

           else  if(!Tradingmanual) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,        0,        0,"",magic,0,Blue);

           }

           if (UseHourTrade && (Hour() >= StartHour2 && Hour() <= EndHour2) && session2) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,0,Ask+tp*pt,"",magic,0,Blue);

           else  if(!Tradingmanual) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,        0,        0,"",magic,0,Blue);

           }

           if (UseHourTrade && (Hour() >= StartHour3 && Hour() <= EndHour3) && session3) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,0,Ask+tp*pt,"",magic,0,Blue);

           else  if(!Tradingmanual) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,        0,        0,"",magic,0,Blue);

           }

          }

        }

     }

     //if((signal()==sell && counter()==sell)||(longterm()==sell && counter()==sell))

     //{target0=Bid;

           if((signal()==buy && counter()==buy)||(longterm()==buy && counter()==buy))

     { target0=Ask;  

        if(stealth_mode)

        {

        if(use_daily_target && dailyprofit()>=daily_target) {}

         else

         {

         if(use_monthly_target && monthlyprofit()>=monthly_target){}

           else

           if (!UseHourTrade) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),1,start_lot,Bid,3,0,Bid-tp*pt,"",magic,0,Red);

           else if(!Tradingmanual)  ticket=OrderSend(Symbol(),1,start_lot,Bid,3,        0,        0,"",magic,0,Red);

           }

           if (UseHourTrade && (Hour() >= StartHour && Hour() <= EndHour) && session1) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),1,start_lot,Bid,3,0,Bid-tp*pt,"",magic,0,Red);

           else if(!Tradingmanual)  ticket=OrderSend(Symbol(),1,start_lot,Bid,3,        0,        0,"",magic,0,Red);

           }

           if (UseHourTrade && (Hour() >= StartHour2 && Hour() <= EndHour2) && session2) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),1,start_lot,Bid,3,0,Bid-tp*pt,"",magic,0,Red);

           else if(!Tradingmanual)  ticket=OrderSend(Symbol(),1,start_lot,Bid,3,        0,        0,"",magic,0,Red);

          }

           if (UseHourTrade && (Hour() >= StartHour3 && Hour() <= EndHour3) && session3) 

           {

           if(use_sl_and_tp) ticket=OrderSend(Symbol(),1,start_lot,Bid,3,0,Bid-tp*pt,"",magic,0,Red);

           else if(!Tradingmanual)  ticket=OrderSend(Symbol(),1,start_lot,Bid,3,        0,        0,"",magic,0,Red);

          }

        }

       }

     } 

   }

   findMyOrders();

        if(use_daily_target && dailyprofit()>=daily_target) {

          for (int i=0; i<OrdersTotal(); i++) {

             if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

                if(Tradingmanual) {TrailingPositions();}

                }

          }

         }

   if(stealth_mode && total()>0 && total()<level)

   {

     int type; double op, lastlot; 

     for(i=0; i<OrdersTotal(); i++)

     {

         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

         if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

         type=OrderType();

         op=OrderOpenPrice();

         lastlot=OrderLots();

     }

//-----------------------------------------------------

     if(type==0 && Ask<=op-(range)*pt) 

     {     target=op;

          if (total()<=2)

           {target1=Ask;

           if(lot_multiplier) ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot*multiplier1,prec),Ask,3,0,0,"",magic,0,Blue);

           else               ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot+increament,prec),Ask,3,0,0,"",magic,0,Blue);

           }

           else

           {

           if(lot_multiplier) ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot*multiplier2,prec),Ask,3,0,0,"",magic,0,Blue);

           else               ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot+increament,prec),Ask,3,0,0,"",magic,0,Blue);

           }

     }

//-----------------------------------------------------

//-----------------------------------------------------

     if(type==1 && Bid>=op+(range)*pt) 

     {     target=op;

          if (total()<=2)

            {target1=Bid;

           if(lot_multiplier) ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot*multiplier1,prec),Bid,3,0,0,"",magic,0,Red);

           else               ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot+increament,prec),Bid,3,0,0,"",magic,0,Red);

           }

           else

            {

           if(lot_multiplier) ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot*multiplier2,prec),Bid,3,0,0,"",magic,0,Red);

           else               ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot+increament,prec),Bid,3,0,0,"",magic,0,Red);

           }

     }

//--------------------------------------------------------

     target3=((target-target1)*10000);

     rageorder=(range);

   }

   double nprofit=0;

   for(i=0; i<OrdersTotal(); i++)

   {

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;

      nprofit+=OrderProfit();

   }

   if (nprofit<=lprofit) {lprofit=nprofit;} 

//--------------------------------------

//--------------------------------------

if (total()>=counterlevel && total()<=6 && countertrend)

{

   if(total()>counterlevel)

   {

      closeall();

      closeall();

      closeall();

      a++;

   start_lot=start_lot0*multiplyRecovery;

   tp_in_money1=tp_in_money0*profitRecovery;

      if(total()==0) a=0;

   }

   if(type==0 && oversignal()==sell && longterm()==sell || total()>counterlevel)

   {

      closeall();

      closeall();

      closeall();

      a++;

   start_lot=start_lot0*multiplyRecovery;

   tp_in_money1=tp_in_money0*profitRecovery;

      if(total()==0) a=0;

   }

   if(type==1 && oversignal()==buy && longterm()==buy || total()>counterlevel) 

   {

      closeall();

      closeall();

      closeall();

      a++;

   start_lot=start_lot0*multiplyRecovery;

   tp_in_money1=tp_in_money0*profitRecovery;

      if(total()==0) a=0;

   }

}

   if(nprofit<-(risk_money*balance/100)) 

   {

      closeall();

      closeall();

      closeall();

   start_lot=start_lot0*multiplyRecovery;

   tp_in_money1=tp_in_money0*profitRecovery;

      if(total()==0) a=0;

   }


//--------------------------------------

if (total()<3 || grandTotal<3)

{

   if(nprofit>=(tp_in_money1))

   {

      closeall();

      closeall();

      closeall();

      a++;

      start_lot=start_lot0;

      tp_in_money1=tp_in_money0;

      if(total()==0) a=0;

   }


}

   

if (total()>=3)

{

   if(nprofit>=tp_in_money2) 

   {

      closeall();

      closeall();

      closeall();

      a++;

      if(total()==0) a=0;

      start_lot=start_lot0;

      tp_in_money1=tp_in_money0;

   }

}

//---------------------------------------

         if (OrderType()==OP_BUY)

         if (OrderSymbol()==Symbol()) {Totalrageorder=((Ask-target0)*10000); xorder="BUY";}

         if (OrderType()==OP_SELL)

         if (OrderSymbol()==Symbol()) {Totalrageorder=((target0-Bid)*10000); xorder="SELL";}

if (Oporder==0) {xorder="No Trade ";}


xsignal="No Trade ";

xcounter="No Trade ";

xlongterm="No Trade ";

xoversignal="No Trade ";

if (nprofit<0 && nprofit<maxloss) {maxloss=nprofit;}

if ((equity-balance)<0 && (equity-balance)<globalloss) {globalloss=(equity-balance);}

if (signal()==buy) {xsignal="-BUY-";}

if (signal()==sell) {xsignal="-SELL-";}

if (counter()==buy) {xcounter="-BUY-";}

if (counter()==sell) {xcounter="-SELL-";}

if (longterm()==buy) {xlongterm="-BUY-";}

if (longterm()==sell) {xlongterm="-SELL-";}

if (oversignal()==buy) {xoversignal="-BUY-";}

if (oversignal()==sell) {xoversignal="-SELL-";}


   Comment("\n               Advisor EA",

           "\n          +==========================+",

           "\n           Pair Use @ M5 : "+Symbol(),

           "\n           Leverage 1  : "+AccountLeverage(),

           "\n           Balance     : "+AccountCurrency()+" "+balance,

           "\n           Equity      : "+AccountCurrency()+" "+equity,

           "\n          +==========================+",

           "\n           Montly  Profit : "+monthlyprofit(),

           "\n           Daily   Profit : "+dailyprofit(),

           "\n           Actual  Profit : "+nprofit,

           "\n          +==========================+",

           "\n           Max Float Loss   : "+maxloss,

           "\n           Total Float Loss : "+globalloss,

           "\n          +==========================+",

           "\n           Open Order  : "+Oporder,

           "\n           Type Order  : "+xorder,

           "\n           RangeOrder  : "+rageorder,

           "\n           ActualRange : "+Totalrageorder,

           "\n           Hari ke     : "+DayOfWeek(),

           "\n          +==========================+",

           "\n           SIGNAL TO TRADE "+xsignal, 

           "\n           SIGNAL COUNTER  "+xcounter,

           "\n           SIGNAL LONGTERM : "+xlongterm,

           "\n           SIGNAL MACD     : "+xoversignal); 

//----

   return(0);

  }

//+------------------------------------------------------------------+

double dailyprofit()

{ lprofit=0;

  int day=Day(); double res=0;

  for(int i=0; i<OrdersHistoryTotal(); i++)

  {

      OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

      if(TimeDay(OrderOpenTime())==day) res+=OrderProfit();

  }

  return(res);

}

double monthlyprofit()

{ lprofit=0;

  int mont=Month(); double res2=0;

  for(int i=0; i<OrdersHistoryTotal(); i++)

  {

      OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

      if(TimeMonth(OrderOpenTime())==mont) res2+=OrderProfit();

  }

  return(res2);

}


//+------------------------------------------------------------------+

int total()

{

  int total=0;

  for(int i=0; i<OrdersTotal(); i++)

  {

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

      total++;

  }

  return(total);

}

//+------------------------------------------------------------------+

int signal()

{

  double upBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_UPPER,bb_shift);

  double loBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_LOWER,bb_shift);

  double stoch=iStochastic(Symbol(),0,k,d,slowing,MODE_SMA,price_field,MODE_SIGNAL,stoch_shift);

  double stoch3=iStochastic(Symbol(),0,k3,d,slowing,MODE_SMA,price_field,MODE_SIGNAL,stoch_shift);

  double rsi=iRSI(Symbol(),0,rsi_period,PRICE_CLOSE,rsi_shift);

  double rsi2=iRSI(Symbol(),0,rsi_period2,PRICE_CLOSE,rsi_shift);

  double EMA1=iMA(Symbol(),timeframe1,ma_periode1,ma_shift1,ma_method1,applied_price1,shift1);

  if(use_bb && use_stoch && use_rsi)

 {

     if(EMA1>upBB  && stoch<up_level && stoch>stoch3 && rsi2<rsi) return(sell);

     if(EMA1<loBB  && stoch>lo_level && stoch<stoch3 && rsi2>rsi) return(buy);

  }

  return(0);

}

//+------------------------------------------------------------------+

int counter()

{

  double upBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_UPPER,bb_shift);

  double loBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_LOWER,bb_shift);

  double stoch=iStochastic(Symbol(),0,k,d,slowing,MODE_SMA,price_field,MODE_SIGNAL,stoch_shift);

  double rsi=iRSI(Symbol(),0,rsi_period,PRICE_CLOSE,rsi_shift);

  double EMA1=iMA(Symbol(),timeframe1,ma_periode1,ma_shift1,ma_method1,applied_price1,shift1);

  double i_trend1= iCustom(Symbol(),0,"i_trend",0,0,0,20,2,13,300,0,1);

  if(use_bb && use_stoch && use_rsi)

 {

     if(EMA1>upBB  && stoch<50 && rsi<45 && i_trend1<-0.001) return(sell);

     if(EMA1<loBB  && stoch>50 && rsi>55 && i_trend1>0.001) return(buy);

  }

  return(0);

}int longterm()

{

  double upBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_UPPER,bb_shift);

  double loBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_LOWER,bb_shift);

  double EMA2=iMA(Symbol(),timeframe1,89,ma_shift1,0,applied_price1,shift1);

  double EMA3=iMA(Symbol(),timeframe1,34,ma_shift1,1,applied_price1,shift1);

  if(use_bb && use_stoch && use_rsi)

 {

     if(EMA2>upBB  && EMA3>upBB) return(sell);

     if(EMA2<loBB  && EMA3<loBB) return(buy);

  }

  return(0);

}

//--------------------------------------------------------------------

int oversignal()

 { 

    double SignalMACD=iMACD(NULL,0,120,260,9,PRICE_CLOSE,MODE_SIGNAL,0);

    double SignalMACD2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);


  if(use_MACD)

 {

     if(SignalMACD>SignalMACD2) return(sell);

     if(SignalMACD<SignalMACD2) return(buy);

  }

    return(0);

  }


//--------------------------------------------------------------------

void closeall()

{  target0=0;

   target1=0;

  for(int i=OrdersTotal()-1; i>=0; i--)

  {   

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

      if(OrderType()>1) OrderDelete(OrderTicket());

      else

      {

        if(OrderType()==0) OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);

        else               OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);

      }

  }

}

//+------------------------------------------------------------------+


void findMyOrders() 

{

   

   actualProfitMonitor=0; 

   

   longActive=0;  shortActive=0;

   longStop=0;    shortStop=0;

   longLimit=0;   shortLimit=0;

   longPending=0; shortPending=0;

   allLong=0;     allShort=0;

   allActive=0;   allPending=0;

   grandTotal=0;   

   


   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)

   {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

         if (OrderType()==OP_BUY)

            {longActive++; actualProfitMonitor=actualProfitMonitor+OrderProfit();}

         if (OrderType()==OP_SELL)

            {shortActive++; actualProfitMonitor=actualProfitMonitor+OrderProfit();}

   }


   longPending  = longStop + longLimit;

   shortPending = shortStop + shortLimit;

   allPending   = longPending + shortPending;

   allActive    = longActive + shortActive;

   allLong      = longStop + longLimit + longActive;

   allShort     = shortStop + shortLimit + shortActive;

   grandTotal   = allActive + allPending;


}

//+------------------------------------------------------------------+

//| Сопровождение позиции простым тралом                             |

//+------------------------------------------------------------------+

void TrailingPositions() {

  double pBid, pAsk, pp;


  pp = MarketInfo(OrderSymbol(), MODE_POINT);

  if (OrderType()==OP_BUY) {

    pBid = MarketInfo(OrderSymbol(), MODE_BID);

    if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {

      if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {

        ModifyStopLoss(pBid-TrailingStop*pp);

        return;

      }

    }

  }

  if (OrderType()==OP_SELL) {

    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);

    if (!ProfitTrailing || (OrderOpenPrice()-pAsk)>TrailingStop*pp) {

      if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp) {

        ModifyStopLoss(pAsk+TrailingStop*pp);

        return;

      }

    }

  }

}


//+------------------------------------------------------------------+

//| Перенос уровня StopLoss                                          |

//| Параметры:                                                       |

//|   ldStopLoss - уровень StopLoss                                  |

//+------------------------------------------------------------------+

void ModifyStopLoss(double ldStopLoss) {

  bool fm;


  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);

}

//+------------------------------------------------------------------+


так же вкладываю дополнительный индикатор для него itrend, так как без него не торгует, а он не вшит в сам робот

//+------------------------------------------------------------------+

//|                                                       iTrend.mq4 |

//|                      Copyright © 2004, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2004, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.net"

//----

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 LimeGreen

#property indicator_color2 Red

//---- input parameters

extern int Bands_Mode_0_2=0;  // =0-2 MODE_MAIN, MODE_LOW, MODE_HIGH

extern int Power_Price_0_6=0; // =0-6 PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED

extern int Price_Type_0_3=0;  // =0-3 PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW

extern int Bands_Period=20;

extern int Bands_Deviation=2;

extern int Power_Period=13;

extern int CountBars=300;

//---- buffers

double value[];

double value2[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

   //   string short_name;

//---- indicator line

   IndicatorBuffers(2);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(0,value);

   SetIndexBuffer(1,value2);

//----

//----

   return(0);

  }

//+------------------------------------------------------------------+

//| Trend                                                         |

//+------------------------------------------------------------------+

int start()

  {

   SetIndexDrawBegin(0,Bars-CountBars+Bands_Period+1);

   SetIndexDrawBegin(1,Bars-CountBars+Bands_Period+1);

   int i,CurrentBar,Bands_Mode,counted_bars=IndicatorCounted();

   double Power_Price,CurrentPrice;

//----

   if(Bars<=Bands_Period) return(0);

//---- initial zero

   if(counted_bars<Bands_Period)

     {

      for(i=1;i<=Bands_Period;i++) value[Bars-i]=0.0;

      for(i=1;i<=Bands_Period;i++) value2[Bars-i]=0.0;

     }

//----

   i=CountBars-Bands_Period-1;

   //   if(counted_bars>=Bands_Period) i=Bars-counted_bars-1;

   if (Bands_Mode_0_2==1) Bands_Mode=MODE_LOW;

   if (Bands_Mode_0_2==2) Bands_Mode=MODE_HIGH;

   if (Bands_Mode_0_2==0) Bands_Mode=MODE_MAIN;

   if (Power_Price_0_6==1) Power_Price=PRICE_OPEN;

   if (Power_Price_0_6==2) Power_Price=PRICE_HIGH;

   if (Power_Price_0_6==3) Power_Price=PRICE_LOW;

   if (Power_Price_0_6==4) Power_Price=PRICE_MEDIAN;

   if (Power_Price_0_6==5) Power_Price=PRICE_TYPICAL;

   if (Power_Price_0_6==6) Power_Price=PRICE_WEIGHTED;

   if (Power_Price_0_6==0) Power_Price=PRICE_CLOSE;

//----

   for(i=CountBars-1; i>=0; i--)

     {

      if (Price_Type_0_3==1) CurrentPrice=Open[i];

      if (Price_Type_0_3==2) CurrentPrice=High[i];

      if (Price_Type_0_3==3) CurrentPrice=Low[i];

      if (Price_Type_0_3==0) CurrentPrice=Close[i];

//----

      value[i]=CurrentPrice-iBands(NULL,0,Bands_Period,Bands_Deviation,0,Bands_Mode,Power_Price,i);

      value2[i]=-(iBearsPower(NULL,0,Power_Period,Power_Price,i)+iBullsPower(NULL,0,Power_Period,Power_Price,i));

     }

   return(0);

  }

//+------------------------------------------------------------------+

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Миллионы трейдеров и сотни брокеров не могут ошибаться — они выбрали MetaTrader 5 для торговли на Форексе и финансовых рынках! Узнать больше
Файлы:
 

легко - но сначала:

* сформулируйте своими словами стратегию

* положите приведённую простыню во фриланс с пожеланием "прокоментить и сократить код" :-)

 
Maxim Kuznetsov:

легко - но сначала:

* сформулируйте своими словами стратегию

* положите приведённую простыню во фриланс с пожеланием "прокоментить и сократить код" :-)

ок спасибо

 

@Azamat Sarsembaev

Для начала, код нужно вставлять в специально для него сделанную форму, а не ляпать пол мили строк в пост...

 
Сергей Таболин:

@Azamat Sarsembaev

Для начала, код нужно вставлять в специально для него сделанную форму, а не ляпать пол мили строк в пост...

Ну может это пригодилось бы кто понимает сразу из записей о чем речь, что бы не тратить время на скачивание и открытие в редакторе, ну учту раз что лучше так просто добавлять файл
 
Azamat Sarsembaev:

... хотел вот узнать в коде прописан ли стоп ...

при открытии ордеров стоп-лосс не ставится

 
Azamat Sarsembaev:
Ну может это пригодилось бы кто понимает сразу из записей о чем речь, что бы не тратить время на скачивание и открытие в редакторе, ну учту раз что лучше так просто добавлять файл
 
Artyom Trishkin:

спасибо, понял как вставлять код

Причина обращения: