[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 330

 

Guys, a hint... I am showing you code fragments where market entry conditions are calculated. WHY with the given values of timeframes obtained during optimization

extern int s_signal_period=7;
extern int t_trend_period =7; // 1-M1, 2-M5, 3-M15, 4-M30, 5-H1, 6-H4, 7-D1, 8-W.

i.e. the TF = daytime, the market entry happens at the opening of 4-hour candlesticks, in the strategy tester, when tested on the period H4? There should be an entry ONLY at the opening of the day candles - I give a code and report sections for testing on H4 and D1, Expert Advisor with control of a new bar opening.

xtern string A4 = "Таймфрейм и параметры технических индикаторов";
extern int s_signal_period=7;
extern int t_trend_period =7;
...
static datetime prevtime = 0;       // по ценам открытия

...
int start()
{
   if(Time[0] == prevtime)   return(0);  //ждем нового бара
   prevtime = Time[0];                   //если появился новый бар , включаемся
   
   ...                     
//---------------------------------------------В ЛОНГ-------------------------------------------------------------------------      

      if(((type_op()==OP_BUY) || (Buy_signal==true && Sell_signal==false)) && (orderCount==0 || orderCount < 10) && Period_MA_Fast<Period_MA_Slow && delta_fma()>0 && delta_sma()>0 &&   
           iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,1) > iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,2) && //идентификация впадины 
           iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,2) > iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,3) && //с последующим
           iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,4) > iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,3))   //ростом
            
           WmOrderSend(Symbol(), OP_BUY, Lots_New, Ask,Bid-StopLoss*Point, Bid + TakeProfit*Point, "2MA+Momentum", magic);


//---------------------------------------------В ШОРТ--------------------------------------------------------------------------     
     
      if(((type_op()==OP_SELL) || (Buy_signal==false && Sell_signal==true)) && (orderCount==0 || orderCount < 10) && Period_MA_Fast<Period_MA_Slow  && delta_fma()<0 && delta_sma()<0 &&
          iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,1) < iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,2) && //вершина 
          iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,2) < iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,3) && //с последующим 
          iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,4) < iMomentum(Symbol(),signal_period,Period_M, PRICE_CLOSE,3))   //падением
      
          
           WmOrderSend(Symbol(), OP_SELL, Lots_New, Bid, Ask+StopLoss*Point, Ask - TakeProfit*Point, "2MA+Momentum", magic); 
      
         
 ...          
}//------------------------------------------Конец Старт-----------------------------------------------------

double delta_fma()
  {
    int signal_period= GetPeriod(s_signal_period);
    return(iMA(Symbol(),signal_period,Period_MA_Fast,0,MODE_EMA,PRICE_CLOSE,1)-
           iMA(Symbol(),signal_period,Period_MA_Fast,0,MODE_EMA,PRICE_CLOSE,3));
  }

double delta_sma()
  {
    int trend_period = GetPeriod(t_trend_period); 
    return(iMA(Symbol(),trend_period,Period_MA_Slow,0,MODE_EMA,PRICE_CLOSE,1)-
           iMA(Symbol(),trend_period,Period_MA_Slow,0,MODE_EMA,PRICE_CLOSE,3));
  }

//для оптимизации по всем периодам по всем периодам
int GetPeriod(int period)
{int periodres;
 switch(period)
  {
   case 1: periodres=1;break;     //M1
   case 2: periodres=5;break;     //M5
   case 3: periodres=15;break;    //M15
   case 4: periodres=30;break;    //M30
   case 5: periodres=60;break;    //H1
   case 6: periodres=240;break;   //H4
   case 7: periodres=1440;break;  //D1
   case 8: periodres=10080;break; //W
   default: periodres=1;break;
  }
return(periodres);
} 

Reports. When testing on H4 - entry into the market every 4 hours, if trading conditions are fulfilled, thoughextern int s_signal_period =7;
extern int
t_trend_period =7;

D1 - testing on D1 - entering the market at the opening of D1, at the sameextern int s_signal_period=7;
extern int
t_trend_period =7;

This is supposed to be so... Why does the strategy tester enter the market at the H4 open when testing on H4, but not at the opening of daily candlesticks? becauses_signal_period=7;
extern int
t_trend_period =7;

Thanks for the tip on this issue.

 
Roman.:

Guys, a hint... I am showing you code fragments where market entry conditions are calculated. WHY with the given values of timeframes obtained during optimization

i.e. the TF = daytime, the market entry happens at the opening of 4-hour candlesticks, in the strategy tester, when tested on the period H4? There should be an entry ONLY at the opening of the day candles - I bring sections of the code and test report on H4 and D1, Expert Advisor with control of the opening of a new bar.

Reports. When testing on H4 - entry into the market every 4 hours, if trading conditions are fulfilled, thoughextern int s_signal_period =7;
extern int
t_trend_period =7;

D1 - testing on D1 - entering the market at the opening of D1, at the sameextern int s_signal_period=7;
extern int
t_trend_period =7;

This is supposed to be so... Why does the strategy tester enter the market at the H4 open when testing on H4, but not at the opening of daily candlesticks? becauses_signal_period=7;
extern int
t_trend_period =7;

Thanks for the tip on this issue.


The code given is not sufficient to answer
 
Vinin:

The code given is not enough to answer

How much code do you need? The signal part is there...
 
Vinin:

The given code is not enough to answer

Now I tested it on H1 - it opens trades every hour with s_signal_period=7;
extern t_trend_period =7;
 
Roman.:

Now tested on H1 - opens trades every hour with s_signal_period=7;
extern int t_trend_period =7;


It makes sense to make the signal_period variable global and assign a value to it in init()

And change the control for a new bar

   if(iTime(Symbol(),signal_period,0) == prevtime)   return(0);  //ждем нового бара
   prevtime = iTime(Symbol(),signal_period,0);                   //если появился новый бар , включаемся
 
Vinin:


It makes sense to make the signal_period variable global and assign a value to it in init()

And change the control of the new bar


I see, Victor, thank you - I will try it tonight after work. I will write to this thread with the results.
 
how do I know if an order has caught a moose or not?
 
CLAIN:
any tips on how to know if an order catches a loss or not?

Think right.

Search: detect losing trade site :mql4.com, search for losing trade site :mql4.com

 
CLAIN:
How do I know if an order has caught a loss or not?

If OrderClosePrice()==OrderStopLoss(), then the order is definitely closed on a loss order. The trick is in the area of which profit it was closed. Let us say, the trader has opened a position, set a stop loss, and then, when the position has moved to profit, he/she has moved the stop loss to a positive profit zone - so, if the stop triggered, the order will be closed with profit. The price won back and knocked the order down by the stop. That is, the OrderClosePrice() is really equal to OrderStopLoss(). The ORDER Caught a Moose, but it did not show a loss, but a profit. What do you do in this situation?
 

Hello!

Can you tell me how to calculate the lot size, depending on the entry price, StopLoss and percentage of the deposit? Let's assume the entry price is 1.4500, StopLoss is 1.4400. The risk is 100 pips. If the price of a pip is 0.1 and the risk is 2% of the balance (10000) the lot size would be 0.2. Is it possible to deduce this formula in MQL? I searched almost the entire forum and could not find anything like that. All other methods for lot calculation are completely different.

Thank you.

Reason: