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

 
isn-88:

Close buy order at Bid price, sell at Ask price.
thanks
 
AlexeyVik:
Simple condition in init function
Metals, stocks and raw materials don't count.

Thanks. Can you tell me the easiest way. Need to understand if there are open positions on this pair or not. Whether there are sell orders and whether there are buy orders. It means that we need to get

0 - if there are no open orders

1-I have sell orders but no buy orders.

2-there are buy orders but no sell orders

3-there are both...

 
woin2110:

https://docs.mql4.com/ru/series

if(DayOfWeek()==1,2..... && Hour()==1,2....)
{
double hi=iHigh(NULL,0,iBarShift(NULL,0,iTime(NULL,PERIOD_D1,0));//define high
double low=iLow(NULL,0,iBarShift(NULL,0,iTime(NULL,PERIOD_D1,0));//define low.

/////////////////////////////////////////////////////////////////////////////////////////////////

double op=iOpen(NULL,0,iBarShift(NULL,0,iTime(NULL,PERIOD_D1,0));//define opening.


Thank you!
 
Zolotai:

Thanks. Can you tell me the easiest way. Need to understand if there are open positions on this pair or not. Whether there are sell orders and whether there are buy orders. It means that we need to get

0 - if there are no open orders

1-I have sell orders but no buy orders.

2-there are buy orders but no sell orders

3-there are both.

For example like this:

int i_buy=0;

int i_sell=0;

//--- получим количество открытых и отложенных ордеров

int total=OrdersTotal();

for(int i=0;i<total;i++)

{

//--- выберем i-й ордер из списка торговли

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

{

//--- если ордер открыт по текущему финансовому инструменту

if(OrderSymbol()==Symbol())

{

switch(OrderType())

{

//--- Бай ордер

case OP_BUY:

i_buy++;

break;

//--- Селл ордер

case OP_SELL:

i_sell++;

break;

case OP_BUYSTOP:

case OP_BUYLIMIT:

case OP_SELLSTOP:

case OP_SELLLIMIT:

//--- пробойники, лимитники

break;

}

}

}

}


if(i_buy==0 && i_sell==0)

{

//--- нет открытых ордеров

}

if(i_buy>0 && i_sell==0)

{

//--- открыты баи

}

if(i_buy==0 && i_sell>0)

{

//--- открыты селы

}

if(i_buy>0 && i_sell>0)

{

//--- открыты и баи и селы

}

 
isn-88:

For example, like this:



Thank you very much. My understanding is that asc is the current price. I open an order when there are no open orders. The loop goes from the first to the last open order? How can I transmit into a variable the lot of the last open order and its price?
 
Zolotai:

Thank you very much. My understanding is that asc is the current price. I open an order when there are no open orders. The loop goes from the first to the last open order? How can I set the lot of the last open order and its price into a variable?

https://docs.mql4.com/ru/trading/orderselecthttps://docs.mql4.com/ru/trading/orderopenprice https://docs.mql4.com/ru/trading/orderlots

double z; //declare a variable "z".
double y; //declare the "y" variable


if(OrderSelect(10,SELECT_BY_POS)==true) //if the order (by ticket) is already selected

{

OrderLots()=z //assign the lot for this order to the "z" variable

OrderOpenPrice()=y //assign the open price to the "y" variable

}

try this

 
woin2110:

https://docs.mql4.com/ru/trading/orderselecthttps://docs.mql4.com/ru/trading/orderopenprice https://docs.mql4.com/ru/trading/orderlots

double z; //declare the "z" variable
double y; //declare the "y" variable


if(OrderSelect(10,SELECT_BY_POS)==true) //if the order (by ticket) is already selected

{

OrderLots()=z //assign the lot for this order to the "z" variable

OrderOpenPrice()=y //assign the open price to the "y" variable

}

try this

y = OrderOpenPrice();


Oops, got it, just don't understand. if((i_buy==0 && i_sell==0) || y > Step). Should open another order if distance from last open order is more than 5 pips. But it doesn't work, question.

for(int i=0;i<total;i++) It goes from the first order opened to the last? That is, I should eventually get the price of the last order opened.

 
Zolotai:

y = OrderOpenPrice();


I don't understand if((i_buy==0 && i_sell==0) || y > Step). Should open another order if distance from last open order is more than 5 pips. But it doesn't work, question.

for(int i=0;i<total;i++) It goes from the first order opened to the last? In otherwords, i should get the price of the last order opened.


I don't know, I haven't come across it.
 

Hello. I saw a post on https://forum.mql4.com/ru/51490/page2 where there is a script that opens the EA settings window:

This one brings up the EA settings window:

//+------------------------------------------------------------------+
//|                                                      EaSetup.mq4 |
//+------------------------------------------------------------------+
//|                                                      EaStart.mq4 |
//|                                 Copyright © 2010, XrustSolution. |
//|                                           mail: xrustx@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, XrustSolution."
#property link      "mail: xrustx@gmail.com"
#import "user32.dll"
   int   RegisterWindowMessageA(string lpstring);
   int   PostMessageA(int  hWnd,int  Msg,int  wParam,string lParam);
#import
#define WM_COMMAND      0x0111
//+------------------------------------------------------------------+
void start(){Sleep(200);PostMessageA(WindowHandle(Symbol(),Period()), WM_COMMAND, 33048, 0);return;}
//+------------------------------------------------------------------+ 

Is it possible to make the script open the EA settings window at 1 second intervals and immediately confirm it (press ok button) and so on?

 

Am I doing it right.

y = OrderOpenPrice()-Ask;

I subtract the current price from the price of the last open order?

int i_buy=0; int i_sell=0;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol()){

switch(OrderType()){// Есть ли открыте ордера

case OP_BUY:

i_buy++;

break;

case OP_SELL:

i_sell++;

break;

}

y = OrderOpenPrice()-Ask;

}

}


if((i_buy==0 && i_sell==0) || y > Step) //--- нет открытых ордеров, открываем или расстояние от последнего ордера до текущей цены. Больше step

OrderSend(Symbol(), OP_BUY,StartLot,Ask,Slippage,0,Ask+TakeProfit*Point(),WindowExpertName()+" "+(string)0,0,0,clrBlue);