EA does not open a position

 
  for(int i = 0; i < ObjectsTotal(0, 0, -1) ; i++){
    string ObjectNameTemp = ObjectName(0, i, -1, -1);
    
    if (ObjectGetInteger(ChartID(), ObjectNameTemp, OBJPROP_TYPE) == OBJ_HLINE && ObjectGetInteger(ChartID(), ObjectNameTemp, OBJPROP_COLOR) == clrBrown){
    TempValue  = ObjectGetDouble(0, ObjectNameTemp, OBJPROP_PRICE);
    Print("SELL AT: ",TempValue);
    if(bid > TempValue)SELL(price_temp_red_zone);
   
  }
}


Hello, I have a simple code here.. it usually opens positions. but sometimes he doesn't and i don't know why. as soon as the bid is above the line, he should actually always trade.. please help.

the variable passed to the SELL function is the stoploss. the price and stoploss are always displayed correctly, i can see them on the chart (on the lines)

 
Hmm, strange .... Auto-update works?
 
bikoza #:
Hmm, strange .... Auto-update works?

Yes, I just installed it yesterday. I really can't figure it out either... the error must be hidden. I've had this problem for 2 weeks now and I just can't find the solution
 
  1. How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    No idea what datatype your TempValue or bid is.

    No idea what value your bid is, or when you update it.

  2.   for(int i = 0; i < ObjectsTotal(0, 0, -1) ; i++){
        string ObjectNameTemp = ObjectName(0, i, -1, -1);

    You are getting the object count for the current chart, main window, but selecting object i on the current chart, including all sub-windows. Code fails if there are sub-windows with any objects.

  3. There is no need to supply default parameters. Write self-documenting code. Simplify your code:

    #define WINDOW_MAIN 0
     for(int i = 0; i < ObjectsTotal(0, WINDOW_MAIN) ; i++){
        string ObjectNameTemp = ObjectName(0, i, WINDOW_MAIN);

 

thanks for the tip, william roeder! the variable is a double type, thought that was clear, sorry. you're right about the main window, i was able to refine my code with it, so that's good to know. but the problem seemed to be something else: my program is very large in terms of the number of lines and there is a lot in the onTick() function. I've moved the loop higher up now, at the beginning of onTick(). Now he calls it constantly and the code ALWAYS works..

 

I will ask my questions more precisely next time and give more information.

Reason: