[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 702

 
keekkenen:

static int time = Time[0];

if (time < Time[0]){

// old candle

} else {

// new candle

time = Time[0];

}

There are now half as many deals as there were before
 
T-G:
Now the trades are half as long as they were before

Instead of checking for a new bar, just pause between openings, set in seconds:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество секунд после открытия последней позиций. |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
datetime SecondsAfterOpenLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) t=OrderOpenTime();
            }
          }
        }
      }
    }
  }
  return(TimeCurrent()-t);
}

I check it this way (in bold, ignore /*PauseMain*/ - it's a random value of delay in minutes - from 5 to 9):

// Тут начало функции открытия позиций (открытие Buy)....

// Ниже код открытия Sell:        
          PauseMain51=random(5,9)*60;
         if (!Lot()) return;               // Средств не хватает на миним.- выходим
         if (!OpnSell51 || !Trade) return;
         if (ExistPositions(NULL, OP_SELL, 51, 0))  // Если есть такой же открытый Sell
               {
                 if (SecondsAfterOpenLastPos(NULL, OP_SELL, 51)<=/* PauseMain51*/ 7*60) return; (7*60 сек = 7 минут)
                  // Если прошло мало времени - валим
               }
//---------------------- Позиции ещё нету - открываемся...-----------------------------
         divider=1;
         Lots=GetSizeLot();
         Magic=51;                                          // Задаём магик... 5 и 1; 5 = пять минут, 1 = стратегия 1
         New_Comm="Sell_M5_Стратегия_1_Основная позиция";   // Задаём комментарий для позиции
         Lots_New=NormalizeLot(Lots/divider, False, NULL);
         OpenPosition(NULL,OP_SELL,Lots_New,0,pb-tp*po,Magic,New_Comm);

         return;            

I hope it makes sense...

 
Question - is it possible that graphical objects are not simulated in the strategy tester in the non-visual mode? For example, I was testing code that opens trades by breaking the channel OBJ_REGRESSION - it trades in the visual mode, but if I turn it off, there are no trades... How to conduct optimization in this case?
 
ToLik_SRGV:

Boris, small correction in the code, forgot to add a reset of the array position, when returning to the original lot:


THANK YOU VERY MUCH! Everything worked out. Goes well and puts the right lots!!!
 
Please tell me what to do and change or add to the code to set the bar width of the histogram?
 
odiseif:
How can I change or add something to the code to set the bar width in the histogram?

in indicator settings - line type, colour and width/thickness
 
IgorM:

in the indicator settings - line type, colour and thickness/width
SetIndexStyle(0, DRAW_NONE);
SetIndexStyle(1, DRAW_LINE,EMPTY);
SetIndexStyle(2, DRAW_NONE);
SetIndexStyle(3, DRAW_NONE);
SetIndexStyle(4, DRAW_NONE);
it's here ....... but my tool has a line width of 0 and I want to set the width of 2 so I don't have to deal with settings ...... I don't know how to do it .... I'm not a programmer .... help me please ))))
 

I don't know anything about programming at all. I wanted to make CCI Filter (https://www.forex-tsd.com/indicators-metatrader-4/3356-cci-filter.html) the same for WPR, changed CCI to WPR and changed levels in coloring conditions of bars (not -100, 0, 100 like CCI, but -60, -50 and -40, because in MT WPR has range -100 to 0, I think, right?) But for some reason it compiles with an error, and the screen shows a monochrome indicator. What is wrong? Thanks in advance

#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "https://www.forex-tsd.com/"

#property indicator_separate_window
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_buffers 4
#property indicator_color1 MediumBlue
#property indicator_color2 Crimson
#property indicator_color3 LightBlue
#property indicator_color4 Orange



//---- input parameters
extern int PeriodWPR=18;
//---- indicator buffers
double UpBuffer1[];
double DnBuffer1[];
double UpBuffer2[];
double DnBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2);
   
   SetIndexBuffer(0,UpBuffer1);
   SetIndexBuffer(1,DnBuffer1);
   SetIndexBuffer(2,UpBuffer2);
   SetIndexBuffer(3,DnBuffer2);
   
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="WPR Filter("+PeriodWPR+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend");
   SetIndexLabel(1,"DownTrend");
   SetIndexLabel(2,"Mild UpTrend");
   SetIndexLabel(3,"Mild DownTrend");
   
//----
   SetIndexDrawBegin(0,PeriodWPR);
   SetIndexDrawBegin(1,PeriodWPR);
   SetIndexDrawBegin(2,PeriodWPR);
   SetIndexDrawBegin(3,PeriodWPR);  
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| WPRFilter                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int shift,trend;
   double WPR0;

   
   for(shift=Bars-PeriodWPR-1;shift>=0;shift--)
   {    
   WPR0=iWPR(NULL,0,PeriodWPR,PRICE_CLOSE);
        
          if (WPR0>-50 && WPR0<-40)  trend=1;
          if (WPR0>-40)  trend=2;  
          if (WPR0<-50 && WPR0>-60) trend=-1;
          if (WPR0<-60)  trend=-2;
          
          if (trend==1) 
          {
          
          UpBuffer1[shift]=0;
          UpBuffer2[shift]=1;
          DnBuffer1[shift]=0;
          DnBuffer2[shift]=0;
          
          }
          if (trend==2) 
          {
          
          UpBuffer1[shift]=1;
          UpBuffer2[shift]=0;
          DnBuffer1[shift]=0;
          DnBuffer2[shift]=0;
          
          }
          if (trend==-1) 
          {
           
          UpBuffer1[shift]=0;
          UpBuffer2[shift]=0;
          DnBuffer1[shift]=0;
          DnBuffer2[shift]=1;
          }
          
          if (trend==-2) 
          {
          
          UpBuffer1[shift]=0;
          UpBuffer2[shift]=0;
          DnBuffer1[shift]=1;
          DnBuffer2[shift]=0; 
          
          }
        }
        return(0);      
 }
 
Infinity:

Memory is useless).

I want to know what kind of currency, prescribed the variables

string EUR="EURUSD";
string GBP="GBPUSD";

string symbl = "";

I write the following at start :

symbl = symbl(); //receive the value of the symbol

I want to compare the received value of symbl with the values of my variables, and if they match, then make a decision.

switch (symbl) {

case .......... then nothing happens (( break;

case ................ break;

}

Refresh my memory))

I figured out that only a character constant can be used, but how do I do it?


 
Infinity:

Memory is useless).

I want to know what kind of currency, prescribed the variables

string EUR="EURUSD";
string GBP="GBPUSD";

string symbl = "";

I write the following at start :

symbl = symbl(); //receive the value of the symbol

I want to compare the received value of symbl with the values of my variables, and if they match, then make a decision.

switch (symbl) {

case .......... then nothing happens (( break;

case ................ break;

}

Refresh your memory ))


The docks on the switch clearly say that the expression in brackets, i.e. symbl should be of integer type, but you are stringing it up...
Reason: