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

 
artmedia70:
Is this from an indicator or from an EA? There is a difference. In general, to avoid drawing the arrow, you need to check the previous adjacent bar in the indicator and if it has a non-zero or non-empty value, it means that the arrow on the adjacent bar already exists and there is no need to enter the value into the current bar buffer. For an EA, if the previous adjacent bar already contains a crossing fact in the same direction as the current one and the arrow already marks this fact, the crossing fact on the current bar can be not registered (if it exists) and the arrow need not be displayed either.
I cannot tell you anything else about your code. If there are telepaths around, they will probably be able to understand your code to a greater extent ;)

This is from the indicator. Intersection of 2 slips, gives direction. I do not quite understand, the direction is given only when crossing not on every bar. From here, judging by the previous bar is impossible.... Tell me, we are building an array, aren't we? How to check the previous cell? Two buffers one CrossUp[i]=Low[i] - Range*0.75;, another one say Cr[i]=Low[i] + Range*0.75;(just don't want to get into folders and code again)
 
zaqwsx123:

If one of the pending orders triggers, then I place another pending order in the opposite direction and double the volume, for example, if I place buy, then I place sellstop 25 pips lower than buy, and if I place sell, then I place buystop 25 pips higher. If one of the pending orders triggers, we place one more pending order in the opposite direction from the triggered order, at the price of the first open order, and if it triggers too, we again place a pending order in the opposite direction from the triggered one within 25 points, etc. Thus, all buy orders should be at one price, and all sell orders should also be at one price. If anybody understand what I've written here, please help me with the code))

You've written a lot of nonsense... At least this:

OrderSelect(1,SELECT_BY_TICKET,MODE_TRADES);            //цена открытия первого ордера

are you sure the order is chosen? Are you sure this is the price? Are you sure the order has a ticket == 1 ? When selecting by ticket, pool is irrelevant, so MODE_TRADES is superfluous there. After successful selection by ticket, we should also check the close time of the selected order. If it == 0, the order is in the market and has been selected from the list of market orders. If the close time > 0, the order has either been closed or is a deleted pending order and has been selected from the list of closed orders.

I don't want to look further into the code. Perhaps, you should get acquainted with the basics first. Read the tutorial and documentation - they are in a prominent place here.

 
artmedia70:


I don't want to look further into the code...


that caught my eye)) Why 4 identical chicks? and the sample is not what is in the comment

if (OrderType() == OP_BUY) buystops++   //количество ордеров buystop

The same goes for selstop. you need OP_BUYSTOP and OP_SELLSTOP

 
ALXIMIKS:


that caught my eye)) Why 4 identical chicks? and the sample is not what is in the comment

similar with selestop. you need OP_BUYSTOP and OP_SELLSTOP

I didn't get to that point. When you look at the code and see that you don't have to explain mistakes, but just start teaching a person from the basics, which he could read himself, then ... ... I don't want to. You may teach on a paid basis, but not where you just help to find errors in the code and not code among errors.
 
Zolotai:

This is from the indicator. Intersection of 2 slides, gives direction. I don't quite get it, it only gives direction when crossing not on every bar. From here, it is impossible to judge from the previous bar.... Tell me, we are building an array, aren't we? How to check the previous cell? There are two buffers: one CrossUp[i]=Low[i] - Range*0.75; and another one, say, Cr[i]=Low[i] + Range*0.75;(I just don't want to search through folders and code again).
There is no source data. Try searching here.
 
There is a BUY_STOP order which has been deleted before execution:




Check code:
            for(int cnt_1=OrdersHistoryTotal()-1; cnt_1>=0; cnt_1--) {
               if(OrderSelect(cnt_1, SELECT_BY_POS, MODE_HISTORY)==true ) {
                  if(OrderSymbol()==Symbol()   &&   OrderCloseTime()!=0   &&   OrderMagicNumber()==My_Magic_Number ) {
                     Print("OrderProfit()=",OrderProfit(), "   OrderCloseTime()=",TimeToStr(OrderCloseTime(),TIME_DATE|TIME_SECONDS), "   OrderType()=",OrderType(), "   OrderTicket()=",OrderTicket(), "   OrderClosePrice()=",OrderClosePrice(), "   OrderOpenPrice()=",OrderOpenPrice() );
                  } // if(OrderSymbol()==Symbol()   &&   OrderCloseTime()!=0   &&   OrderMagicNumber()==My_Magic_Number ) {
               }
            } // for(int cnt_1=0; cnt_1<OrdersHistoryTotal(); cnt_1++) {

String with result:
OrderProfit()=0   OrderCloseTime()=2001.01.26 06:15:00   OrderType()=4   OrderTicket()=24   OrderClosePrice()=0.9237   OrderOpenPrice()=0.9419

1, OrderType=4 - "4" is OP_SELLLIMIT, right?
2. OrderClosePrice()=0.9237 OrderOpenPrice()=0.9419 - Where did the OrderClosePrice() value not equal to OrderOpenPrice() come from?

 
chief2000:

There is a BUY_STOP order which has been deleted before execution:




Check code:

String with result:

1, OrderType=4 - "4" is OP_SELLLIMIT, right?
2. OrderClosePrice()=0.9237 OrderOpenPrice()=0.9419 - where did the OrderClosePrice() value not equal to OrderOpenPrice() come from?

and in the visualization mode of the tester, over all ticks, in step-by-step mode (F12 on pause) find the moment of its removal and look at the current price, maybe there the dog is hidden there?
 
artmedia70:
and you in the tester in visualisation mode, yes on all ticks, in step mode (F12 on pause) find the moment of its removal and see the current price, maybe that's where the dog is buried?


BINGO! Didn't know, but all as you wrote, i.e. the closing price in this case is the value of the price at the time the order was deleted. Thank you!
 

Often I would declare a variable like this inside functions:

int err = GetLastError();

Further inside, at some condition I already call it to see if there is an error. Well, it's not only me but many other places in the code I've encountered. So to say, it's a typical situation. I thought today that it's not logical to declare the same variable each time in each function where you want to control errors. I thought it over and came to the conclusion that it would be easier to declare globally once and initialize it in the init. It goes like this:

// Объявили на глобальном уровне
int err;

// Инициируем данную переменную:
int init()
{
    err = GetLastError();
}

And further, when you need to call the err variable in user functions, knowing that it already has a value. As a matter of fact, GetLastError() outputs the code of the last error, so if this variable err is called in each function at the end of all calculations, which is responsible for outputting the error code, and calls GetLastError(), then everything will be correct, right?

But if you don't call this variable at the end of some function (following the chain of code execution), it won't reset, and it will cause wrong execution in case there was an error in previous execution, but not in current one, but error code is returned last... And to reset it, you need to call this function GetLastError(). I.e. here everything depends on whether it was called or not. If you're not sure that it will be everywhere, it's easier to re-insure and reset it every time, right?

 

1) why not initialize immediately when declaring int err=0 ?

2) didn't check, but according to documentation err is stored in some variable, which is auto-zeroed when using GetLastError() function,

and also always changes when using some functions (mostly terminal ones)

3) This is why GetLastError() gave a value of 0 after referring to a non-existent ticket number in OrderSelect:

" The other functions do not change the value of the last_error variable under any conditions. ................., OrderSelect, ...................."