expert advisor - miscellaneous questions - page 23

 

I recommend it.

By the time you solved all those problems you can consider yourself among the pro's.

Make things as hard as possible then you will learn the most.

Otherwise you keep struggling with the simple things all the time.

 

First of all really thanks for your comments.

After your comments, I decided I should once again create Order Modification code blocks for sure and for test.

 

Mr. @Marco vd Heijden

After your greatest comments / examples - I already write a code for drags for Take Profit Prices.
But actually I am against continuously updates. Why? Since I write code blocks for Take Profit drags I see my chart gets slowly. Maybe I made mistakes in that part of code. I will check it after I solve this issue.

( while I was trying to solve my issue by myself, after I tried several times then I just thought there is a no chance to stop calculation if I use " for " loop operator ) 

       I would like to mention I already have calculation for Take Profit and Stop Loss sizes that cause I removed " Switch " operator from below code.
       I am just trying when Take Profit price will be equal to " Line " Price - then stop calculates / updates till next time Take Profit price " != " Line price.
Q:  
I am struggle to correct below code for my concern. So what can I do for it, please?
Q:   Am I doing wrong I am not using " Switch " operator for my this issue?

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   for(int order=OrdersTotal(); order>=0; order--)
     {
      bool selected=OrderSelect(order,SELECT_BY_POS);
        {
         if(selected==1)
           {
            if(Symbol()==OrderSymbol()) // only for current chart symbol
              {
               /* I just try for - if price not equal != "Line OBJPROP_PRICE "
                  stop updates */


               // if objects not found - create them
               // ...
               // if objects exist
               // ...
               while(price!=ObjectGetDouble(0,"line",OBJPROP_PRICE,0))
                 {
                  PlaySound("ok.wav");
                  price=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);
                  Comment(price);
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

While I read documentation and book for OrderModify() with example I did not see example exactly for my concern.

All the best to you! 

 

I haven't been keeping up to date with the thread, so I may have missed what you are doing. 

First of all, simplify:

for(int order=OrdersTotal(); order>=0; order--)
     {
      bool selected=OrderSelect(order,SELECT_BY_POS);
        {
         if(selected==1)
Should become:
for(int order=OrdersTotal()-1; order>=0; order--)
     {
      if(OrderSelect(order,SELECT_BY_POS)

Also, think about how often you move the line. Is it once a second? Probably not.

Put your code in OnChartEvent():

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line

You are calling the same function multiple times on every open order you have:

while(price!=ObjectGetDouble(0,"line",OBJPROP_PRICE,0))
  {
   PlaySound("ok.wav");
   price=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);
   Comment(price);
  }

Call it once before you enter the order loop:

double lineprice=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);
for(int order=OrdersTotal()-1; order>=0; order--)
  {  
 

Make sure you understand the principle of while loops.

It's dangerous because if for whatever reason one other EA tries to modify the line price value then as a result this piece of code will be stuck in an endless loop and your terminal will most likely freeze.

This usually ends in Abnormal termination.

Since you are using object "line" the danger however is not so great as when you talk about tp and sl levels that are sent to the server by OrderModify() so unless you are planning to write another EA that interferes with "line" it should not be a problem.

 
honest_knave:

I haven't been keeping up to date with the thread, so I may have missed what you are doing. 


Call it once before you enter the order loop:

double lineprice=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);
for(int order=OrdersTotal(); order>=0; order--)
  {  

Please understand what he is trying to do.

He must call two times and compare values in order to see if the line has been moved.

That is impossible to do without reading the value twice.

while(price!=ObjectGetDouble(0,"line",OBJPROP_PRICE,0))// if price differs from "line" value do:
  {
   PlaySound("ok.wav");
   price=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);// now overwrite old line value with new line value.
   Comment(price);
  }
 
Marco vd Heijden:

Please understand what he is trying to do.

He must call two times and compare values in order to see if the line has been moved.

That is impossible to do without reading the value twice.

 

You'll need to explain that to me again.

If you have a CHARTEVENT_OBJECT_DRAG and the sparam is "line" then the line has moved.

For the rare occasions it moves timewise along the same price, the penalty is not much. 

 

There are many ways to do the same thing.

If you decide to use the CHARTEVENT remember that it does not work in the tester.

 
OK, I'll leave it to you guys. Good luck.
 

I already read your beneficial comments, Mr. Marco, Mr. Knave, Mr. William, thanks so much all of that comments!

Now I already checked few things and also I decided I could write ( / and check) OrderModify() step by step. Because this OrderModify() is really really dangerous for me.
Several times I already faced wrong modifications. But when I try to faced same problems / issues, that I know for sure where that problems comes from, even I try same things in the chart that problems / issues was not happened again. After few hours I faced same problem again.
I am still not know exactly what caused for that problems. What is problem that I mean. I already shared one of them with you in my previous comments. Also I open one position by the my Trade Panel EA, that is OK! then I try to open Sell Limit by the manual trade method. ( which is my Trade Panel have not that Sell Limit or Sell Stop Pending orders yet )

So, I think I should share that codes of block with you, but I can't share it for now because I am still working on it. I want to move that codes of block to OnChartEvent() - because also I will add some buttons into it.

Issue:       I can't write a code if Order closed then remove it's objects, like this, Stop Loss, Take Profit, Open, Close arrows something like this, please help me.
Question: Also Stop Loss, Take Profit Lines front of Trade Panel Objects. I know that caused from last time creates object. But if you understand me, please let me know how can I do Trade Panel object should be front all of other objects without " Stop Loss and Take Profit " Lines.

Thanks in advance.