Please help me to deal with my first EA

 

Hi,

I'm coding an "EA" (not full automatic), the idea is that i create 1 support and 1 resistance (both are angled, not horizon). Both lines is created in init() area and by extern input (time and price). If price touch line EA will place an order with setting stoploss and target profit.

However, when i run EA, it can create support and resistance lines, 2 horizontal-ask-lines cross the support and resistance at time of the last candle. The problem is that when the next candle comes, 2 horizontal-ask-lines don't move along with the current bar (bar 0). I guess i need some kind of refresh or loop or something else.

I'm a newbie, my "EA" is funny thing, i guess. Anyway I really do hope someone could give me some valuable advice. Thank you very much


my set up in start() are as follows:

_________________________________________________-

int start()
  {
   double
   M_E,
   LongPrice,
   ShortPrice;
   string
   Symb,
   Long,
   Short;
   Symb=Symbol();
   int Orders=OrdersTotal();
   if (Orders==0)
      Comment("No orders");
   else
      Comment("Available ",Orders," orders." );
   if (Orders>MaxOrder)
      {
      Alert("ordering>",Orders,"orders.");
      return;
      } 
      M_E=AccountMargin()/AccountEquity();
   if (M_E>=MaxMarginEquity)
      {
      Alert("Margin/Equity is more than setting");
      return;
      }
      RefreshRates();
      LongPrice=NormalizeDouble(ObjectGetValueByShift("S",0),Digits);         // "S" is support line, Longprice is price at which "S" line get the time of bar 0
      ObjectCreate("Long",1,0,NULL,LongPrice);   
      ObjectSet("Long",6,Gold);
      ObjectSet("Long",7,STYLE_DOT);
      ShortPrice=NormalizeDouble(ObjectGetValueByShift("R",0),Digits);        //"R" is resistance line Short price is price at which "R" line get the time of bar 0
      ObjectCreate("Short",1,0,NULL,ShortPrice);    
      ObjectSet("Short",6,Gold);
      ObjectSet("Short",7,STYLE_DOT);    
      if(Ask==LongPrice)
         {
         OrderSend(Symb,0,Lot,Ask,1,Bid-StopLoss*Point,Ask+TakeProfit*Point); //Long order
         ObjectDelete("Long");
         return;
         }
      if(Ask==ShortPrice)
         {
         OrderSend(Symb,1,Lot,Bid,1,Ask+StopLoss*Point,Bid-TakeProfit*Point); //Short order
         ObjectDelete("Short");
         return;
         }
   return(0);
   }
  

________________________________________________------

 

u trying to move the s & r lines or move the order ?

for moving the s & r lines

ObjectSet("object name", OBJPROP_PRICE1, the new price value);

for moving the order if its a pending order u need to delelte it & send a new one,

if the order is already executed u need to close it first, and then send the new one

 
zxcvbm:

Hi,

I'm coding an "EA" (not full automatic), the idea is that i create 1 support and 1 resistance (both are angled, not horizon). Both lines is created in init() area and by extern input (time and price). If price touch line EA will place an order with setting stoploss and target profit. 

Read this:  https://www.mql5.com/en/forum/144875

You can't create an Object that already exists . . . move it using ObjectMove or ObjectSet() 

 

@Raptor

Thank you for the link

 
qjol:

u trying to move the s & r lines or move the order ?

for moving the s & r lines

for moving the order if its a pending order u need to delelte it & send a new one,

if the order is already executed u need to close it first, and then send the new one


moving pending order is better than moving prices, tks you for the advice
Reason: