← К каталогу
Исходный код · ID 2606

TradeStarTrend[EA]

tradestartrend[ea].mq4
Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Краткий обзор

О программе

Советник проверяет наличие открытых позиций по своему магическому номеру, рассчитывает размер лота с учётом управления рисками или фиксированного минимума, а также формирует комментарии на экране с текущей информацией о позиции и настройках. При закрытии ордеров отправляется email-уведомление. В коде реализована защита от одновременного открытия и закрытия позиции по одному и тому же сигналу жёлтого цвета индикатора.

Настройки программы

НастройкаОписание
Star_Trend_Options Настройки Star Trend — Текстовый разделитель группы настроек, связанных с индикатором GLS-StarTrend и временными фреймами
SL_TP_Trail_Options Настройки стоп-лосса, тейк-профита и трейлинга — Текстовый разделитель группы настроек фиксированных и трейлинговых стоп-лоссов, тейк-профита и перемещения в безубыток
Lot_Money_Management Управление лотом и деньгами — Текстовый разделитель группы настроек размера лота и управления рисками
MaximumRisk Максимальный риск — Максимальный процент от свободного маржи, используемый для расчёта размера лота при включённом управлении деньгами
Magic Магический номер — Уникальный идентификатор ордеров советника, используемый для фильтрации и управления позициями
Trading_Hours_Options Настройки торговых часов — Текстовый разделитель группы настроек ограничения времени открытия новых сделок
Juice_Options Настройки Juice — Текстовый разделитель группы настроек фильтра Juice на основе стандартного отклонения
ADX_Option Настройки ADX — Текстовый разделитель группы настроек фильтра Average Directional Movement Index
Получить полный код

Поиск по коду файла

extern string  Star_Trend_Options="--------------------------";
extern int     Trigger.Period=60;                                 // gls-startrend trigger time frame
extern int     Filter.Period.1=240;                               // gls-startrend first filter time frame.

extern int     Filter.Period.2=1440;                              // gls-startrend second filter time frame - can be optional
extern bool    Entry.On.Yellow=true;                              // enter a position if yellow appears on any t/f
extern bool    Exit.On.Yellow=true;                               // exit a position if yellow appears on t/f specified below and all t/f above that
extern int     Exit.On.Yellow.Period=60;                          // t/f for yellow change exit
extern bool    Use.Only.First2.Indicators=false;                  // if true, entries and exits will be based on trigger.period and filter.period.1 only
extern string  SL_TP_Trail_Options="--------------------------";
extern int     StopLoss.Pips=80;                                  // static, initial s/l. Unused if Use.Adr.for.sl.pips = true
extern int     TakeProfit.Pips=300;                               // static, initial take profit
extern int     Trail.Pips=50;                                     // trail.pips. Unused if Use.Adr.for.sl.pips=true or if value=0
extern bool    Trail.Starts.After.BreakEven=false;                // if true trailing will start after a profit of "Move.To.BreakEven.at.pips" is made
extern int     Move.To.BreakEven.at.pips=35;                      // trades in profit will move to entry price + Move.To.BreakEven.Lock.pips

extern int     Move.To.BreakEven.Lock.pips=1;
extern int     Move.Trail.Every.xx.Pips=0;                        // If > 0 then ALL other s/l are dropped and trail will only move by

extern bool    Use.ADR.for.SL.pips=false;                         // if true s/l and trail according to average daily range and tsl.divisor
extern double  tsl.divisor=0.40;
extern string  Lot_Money_Management="--------------------------";
extern bool    Use.Money.Management=false;
extern double  Minimum.Lot=0.1;
extern double  MaximumRisk=0.03;
extern int     Lot.Margin=50;
extern int     Magic=2006;
extern string  Trading_Hours_Options="--------------------------";
extern bool    Use.Trading.Hours.Restriction = false;             // time filter. if true, expert will open new orders only between
extern int     Start.Trading.Hour.Begin=0;                        // Start.Trading.Hour.Begin and Start.Trading.Hour.End
extern int     Start.Trading.Hour.End=24;
extern string  Juice_Options="--------------------------";
extern bool    Use.Juice=false;                                   // if true, std deviation limit will be used as filter (know as Juice indicator)
extern int     Juice.TimeFrame=5;                                 // time frame for juice. Should be in accordance with trigger.period
extern int     Juice.Period=7;                                    // Juice Period
extern int     Juice.Level=4;                                     // Juice Threshold level used for the filtering
extern string  ADX_Option="--------------------------";
extern bool    Use.Adx= false;                                    // if true, Avereage Directional Movement Index (ADX) MAIN LINE will be used as filter
extern int     Adx.TimeFrame= 5;                                  // time frame on which to evaluate ADX
extern int     Adx.Period=14;                                     // ADX Period
extern int     Adx.Threshold=20;                                  // ADX Main Line threshold value used for the filtering

int b.ticket, s.ticket,slip, TodaysRange;
string DR, DR1, comment=" TST v1.10",ScreenComment="TradeStarTrend[EA] v1.10";
double avg.rng, rng, sum.rng, x;
int Trig_1_Green, Trig_1_MediumSeaGreen, Trig_1_Red, Trig_1_LightCoral, Trig_1_Yellow;
int Trig_2_Green, Trig_2_MediumSeaGreen, Trig_2_Red, Trig_2_LightCoral, Trig_2_Yellow;
int Per1_1_Green, Per1_1_MediumSeaGreen, Per1_1_Red, Per1_1_LightCoral, Per1_1_Yellow;
int Per1_2_Green, Per1_2_MediumSeaGreen, Per1_2_Red, Per1_2_LightCoral, Per1_2_Yellow;
int Per2_1_Green, Per2_1_MediumSeaGreen, Per2_1_Red, Per2_1_LightCoral, Per2_1_Yellow;
int Per2_2_Green, Per2_2_MediumSeaGreen, Per2_2_Red, Per2_2_LightCoral, Per2_2_Yellow;
bool TradingEnabled, LongTradeEnabled, ShortTradeEnabled, ShortTradeShouldClose, LongTradeShouldClose;
double ADXMain1, PlusDI1, MinusDI1, ADXMain2, PlusDI2, MinusDI2, CurrentJuice, TPPrice;

int init()
{
      // код доступен только после оплаты
   }

int deinit()
{  return(0);
}

int start()
{
      // код доступен только после оплаты
   } // start

void Indicator.Values()
{  Trig_1_Green            =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 0, 1); //Green.
   Trig_1_MediumSeaGreen   =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 1, 1); //MediumSeaGreen.
   Trig_1_Red              =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 2, 1); //Red.
   Trig_1_LightCoral       =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 3, 1); //LightCoral.
   Trig_1_Yellow           =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 4, 1); //Neutral Yellow.

   Trig_2_Green            =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 0, 2); //Green.
   Trig_2_MediumSeaGreen   =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 1, 2); //MediumSeaGreen.
   Trig_2_Red              =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 2, 2); //Red.
   Trig_2_LightCoral       =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 3, 2); //LightCoral.
   Trig_2_Yellow           =iCustom(NULL,Trigger.Period, "GLS-StarTrend", 4, 2); //Neutral Yellow.

   Per1_1_Green            =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 0, 1); //Green.
   Per1_1_MediumSeaGreen   =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 1, 1); //MediumSeaGreen.
   Per1_1_Red              =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 2, 1); //Red.
   Per1_1_LightCoral       =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 3, 1); //LightCoral.
   Per1_1_Yellow           =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 4, 1); //Neutral Yellow.

   Per1_2_Green            =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 0, 2); //Green.
   Per1_2_MediumSeaGreen   =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 1, 2); //MediumSeaGreen.
   Per1_2_Red              =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 2, 2); //Red.
   Per1_2_LightCoral       =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 3, 2); //LightCoral.
   Per1_2_Yellow           =iCustom(NULL,Filter.Period.1, "GLS-StarTrend", 4, 2); //Neutral Yellow.

   Per2_1_Green            =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 0, 1); //Green.
   Per2_1_MediumSeaGreen   =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 1, 1); //MediumSeaGreen.
   Per2_1_Red              =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 2, 1); //Red.
   Per2_1_LightCoral       =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 3, 1); //LightCoral.
   Per2_1_Yellow           =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 4, 1); //Neutral Yellow.

   Per2_2_Green            =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 0, 2); //Green.
   Per2_2_MediumSeaGreen   =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 1, 2); //MediumSeaGreen.
   Per2_2_Red              =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 2, 2); //Red.
   Per2_2_LightCoral       =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 3, 2); //LightCoral.
   Per2_2_Yellow           =iCustom(NULL,Filter.Period.2, "GLS-StarTrend", 4, 2); //Neutral Yellow.
}

void Filter.Values()
{  if (Use.Adx)
   {  ADXMain1=iADX(NULL,Adx.TimeFrame,Adx.Period,PRICE_CLOSE,MODE_MAIN,1);

      ADXMain2=iADX(NULL,Adx.TimeFrame,Adx.Period,PRICE_CLOSE,MODE_MAIN,2);

   }
   if (Use.Juice)
   {  CurrentJuice = Juice(1, Juice.Period, Juice.Level,Juice.TimeFrame);
   }
}

double Daily.Range()
{  if (DR==TimeToStr(CurTime(),TIME_DATE))
   {  return(NormalizeDouble(avg.rng,Digits));
   }
   rng=0;sum.rng=0;avg.rng=0;
   for (int i=0;i<iBars(Symbol(),1440);i++)
   {  rng=(iHigh(Symbol(),PERIOD_D1,i)-iLow(Symbol(),PERIOD_D1,i));
      sum.rng+=rng;
   }
   double db=iBars(Symbol(),1440);
   avg.rng=sum.rng/db;
   DR=TimeToStr(CurTime(),TIME_DATE);
   return (NormalizeDouble(avg.rng,Digits));
}

void PosCounter()
{  b.ticket=0;s.ticket=0;
   for (int cnt=0;cnt<=OrdersTotal();cnt++)
   {  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
      {  if (OrderType()==OP_SELL)
         {  s.ticket=OrderTicket();
         }
         if (OrderType()==OP_BUY)
         {  b.ticket=OrderTicket();
         }
      }
   }
}

double LotCalc()
{  double lot;
   if (Use.Money.Management)
   {  //lot=AccountFreeMargin()*(MaximumRisk/Lot.Margin);
      lot=NormalizeDouble((AccountFreeMargin()*MaximumRisk)/(MarketInfo(Symbol(),MODE_TICKVALUE)*StopLoss.Pips),2);
   }
   if (!Use.Money.Management) {lot=Minimum.Lot;}
   return(lot);
}

void comments()
{  string s0="", s1="", s2="", s3="", swap="", sCombo="", sStr ;
   int PipsProfit;
   double AmountProfit;
   PipsProfit=0; AmountProfit=0;
   PosCounter();
   if (b.ticket>0) 
   {  OrderSelect(b.ticket,SELECT_BY_TICKET);
      PipsProfit=NormalizeDouble(((Bid - OrderOpenPrice())/Point),Digits);
      AmountProfit=OrderProfit();
   }
   else if (s.ticket>0) 
   {  OrderSelect(s.ticket,SELECT_BY_TICKET);
      PipsProfit=NormalizeDouble(((OrderOpenPrice()-Ask)/Point),Digits);
      AmountProfit=OrderProfit();
   }
   if (Exit.On.Yellow)              s0="Exit if Yellow on "+Exit.On.Yellow.Period+" min";
   else                             s0="";
   if (Move.To.BreakEven.at.pips>0) s1="s/l will move to b/e after: "+Move.To.BreakEven.at.pips+" pips   and lock: "+Move.To.BreakEven.Lock.pips+" pips"+"\n\n";
   else                             s1="";
   if (Use.Juice)                   s2="Use Juice: Yes  Juice.TimeFrame: "+Juice.TimeFrame+"\n";
   else                             s2="Use Juice: No";
   if (Use.Adx)                     s3="Use ADX: Yes    ADX TimeFrame:"+Adx.TimeFrame +"    Adx Threshold: "+Adx.Threshold+"\n";
   else                             s3="Use ADX: No";
   if (Use.Only.First2.Indicators) sCombo=Trigger.Period+"/"+Filter.Period.1;
   else sCombo=Trigger.Period+"/"+Filter.Period.1+"/"+Filter.Period.2;
   Comment( ScreenComment,"\n",
            "Today\'s Range: ",TodaysRange,"\n",
            "Combo Used: ",sCombo,"  ",s0,"\n",
            "s/l: ",StopLoss.Pips,"  tp:",TakeProfit.Pips,"  trail:",Trail.Pips,"\n",
            s1,
            s2,"\n",
            s3,"\n",
            "\n", "Pips: ",PipsProfit,"  /  $ ", AmountProfit,
          );
}

void Trail.With.ADR(int AfterBE)
{  double bsl, b.tsl, ssl, s.tsl;
   PosCounter();

   if (AfterBE==0) // Trail Starts immediately
   {  if(b.ticket>0)
      {  bsl=NormalizeDouble(x,Digits);
         b.tsl=0;
         OrderSelect(b.ticket,SELECT_BY_TICKET);

         if (OrderStopLoss()<OrderOpenPrice() && OrderOpenPrice()-OrderStopLoss()<x)
         {  bsl=OrderOpenPrice()-OrderStopLoss();
         }

         if (OrderStopLoss()<OrderOpenPrice() && OrderOpenPrice()-OrderStopLoss()>=x)
         {  bsl=NormalizeDouble(x,Digits);
         }

         if (Bid>(OrderOpenPrice()+bsl) && OrderStopLoss()<(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl))))
         {  b.tsl=NormalizeDouble(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl)),Digits);
            Print("b.tsl ",b.tsl);
            if (OrderStopLoss()<b.tsl)
            {  OrderModify(b.ticket,OrderOpenPrice(),b.tsl,OrderTakeProfit(),OrderExpiration(),MediumSpringGreen);
            }
         }
      }
      if(s.ticket>0)
      {  ssl=NormalizeDouble(x,Digits);
         s.tsl=0;
         OrderSelect(s.ticket,SELECT_BY_TICKET);

         if (OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()-OrderOpenPrice()<x)
         {  ssl=OrderStopLoss()-OrderOpenPrice();
         }

         if (OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()-OrderOpenPrice()>=x)
         {  ssl=NormalizeDouble(x,Digits);
         }

         if (Ask<(OrderOpenPrice()-ssl) && OrderStopLoss()>(OrderOpenPrice()-(OrderOpenPrice()-ssl)-Ask))
         {  s.tsl=NormalizeDouble(OrderOpenPrice()-((OrderOpenPrice()-ssl)-Ask),Digits);
            Print("s.tsl ",s.tsl);
            if(OrderStopLoss()>s.tsl)
            {  OrderModify(s.ticket,OrderOpenPrice(),s.tsl,OrderTakeProfit(),OrderExpiration(),MediumVioletRed);
            }
         }
      }
   }
   else // If Trail.Starts.After.BreakEven
   {  if (b.ticket>0)
      {  bsl=NormalizeDouble(x,Digits);
         b.tsl=0;
         OrderSelect(b.ticket,SELECT_BY_TICKET);
         if (Bid>=(OrderOpenPrice()+(Move.To.BreakEven.at.pips*Point)))
         {  //if stoploss is less than minimum wave range, set bsl to current SL
            if (OrderStopLoss()<OrderOpenPrice() && OrderOpenPrice()-OrderStopLoss()<x)
            {  bsl=OrderOpenPrice()-OrderStopLoss();
            }

            if (OrderStopLoss()<OrderOpenPrice() && OrderOpenPrice()-OrderStopLoss()>=x)
            {  bsl=NormalizeDouble(x,Digits);
            }

            if (Bid>(OrderOpenPrice()+bsl) && OrderStopLoss()<(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl))))
            {  b.tsl=NormalizeDouble(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl)),Digits);
               Print("b.tsl ",b.tsl);
               if (OrderStopLoss()<b.tsl)
               {  OrderModify(b.ticket,OrderOpenPrice(),b.tsl,OrderTakeProfit(),OrderExpiration(),MediumSpringGreen);
               }
            }
         }
      }
      if (s.ticket>0)
      {  ssl=NormalizeDouble(x,Digits);
         s.tsl=0;
         OrderSelect(s.ticket,SELECT_BY_TICKET);
         if (Ask<=(OrderOpenPrice()-(Move.To.BreakEven.at.pips*Point)))
         {  //if stoploss is less than minimum wave range, set ssl to current SL
            if(OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()-OrderOpenPrice()<x)
            {  ssl=OrderStopLoss()-OrderOpenPrice();
            }

            if(OrderStopLoss()>OrderOpenPrice() && OrderStopLoss()-OrderOpenPrice()>=x)
            {  ssl=NormalizeDouble(x,Digits);
            }

            if(Ask<(OrderOpenPrice()-ssl) && OrderStopLoss()>(OrderOpenPrice()-(OrderOpenPrice()-ssl)-Ask))
            {  s.tsl=NormalizeDouble(OrderOpenPrice()-((OrderOpenPrice()-ssl)-Ask),Digits);
               Print("s.tsl ",s.tsl);
               if(OrderStopLoss()>s.tsl)
               {  OrderModify(s.ticket,OrderOpenPrice(),s.tsl,OrderTakeProfit(),OrderExpiration(),MediumVioletRed);
               }
            }
         }
      }
   }
}

void Trail.With.Standard.Trailing(int AfterBE)
{  double bsl, b.tsl, ssl, s.tsl;
   PosCounter();
   if (AfterBE==0)
   {  if (b.ticket>0)
      {  bsl=Trail.Pips*Point;
         OrderSelect(b.ticket,SELECT_BY_TICKET);

         if(Bid>(OrderOpenPrice()+bsl) && OrderStopLoss()<(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl))))
         {  b.tsl=NormalizeDouble(OrderOpenPrice()+(Bid-(OrderOpenPrice()+bsl)),Digits);
            Print("b.tsl ",b.tsl);
            if (OrderStopLoss()<b.tsl)
            {  OrderModify(b.ticket,OrderOpenPrice(),b.tsl,OrderTakeProfit(),OrderExpiration(),MediumSpringGreen);
            }
         }
      }
      if(s.ticket>0)
      {  ssl=Trail.Pips*Point;

         OrderSelect(s.ticket,SELECT_BY_TICKET);
         if (Ask<(OrderOpenPrice()-ssl) && OrderStopLoss()>(OrderOpenPrice()-(OrderOpenPrice()-ssl)-Ask))
         {  s.tsl=NormalizeDouble(OrderOpenPrice()-((OrderOpenPrice()-ssl)-Ask),Digits);
            Print("s.tsl ",s.tsl);
            if (OrderStopLoss()>s.tsl)
            {  OrderModify(s.ticket,OrderOpenPrice(),s.tsl,OrderTakeProfit(),OrderExpiration(),MediumVioletRed);
            }
         }
      }
   }
   else // If Trail.Starts.After.BreakEven
   {  if (b.ticket>0)
      {  OrderSelect(b.ticket,SELECT_BY_TICKET);
         if (Bid>=(OrderOpenPrice()+(Move.To.

Показано первые 50% кода (символов: 27556)

Открыть по тарифу

Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.

Разовая покупка файла

На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.

Чтобы оформить заказ, введите email и перейдите к оплате.

Стоимость полного кода
2 755,60₽ ≈ $33.68