[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 336

 

And barma, make sure

//--------------------------------------------------------------- 5 --
// торговые критерии
if(vverh>0)
  {
   Opn_B=true;
   Cls_S=true;
   Opn_S=false;
   Cls_B=false;
  }
if(vverh>0)
  {
   Opn_S=true;
   Cls_B=true;
   Opn_B=false;
   Cls_S=false;
  }
  
//--------------------------------------------------------------- 6 --
if you have spelled out the conditions correctly
 

Gentlemen! Good evening (at night, in the morning, in the afternoon)!

Could you please give me an answer to a simple question?

What function returns the opening price of an order, which:

- closed last

- closed on a Stop Loss.

Thank you for your help.

 
solnce600:

Gentlemen! Good evening (at night, in the morning, in the afternoon)!

Please tell me the answer to a simple question.

What function returns the opening price of the order, which:

- closed last

- Closed on a Stop Loss.

Thank you for your help.



there is no such function - there is a little code to be written
 
artmedia70:

Variables can only be used when testing the strategy in the tester.

For the real world, every value needed to execute the logic must be calculated at the right time, because the values of these variables are very easy to lose, for example during a restart.



Artem, and it is possible to give an example? After all it is possible even to replace a variable by function. And you can't replace a function with a variable :)

 

solnce600:


Gentlemen! Good evening (night, morning, and afternoon) to all!

Please tell me the answer to a simple question for you.

What function returns the open price of the order, which :

- closed last

- Closed on a Stop Loss.

Thank you for your help.



There's a branch like that there's a lot of stuff there, interesting stuff.

This function returns the flag to close the last position on the stop

 
r772ra:


There issuch a branch, there is a lot of interesting stuff there.

This function returns a flag to close the last position on the stop

Thank you very much for the tip.

This is exactly the function I am using.

After a stop order has been closed, I need to code the opening of market orders at the price of

of the last order closed at stop.

I tried to memorize the opening price of the last order closed at stop in the variable
if (isCloseLastPosByStop()==True)                                            //если посл.орд.SELL  закрылся по стопу(стоп данного ордера SELL = 295 п.)

double PrStop = (Bid - 0.0295);                                              // от цены срабатывания СТОП-ЛОССА вычитаем 295 п. 
                                                                             // и запоминаем это значение,(т.е. цену открытия ордера)в переменной  PrStop         
if (Bid == PrStop )                                                          //если цена Bid будет равна значению PrStop
OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-2950*Point,Bid+150*Point,"jfh",123 );//открыть ордер.

But when the price is equal to the value of PrStop, the order is not placed.

I also tried to place an order when the price is lower than the value of PrStop.

But it didn't set an order again.

if (Bid < PrStop ) 

I think the reason may be that until the next order closes NOT ON STOP LOSS.

isCloseLastPosByStop () will return True at every tick and the PrStop variable will get

ON EACH TICK A NEW VALUE.

I have attentively examined all of Kim's functions, but their names seem to be unsuitable for solving my problem.

I would be very grateful to those who guide me in the right direction.

 

Please give me a hint! I'm just starting to take my first steps in programming.

How would a function work faster? (The function is called 2 times)

- if it is called from the library

- if it is described outside the function start() directly in the EA.

- if it is in the start() function itself

 

solnce600, Andrei, you have the last position closed on SL in your hands! And who prevents you from finding out everything you want about it, by tweaking the function a bit:

double GetOOPCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {
  datetime t; 
  double   ocp, osl, OOP;
  double p = 0;
  int    i, j=-1, k=OrdersHistoryTotal();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
        if (op<0 || OrderType()==op) {
          if (t<OrderCloseTime()) {
            t=OrderCloseTime();
            j=i;
//            p = OrderProfit()+OrderCommission()+OrderSwap();
            OOP = OrderOpenPrice();
  } } } } }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    ocp=NormalizeDouble(OrderClosePrice(), 5);
    osl=NormalizeDouble(OrderStopLoss(), 5);
//    if (ocp==osl) return(p);
    if (ocp==osl) return(OOP);
  }
  return(0);
}
I've commented out the two lines that give me the closing profit, and added two lines to get the opening price of that closed position. I haven't tested it, but it should work as it all works when I substitute what I need! Check it out!
 
borilunad:

solnce600, Andrei, you have the last position closed on SL in your hands! And who's stopping you from finding out all you want about it by tweaking the function a bit:

I commented out the two lines which give me the closing profit and added two lines to get the opening price of that closed position. I haven't tested it, but it should work as everything works when I put in what I need! Check it out!

Thank you very much for your prompt help.

I would also be very grateful if you could give me an idea about.....

My strategy is very simple.

If price moves upwards (300 pips) faster from the open (iOpen (Symbol (),0,0) than a smaller distance (10 pips) in the opposite direction

-After the price reverses and goes in the opposite direction, open market orders at the opening price of each candle ( iOpen (Symbol (),0,0) .

To implement this idea the first thing that comes to mind is

1.At the open price of each candle, place a market order with a large stop and a small profit.

If the order closed faster on the stop than on the profit, set a market order at the opening price of the order which closed on the stop.

This method allows you to detect candlesticks at their opening prices which later should be set as market orders.....But to do this I have to place market

orders with large stops and small profits ON THE OPENING OF EVERY CURRENT.

And I don't need to place orders at the opening of each candle in real trading.

The first thing that comes to mind is

- We should open an order at the opening of each candlestick on a demo account which will have one EA attached to its chart.

- And I should open orders only by the conditions described above on a real account with another EA attached to the chart.

But it seems to me that trading on two accounts and two EAs is not the most convenient and optimal variant either. I would like to trade on one account and one EA.

QUESTION: How else can I find the conditions for position opening described above without opening market orders at the opening of each candle?

Thank you.

 
solnce600:

Thank you very much for your prompt help.

I would also be very grateful if you could give me an idea about.....

My strategy is very simple

If price from the beginning of a candle (iOpen (Symbol (),0,0) went up(down) more distance(300 pips) faster than a lesser distance(10 pips) in the opposite direction

-then after the price turns around and goes in the opposite direction, open market orders at the price of the candle ( iOpen (Symbol (),0,0) at the opening of each candle.

To implement this idea, the first thing that comes to mind is

1. at the open price of each candle, place a market order with a large stop and a small profit.

2. If the order is closed faster at stop than at profit, set a market order at the opening price of the order which closed at stop.

This method allows you to identify candlesticks at their opening prices which later should be set as market orders.....But to do this I have to place market

orders with large stops and small profits ON THE OPENING OF EVERY CURRENT.

And I don't need to place orders at the opening of each candle in real trading.

The first thing that comes to mind is

- We should open an order at the opening of each candlestick on a demo account which will have one EA attached to its chart.

- And I should open orders only by the conditions described above on a real account with another EA attached to the chart.

But it seems to me that trading on two accounts and two EAs is not the most convenient and optimal variant either. I would like to trade on one account and one EA.

Q: How else can I detect the conditions for the position opening without opening the market order at the opening of each candle?

Thank you.

Well, of course, you've made such a big deal out of it as if you've seen it for real, which I doubt! I don't understand your idea thoroughly, but I suggest you try, by tracing the candlesticks in the conditions and, if these conditions coincide with yours, to set the pending orders at the desired distances from the opening zero candlestick, while setting stops and profits, modifying them immediately after setting them by applying the same way another Kim's function to determine the last placed order's data! Examine your logic carefully, experiment and go ahead! Good luck!
Reason: