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;
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?
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
static int time = Time[0];
if (time < Time[0]){
// old candle
} else {
// new candle
time = Time[0];
}
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:
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...
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!!!
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
in the indicator settings - line type, colour and thickness/width
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
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?
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 ))