[Archive!] WRITING A COUNTRY TOGETHER!!! - page 3

 
dmmikl86 >> :

You may open on the daily and then pull up a stop on the lower fractals of a smaller TF

Played)

added trailing on fractals.


a little more and a grail :D

Files:
gena.mq4  5 kb
 


//+-----------------------------------------------------------------------+
//|                                                              Gena.mq4 |
//+-----------------------------------------------------------------------+
// Описание ТС
// 1. Открытие позиций происходит при пробитии High или Low предыдущего дня
//    SL ставиться на High или Low текущего дня, TP выставляется во внешних переменных, 
//    единственная оговорка не более 1 позиции в день в переменной LastTradeTime 
//    если в ней нет необходимост смело сносите /RomanS/
// 2.
// 3.
// 4.
// 5.
 
// Внешние переменные
extern double TakeProfit = 4000;

extern string vybor_perioda ="1;5;15;30;60;240;1440";
extern int period = 1440;

extern int Fractals_TF = 240;
//extern
double Lots = 0.1;
// Глобальные переменные
int LastTradeTime = 0;      // Время последней открытой сделки
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
  // Поехали... :)
int start() 
 {
//+----фсяки разны значения, индикаторы и т.д. и т.п. :)
double SL=0, TP=0,
Spread=Ask-Bid,
StopLevel=Point*MarketInfo(Symbol(),MODE_STOPLEVEL);
int per;
switch( period)
{
case 1440:  per=PERIOD_D1; 	break;
case 240:   per=PERIOD_H4; 	break;
case 60:    per=PERIOD_H1; 	break;
case 30:    per=PERIOD_M30; 	break;
case 15:    per=PERIOD_M15; 	break;
case 5:     per=PERIOD_M5; 	break;
case 1:     per=PERIOD_M1; 	break;
default:    per=0; 		break;
}

HighD1=iHigh(Symbol(), per,1),
LowD1=iLow(Symbol(), per,1);
//----Критерии открытия позиций
bool Open_Bay=false, Open_Sell=false;
if(Bid > HighD1+0.5*Point) Open_Bay = true; 
if(Bid < LowD1-0.5*Point) Open_Sell = true;
//----Проверяем нужно ли торговать :)// Закрытие позиции// Модификация ордера
int Ticket, cnt, Total=0;
for( cnt=0; cnt<OrdersTotal(); cnt++)
   {
   OrderSelect( cnt, SELECT_BY_POS);
   if(OrderSymbol()==Symbol())
      {
      Total++;
      if(OrderType()==OP_BUY)// long position is opened
         {
         SL= LowerFractal();
         if( SL-0.5*Point>OrderStopLoss()
         && SL-0.5*Point>OrderOpenPrice()
         && Bid- SL> StopLevel+0.5*Point)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0);
            return(0);
            }
         }
//--------
      if(OrderType()==OP_SELL)// Short position is opened
         {
         SL= UpperFractal();
         if( SL+0.5*Point<OrderStopLoss()
         && SL+0.5*Point<OrderOpenPrice()
         && SL-Ask> StopLevel+0.5*Point)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0);
            return(0);
            }
         }
      }
   }
//+----Открытие позиций
int TradeTime=TimeDay(TimeCurrent());
if( Total<1 && LastTradeTime!= TradeTime)
   {
   if( Open_Bay)
      {      
      //SL = LowerFractal();
      SL = iLow(NULL,PERIOD_D1,0);
      if( TakeProfit>0) TP = Ask + TakeProfit*Point;
      if(Bid- SL< StopLevel-0.5*Point) return(0);  // проверяем минимальный уровень стопов
      //Alert("Пробуем открыть Buy ",SYMBOL, " по ",ASK, SL, TP);         
      Ticket=OrderSend(Symbol(),OP_BUY, Lots,Ask,20, SL, TP);
      if ( Ticket > 0)                                                  
         {            
         //Alert ("Открыт ордер Buy ",Ticket);
         LastTradeTime= TradeTime; // задаем время сделки, чтобы сегодня больше не торговать 
         }     
      return(0);
      }
//+----
   if( Open_Sell)
      {      
      //SL = UpperFractal()+Spread;
      SL = iHigh(NULL,PERIOD_D1,0)+ Spread;
      if( TakeProfit>0) TP = Bid - TakeProfit*Point;
      if ( SL-Ask< StopLevel-0.5*Point) return(0); // проверяем минимальный уровень стопов
      Ticket = OrderSend(Symbol(),OP_SELL, Lots,Bid,20, SL, TP);
      if ( Ticket > 0)                                                  
         { 
         //Alert ("Открыт ордер Sell ",Ticket);
         LastTradeTime= TradeTime;  // задаем время сделки, чтобы сегодня больше не торговать
         }         
      }
   }
  return(0);
 }
//+------------------------------------------------------------------+
double LowerFractal()
   {
   for(int i=3; i<iBars(NULL, Fractals_TF)-3; i++)
      {
      double Fractal=iFractals(NULL, Fractals_TF,MODE_LOWER, i);
      if( Fractal!=0.0) return( Fractal);
      }
   }
//+-----
double UpperFractal()
   {
   for(int i=3; i<iBars(NULL, Fractals_TF)-3; i++)
      {
      double Fractal=iFractals(NULL, Fractals_TF,MODE_UPPER, i);
      if( Fractal!=0.0) return( Fractal);
      }
   }
//+-----
 
gince >> :

Only Fractals_TF should probably be named

 
gince >> :

Only Fractals_TF should probably be named

//+-----------------------------------------------------------------------+
//|                                                              Gena.mq4 |
//+-----------------------------------------------------------------------+
// ???????? ??
// 1. ???????? ??????? ?????????? ??? ???????? High ??? Low ??????????? ???
//    SL ????????? ?? High ??? Low ???????? ???, TP ???????????? ?? ??????? ??????????, 
//    ???????????? ???????? ?? ????? 1 ??????? ? ???? ? ?????????? LastTradeTime 
//    ???? ? ??? ??? ???????????? ????? ??????? /RomanS/
// 2.
// 3.
// 4.
// 5.
 
// ??????? ??????????
extern double TakeProfit = 4000;

extern string vybor_perioda ="1;5;15;30;60;240;1440";
extern int period = 1440;

extern int fract = 240;
//extern
double Lots = 0.1;
// ?????????? ??????????
int LastTradeTime = 0;      // ????? ????????? ???????? ??????
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
  // ???????... :)
int start() 
 {
//+----????? ????? ????????, ?????????? ? ?.?. ? ?.?. :)
double SL=0, TP=0,
Spread=Ask-Bid,
StopLevel=Point*MarketInfo(Symbol(),MODE_STOPLEVEL);
int per;
switch( period)
{
case 1440:  per=PERIOD_D1; fract=240;break;
case 240:   per=PERIOD_H4; fract=60;break;
case 60:    per=PERIOD_H1; fract=30;break;
case 30:    per=PERIOD_M30; fract=15;break;
case 15:    per=PERIOD_M15; fract=5;break;
case 5:     per=PERIOD_M5; fract=1;break;
default:    per=0; 		break;
}

double _High=iHigh(Symbol(), per,1);
double _Low=iLow(Symbol(), per,1);
//----???????? ???????? ???????
bool Open_Bay=false, Open_Sell=false;
if(Bid > _High+0.5*Point) Open_Bay = true; 
if(Bid < _Low-0.5*Point) Open_Sell = true;
//----????????? ????? ?? ????????? :)// ???????? ???????// ??????????? ??????
int Ticket, cnt, Total=0;
for( cnt=0; cnt<OrdersTotal(); cnt++)
   {
   OrderSelect( cnt, SELECT_BY_POS);
   if(OrderSymbol()==Symbol())
      {
      Total++;
      if(OrderType()==OP_BUY)// long position is opened
         {
         SL= LowerFractal( fract);
         if( SL-0.5*Point>OrderStopLoss()
         && SL-0.5*Point>OrderOpenPrice()
         && Bid- SL> StopLevel+0.5*Point)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0);
            return(0);
            }
         }
//--------
      if(OrderType()==OP_SELL)// Short position is opened
         {
         SL= UpperFractal( fract);
         if( SL+0.5*Point<OrderStopLoss()
         && SL+0.5*Point<OrderOpenPrice()
         && SL-Ask> StopLevel+0.5*Point)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0);
            return(0);
            }
         }
      }
   }
//+----???????? ???????
int TradeTime=TimeDay(TimeCurrent());
if( Total<1 && LastTradeTime!= TradeTime)
   {
   if( Open_Bay)
      {      
      //SL = LowerFractal();
      SL = iLow(NULL,PERIOD_D1,0);
      if( TakeProfit>0) TP = Ask + TakeProfit*Point;
      if(Bid- SL< StopLevel-0.5*Point) return(0);  // ????????? ??????????? ??????? ??????
      //Alert("??????? ??????? Buy ",SYMBOL, " ?? ",ASK, SL, TP);         
      Ticket=OrderSend(Symbol(),OP_BUY, Lots,Ask,20, SL, TP);
      if ( Ticket > 0)                                                  
         {            
         //Alert ("?????? ????? Buy ",Ticket);
         LastTradeTime= TradeTime; // ?????? ????? ??????, ????? ??????? ?????? ?? ????????? 
         }     
      return(0);
      }
//+----
   if( Open_Sell)
      {      
      //SL = UpperFractal()+Spread;
      SL = iHigh(NULL,PERIOD_D1,0)+ Spread;
      if( TakeProfit>0) TP = Bid - TakeProfit*Point;
      if ( SL-Ask< StopLevel-0.5*Point) return(0); // ????????? ??????????? ??????? ??????
      Ticket = OrderSend(Symbol(),OP_SELL, Lots,Bid,20, SL, TP);
      if ( Ticket > 0)                                                  
         { 
         //Alert ("?????? ????? Sell ",Ticket);
         LastTradeTime= TradeTime;  // ?????? ????? ??????, ????? ??????? ?????? ?? ?????????
         }         
      }
   }
  return(0);
 }
//+------------------------------------------------------------------+
double LowerFractal(int fract)
   {
int Fractals_TF;
 Fractals_TF= fract;
   for(int i=3; i<iBars(NULL, Fractals_TF)-3; i++)
      {
      double Fractal=iFractals(NULL, Fractals_TF,MODE_LOWER, i);
      if( Fractal!=0.0) return( Fractal);
      }
   }
//+-----
double UpperFractal(int fract)
   {
   int Fractals_TF;
 Fractals_TF= fract;
   for(int i=3; i<iBars(NULL, Fractals_TF)-3; i++)
      {
      double Fractal=iFractals(NULL, Fractals_TF,MODE_UPPER, i);
      if( Fractal!=0.0) return( Fractal);
      }
   }
//+-----
 
sayfuji >> :

I think it is correct to rely on the following things:

- the nature of the movement within the breakout range, and the sentiment before the breakout(which is less important)

- The general trend, possibly on a larger TF.

As for the last one, try to dance from Parabolic, maybe it will help.

Wrote... The result turned out to be worse than originally.... Prof. factor is only 1.31 after optimisation :(

I think it is more sensible to use oscillators in this system

//+-----------------------------------------------------------------------+
//|                                                     Крокодил ГЕНА.mq4 |
//|                                                         Крокодил ГЕНА |
//+-----------------------------------------------------------------------+
// Описание ТС
// 1. Открытие позиций происходит при пробитии High или Low предыдущего дня
//    SL ставиться на High или Low текущего дня, TP выставляется во внешних переменных, 
//    единственная оговорка не более 1 позиции в день в переменной LastTradeTime 
//    если в ней нет необходимости смело сносите /RomanS/
// 2. Добавил к условию открытия трендовый параболик + трал. стоп по нему же на М5. 
//    Результат оказался хуже :( /RomanS/
// 3.
// 4.
// 5.
 
  // Внешние переменные
  extern double TakeProfit = 900;
  extern double SAR_steep  = 0.0005;
  extern double Lot        = 1;    
  extern string SYMBOL     = "EURUSD";
  
  // Глобальные переменные
  int LastTradeTime = 0;      // Время последней открытой сделки
  
  // Поехали... :)
  int start() 
  {  
     int Ticket;
  double BID,
         ASK,
         SL=0,
         TP=0;                                  
    bool Trade     = true,
         Open_Bay  = false,
         Open_Sell = false;

  // Проверяем можно ли торговать
  if ( Trade==true) 
   {
   
  // Критерии открытия позиций
    ASK = MarketInfo( SYMBOL,10);
    BID = MarketInfo( SYMBOL,9);
    if ( BID > iHigh ( SYMBOL,PERIOD_D1,1) && iSAR( SYMBOL,PERIOD_M5, SAR_steep,0.2,0)< BID) Open_Bay = true; 
    if ( BID < iLow ( SYMBOL,PERIOD_D1,1) && iSAR( SYMBOL,PERIOD_M5, SAR_steep,0.2,0)> BID) Open_Sell = true;
        
  // Открытие позиций
      if ( Open_Bay == true && OrdersTotal()==0 && TimeDay(TimeCurrent())!= LastTradeTime)                                           
        {      
         RefreshRates(); 
          SL = iLow( SYMBOL,PERIOD_D1,0);
          TP = ASK + TakeProfit*Point;
          if (( ASK- SL)/Point<MarketInfo( SYMBOL,14)) return;  // проверяем минимальный уровень стопов
          Alert("Пробуем открыть Buy ", SYMBOL, " по ", ASK, SL, TP);         
          Ticket=OrderSend( SYMBOL,OP_BUY, Lot, ASK,20, SL, TP);         
           if ( Ticket > 0)                                                  
            {            
             Alert ("Открыт ордер Buy ", Ticket);
             LastTradeTime=TimeDay(TimeCurrent()); // задаем время сделки, чтобы сегодня больше не торговать 
             return;                                                       
            }         
        }
     if ( Open_Sell == true && OrdersTotal()==0 && TimeDay(TimeCurrent())!= LastTradeTime)                                             
        {      
         RefreshRates();                                             
          SL = iHigh ( SYMBOL,PERIOD_D1,0);
          TP = BID - TakeProfit*Point;
          if (( SL- BID)/Point<MarketInfo( SYMBOL,14)) return; // проверяем минимальный уровень стопов
          Ticket = OrderSend( SYMBOL,OP_SELL, Lot, BID,20, SL, TP);         
           if ( Ticket > 0)                                                  
             { 
              Alert ("Открыт ордер Sell ", Ticket);
              LastTradeTime=TimeDay(TimeCurrent());  // задаем время сделки, чтобы сегодня больше не торговать
              return;                                   
             }         
          return;                                                       
        }
   
   // Закрытие позиции
   // .......
   
   // Модификация ордера
    for(int i=0; i<=OrdersTotal(); i++)      
      {  
       if (OrderSelect( i, SELECT_BY_POS)==true)     
         {                                       
         if (OrderSymbol()!= SYMBOL) continue;    
          if (OrderType() == 0)                                                    
            {               
             double TralStop = iSAR( SYMBOL,PERIOD_M5, SAR_steep,0.2,0);
             if ( SL < TralStop)                   
               {
                SL= TralStop;                                   
                 bool Ans=OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0); 
                 if ( Ans == true)                                       
                  {               
                //   Alert ("Ордер Bay ","EURUSD"," №",Ticket," модифицирован. Новый Stop Loss ", SL);               
                   break;                                             
                  }   
               }
            }
          if (OrderType() == 1)               
            {  
             TralStop = iSAR( SYMBOL,PERIOD_M5, SAR_steep,0.2,0);
              if ( SL > TralStop)  
               {
                SL= TralStop;  
                if (( SL- ASK)/Point<MarketInfo("EURUSD",14)) break;                  
                Ans=OrderModify(OrderTicket(),OrderOpenPrice(), SL,OrderTakeProfit(),0); 
                 if ( Ans == true)                                       
                   {               
                  //  Alert ("Ордер Sell ","EURUSD"," №",Ticket," модифицирован. Новый Stop Loss ", SL);               
                    break;                                             
                    }         
               }
            }
         }
      }
   }
  return;       
  }
 

Anyway, I'm not trying to write a super system here... I described the reason for doing this at the beginning of the thread.

I wanted to check something out, namely. My main goal is (I didn't want to say so at first, but I think this branch is going to be extinguished) to find out how the system that I am improving over a period of history (say, last half year) will behave over previous periods. I told at the beginning it's a 50/50 system in a long term, i.e. if we draw the system in 2009 at maximum profitability, will it work better in the past ... Suppose we take it to the level of pr.f.. 2.0 or higher... will it perform better since e.g. 2000 ? ???

I assume (and only assume!!!) that the better it performs today, the worse it will perform in the long run. I.e. we gain maximal profit today, and the system will not show 1,0 on history, and probably will fall to 0,9

But this is just a guess... I'm not trying to prove anything yet.... And honestly, I hope I'm wrong.

 

I honestly don't understand why trying to figure out how the system will behave in the past. It is better to look to the future. The market is changing and there is no getting away from it. Even if

Я предпологаю (и только предпологаю!!!), что чем лучше она будет работать сегодня, тем хуже она отработает в долгосрочке.

even if it does, so what?

My personal supposition (and only supposition))) is that there is no dependence, and having said (even having proved) this for one system, or even for a thousand systems, it is not a fact that it will be the same for absolutely all systems.

There is a good saying - do not look for happiness where it is not present.

 
sayfuji >> :

My personal belief (and only belief))) is that there is no dependency.

That's what I want to make sure of...

Take an Expert Advisor that works 50/50 on history and add some extra indicators, oscillators and other tricks to it. Test it on a small period of time (half a year) and see what happens...

Many thanks to Swan and gince for showing interest. And you'dbetter sayfuji suggest something .... like how to close a position on something other than the t.p., maybe it would help...

 
RomanS >> :

Just open at breakdown of the previous day's High/Low with a fixed TP and stop at this day's High/Low. Why exactly? Because it doesn't use any indicator.

My idea is 100% the same)) only on H4 Results tester...

The only thing is... My direction is chosen by the previous candle, and the stop is set at the lower of the two - the current/previous High/Low...



 
ALex2008 >> :

My idea is 100% the same)) only on H4 Results tester...

The only thing is... my direction is chosen by the previous candle, and the stop is placed by the smaller of the two - the current/previous high/low...



Great idea... it's worth trying to dance from it...

I looked at the link, the period is small... have you tried with 2000? maybe the same problem will occur.... 50/50???

Reason: