Download MetaTrader 5

help with the objectset function

To add comments, please log in or register
joe
63
joe 2014.01.06 11:44 

Hello,

I m trying to create an ea that will move an horizontal line on the High/Low of the previous candle according to certain condition. the compilation is OK, but the ea doesn't work.

void TechnicalAnalysissell()
{
      if (Close[current+1] <= Close[current+2]  && Volume[current+1] == Volume[iHighest(NULL,0,MODE_VOLUME,period,current+1)])
    {
    ObjectSet("BUY", OBJPROP_PRICE1,High[current+1]);
    }
}

if you can highlight the mistaken part, it would be great.

thanks

Carl Schreiber
6685
Carl Schreiber 2014.01.06 13:09  

try this:

        if( ObjectFind("BUY") != -1 ) ObjectDelete("BUY");
        ObjectCreate("BUY", OBJ_HLINE, 0, TimeCurrent(), High[current+1]);

Then you can change how your line should look with

ObjectSet(..)

gooly

joe
63
joe 2014.01.06 13:42  
thanks gooly, it seems to work smoothly
whroeder1
14764
whroeder1 2014.01.06 13:47  
jopopo: but the ea doesn't work.
    ObjectSet("BUY", OBJPROP_PRICE1,High[current+1]);
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Check your return codes and find out if it's even being called. What are Function return values ? How do I use them ? - MQL4 forum
  3. You could use Gooly's suggestion (always delete and create,) or ObjectMove (if move fails, create,) or your ObjectSet (if set fails, create.) All do the same.
  4. Current+1 sounds like EA Builder. We hate EA builder
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    • EA builder makes bad code Not adjusting for 4/5 digit brokers
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
To add comments, please log in or register