[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 46

 
bool exit_for=false;
double max_1=0;
double max_2=0;
for(int k=0; k<Bars; k++)
{
	if(	iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k)<iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k+1)
		&& iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k+1)>iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k+2) 	)
	{
		//Если это первый максимум:
		if( max_1==0)
			max_1=iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k+1);//Записываем номер бара экстремума
		else
		//Если первый найден, записываем второй
		{	
                        max_2=iRSI(Symbol(),0, rsi_period,PRICE_CLOSE, k+1);
                        exit_for=true;
                } 
	}
        //Выход из цикла, когда найдены оба максимума
        if( exit_for==true) k=Bars+1;  
}
Good afternoon . Please advise. To my question about comparing the tops with RSI after its value is above 70, I was asked this solution (code above)

It does not work like this. As a result I get that I look for maxima in history (it finds maxima in previous day), but I need it to wait for fulfillment after this function takes action (like value on 1st bar > 70) ... If this condition is fulfilled (not before the bar > 70, but after) the 1st maci is lower than the 2nd one, then the order is closed

Any tips on what to change.

Thank you
 
xruss писал(а) >>

one more question - help us out)

how to determine after an order has been selected from the history its type (was the order closed by Buy or Sell)?

// ищем самый последний закрытый ордер
for( i=OrdersHistoryTotal(); i>=0; i--){
  if(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)){
    if(OrderSymbol()==Symbol()){
      if(OrderMagicNumber()== MagicNumber){
        if(OrderCloseTime()!=0){
          if(OrderCloseTime()> time){
            time  =OrderCloseTime();
            tikcet=OrderTicket();
            profit=OrderProfit();
            type  =OrderType(); <-----
          }
        }
      }
    }
  }
}
 
Roger >> :
You have one variable declared and then try to use another.

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!!!!!!!!!!!!!!!!! Well, you should have said so right away........... otherwise old age is no fun - but youth is nasty.....

>> >>SPASSYBOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

Could you please advise
I need a clear understanding of whether an order closed on stop or profit
I made the variables priceprofitbuy and pricestopbuy
before ordersend I make pricebuy = Ask, then the order is submitted to pricebuy, if successful, then alert and remember priceprofitbuy and pricestopbuy, based on pricebuy
further conditions priceprofitbuy >= Bid= Bid and pricestopbuy <= Bid, I check if the order is closed on profit or stop
; however, sometimes Bid has reached takeprofit level and the order is closed, but while the loop reaches priceprofitbuy >= Bid, Bid has become lower, and the loop does not work correctly

Question - is there any way to clearly detect that the order has closed on profit?
I tried to assign a variable to the ticket number of the order and then check profit in the history, but the order cannot be selected from the ticket - only the profit is shown in the history.

 
gramp >> :

I made the priceprofitbuy and pricestopbuy variables
I place pricebuy = Ask before ordersend, then order-send by pricebuy; if successful, alert and store priceprofitbuy and pricestopbuy based on pricebuy
then using the priceprofitbuy >= Bid and pricestopbuy <= Bid condition, i check if the order is closed on profit or stop
however, it happens that Bid has reached takeprofit level, the order is closed, but while the cycle reached priceprofitbuy >= Bid, Bid has become lower and then the cycle does not work correctly

Question - is there any way to clearly detect that the order has closed on profit?
I tried to set the ticket number to a variable and then check the profit in the history, but the order cannot be selected from the history - only the post is shown in the history.

It is not quite correct:

A position may open at a slippage (usually at a worse price) instead of the exact price.

It would be more correct to determine the open order price using the OrderOpenPrice() function, having previously selected it using OrderSelect(...).

Or, after its closing, calculate the difference between the open and close price. The latter is determined by OrderClosePrice() function.

OrderType() will return your type (buy/sell).

 

To xrust: Thank you very much.


Only it is not clear how to spell in trade conditions that if the type of closed order was OP_BUY,then blah blah(

I have it like this:


int ORDtype;
// ищем самый последний закрытый ордер
for( i=OrdersHistoryTotal(); i>=0; i--){
  if(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)){
    if(OrderSymbol()==Symbol()){
      if(OrderMagicNumber()== MagicNumber){
        if(OrderCloseTime()!=0){
          if(OrderCloseTime()> time){
            time  =OrderCloseTime();
            tikcet=OrderTicket();
            profit=OrderProfit();
            ORDtype  =OrderType(); <-----
          }
        }
      }
    }
  }
}
// торг условия
if(ORDtype=1)&&....

in the condition I correctly wrote that If the order type was OP_BUY then blah blah blah?

 
xruss >> :

if(ORDtype=1)&&....

I wrote correctly in the condition that If the order type was OP_BUY then blablabla?

It should be:

if(ORDtype==1)&&....

 
Everlost >> :

It should be:

if(ORDtype==1)&&....

fa if there is no history - in my case ORDtype ==0?

 
xruss >> :

If there is no history - in my case ORDtype ==0?

It will be equal to the value specified when declaring the variable, i.e. 0 in your case, because no value was explicitly assigned to it. By the way, I hadn't noticed in your previous post that you wanted to select OP_BUY order - this constant is 0, while 1 is OP_SELL. So it's better to declare variable ORDtype with value -1:

int ORDtype=-1;

To avoid confusion what value corresponds to what type of operation, you can also specify it in condition:


if (ORDtype==OP_BUY) ...

 
Everlost >> :

It will be equal to the value specified when the variable was declared, i.e. in your case 0, since there was no explicit assignment of a value to it. By the way, I didn't notice in your previous post that you wanted to select OP_BUY order - this constant is exactly 0, while 1 is OP_SELL. So it's better to declare variable ORDtype with value -1:

int ORDtype=-1;

Also, to avoid confusion, what value corresponds to what type of operation, you can specify so in condition:


if (ORDtype==OP_BUY) ...

and if there was a Sell order in the history and then the Expert Advisor closed it (in the history type it (its closing) is displayed as t/p or s/l - will it not be considered as the last one? could not achieve the desired effect((