Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 509

 
Zolotai:

Folks, suggest a robot. One that uses martin.

For example, I open an order and the robot keeps working...

Code Base
 

Hello. I am trying to figure out how the events work. I have NOT worked the event of deleting an object from the chart(CHARTEVENT_OBJECT_DELETE). Removed both with the mouse and through the Object List. Build 600.

Please tell me what is wrong?

I use code from help

#define KEY_NUMPAD_5 12
#define KEY_LEFT 37
#define KEY_UP 38
#define KEY_RIGHT 39
#define KEY_DOWN 40
#define KEY_NUMLOCK_DOWN 98
#define KEY_NUMLOCK_LEFT 100
#define KEY_NUMLOCK_5 101
#define KEY_NUMLOCK_RIGHT 102
#define KEY_NUMLOCK_UP 104
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Print("Запущен эксперт с именем ",MQLInfoString(MQL_PROGRAM_NAME));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // идентификатор события
const long& lparam, // параметр события типа long
const double& dparam, // параметр события типа double
const string& sparam) // параметр события типа string
{
//--- нажатие левой кнопкой мышки на графике
if(id==CHARTEVENT_CLICK)
{
Print("Координаты щелчка мышки на графике: x = ",lparam," y = ",dparam);
}
//--- нажатие мышкой на графическом объекте
if(id==CHARTEVENT_OBJECT_CLICK)
{
Print("Нажатие кнопки мышки на объекте с именем '"+sparam+"'");
}
//--- нажатие кнопки на клавиатуре
if(id==CHARTEVENT_KEYDOWN)
{
switch(int(lparam))
{
case KEY_NUMLOCK_LEFT: Print("Нажата KEY_NUMLOCK_LEFT"); break;
case KEY_LEFT: Print("Нажата KEY_LEFT"); break;
case KEY_NUMLOCK_UP: Print("Нажата KEY_NUMLOCK_UP"); break;
case KEY_UP: Print("Нажата KEY_UP"); break;
case KEY_NUMLOCK_RIGHT: Print("Нажата KEY_NUMLOCK_RIGHT"); break;
case KEY_RIGHT: Print("Нажата KEY_RIGHT"); break;
case KEY_NUMLOCK_DOWN: Print("Нажата KEY_NUMLOCK_DOWN"); break;
case KEY_DOWN: Print("Нажата KEY_DOWN"); break;
case KEY_NUMPAD_5: Print("Нажата KEY_NUMPAD_5"); break;
case KEY_NUMLOCK_5: Print("Нажата KEY_NUMLOCK_5"); break;
default: Print("Нажата какая-то неперечисленная клавиша");
}
ChartRedraw();
}
//--- удален объект
if(id==CHARTEVENT_OBJECT_DELETE)
{
Print("Удален объект с именем ",sparam);
}
//--- создан объект
if(id==CHARTEVENT_OBJECT_CREATE)
{
Print("Создан объект с именем ",sparam);
}
//--- перемещен объект или изменены координаты точек привязки
if(id==CHARTEVENT_OBJECT_DRAG)
{
Print("Изменение точек привязки объекта с именем ",sparam);
}
//--- изменен текст в поле ввода графического объекта Edit
if(id==CHARTEVENT_OBJECT_ENDEDIT)
{
Print("Изменен текст в объекте Edit ",sparam);
}
}


 

Dear forum members, help me to understand, i is the current candle, why i-2 does not want to draw a line, the tester stops when running.

ObjectCreate("line",OBJ_VLINE,0,Time[i-2],Open[1]);
 
Alexandr24:

Dear forum members, help me to understand, i is the current candle, why i-2 does not want to draw a line, the tester stops when running.


If you are trying to draw a line 2 candles earlier from the i, then you need to add 2, not subtract, because candle numbering goes from right to left, 0-current bar.
If you try to draw lines on a bar that doesn't exist yet (-2), the array index can't be negative. To do this, calculate the time of the needed bar, e.g. Time[0]+2*(Time[0]-Time[1])
 
isn-88:

If you are trying to draw a line 2 candles ahead of the i-th candle, then you need to add 2, not subtract, because candle numbering goes from right to left, 0-current bar.
If you try to draw lines on a bar that doesn't exist yet (-2), the array index can't be negative. To do this, you need to calculate the time of the bar you want, e.g. Time[0]+2*(Time[0]-Time[1])

Thank you very much, the line should have been drawn on a bar that does not exist (-2)
 
Alexandr24:

Thank you very much, the line should have been drawn on a bar that does not exist (-2)

Why else would there be a price. After all, the object is time-based .
 
Alexandr24:

Thank you very much, the line should have been built on a bar (-2) that does not exist

Please
Here is another "beautiful" solution

Time[0]+Period()*60*2 //60 переводим в секунды, 2 кол-во баров

 

Folks, help me get started. Need to open an order.

input int TakeProfit = 30;

input double StartLot = 0.01;

input double summ=false; //true, открываем позиции в обе стороны

input int Slippage = 30; // установим значение проскальзывания



void OnTick()

{

if(summ) { // открываем однупозицию, покупка.

OrderSend(

Symbol(),

OP_BUY,

StartLot,

NormalizeDouble(NormalizeDouble(Ask,_Digits),_Digits),

Slippage,

0,

TakeProfit,

WindowExpertName()+" "+(string)0,

0,

0,

clrBlue

);

}else{

OrderSend(

Symbol(),

OP_BUY,

StartLot,

NormalizeDouble(NormalizeDouble(Ask,_Digits),_Digits),

Slippage,

0,

TakeProfit,

WindowExpertName()+" "+(string)0,

0,

0,

clrBlue

);

OrderSend(

Symbol(),

OP_SELL,

StartLot,

NormalizeDouble(NormalizeDouble(Bid,_Digits),_Digits),

Slippage,

0,

TakeProfit,

WindowExpertName()+" "+(string)0,

0,

0,

clrBlue

);

}

}

It's not working, what's wrong?

Write code that will just open a position. That's all you need...

 
Zolotai:

Folks, help me get started. Need to open an order.

It's not working, what's wrong?

Write code that will just open a position. This is all you need...


TakeProfit is not specified correctly in the order submission. You need to specify the price, not the number of nano-pips of profit. Correct to Ask+TakeProfit*Point()
Ask, Bid need not be normalised....

OrderSend(

Symbol(),

OP_BUY,

StartLot,

Ask,

Slippage,

0,

Ask+TakeProfit*Point(),

WindowExpertName()+" "+(string)0,

0,

0,

clrBlue

);

 
r772ra:

Why else would there be a price. After all, the project is being built in time.
And once again, yes, many, many times to read the reference book...
This website uses cookies. Learn more about our Cookies Policy.