I need some help in moving my buy/sell price in direction of market price - page 2

 
ernest02:

The problem with the if statement is that when the program cycles through that code the market price have not yet moved far enough for that condition to be true and so nothing happens. I got to find a way to keep on checking the market price movements until it move far enough to make that condition true. It should abandon the task if the market price goes below/above the PendingOrderOpen Price.

That is why I thought I needed a loop (while statement) to achieve that.

It is meant to go in start() so it is checked every tick . . .
 
The problem is that if the "if" statement is not true it goes to the next statement which is the OrderSend operation and the pending order is placed. Will I have to add a check for certain conditions and use a Return(0) statement to make sure it goes back to Start() before doing the OrderSend? Or would it be better to loop through until one or other condition is true, rather than send it back to Start() every time?
 

Well, I give up! I have tried everything and nothing wants to work. I cannot move the pending order as WHRoeder suggests because it gets activated about immediately since I place it with a 1/2 pip margin (I am with an ECN broker where this is possible) so that I can have an immediate Stop Loss and Profit Take and not to have to modify the order later.

Now thinking of sending an Alert() and Comment() and place the order manually, but this negates the automatic trading of my EA.

 
ernest02:

Well, I give up! I have tried everything and nothing wants to work. I cannot move the pending order as WHRoeder suggests because it gets activated about immediately since I place it with a 1/2 pip margin (I am with an ECN broker where this is possible) so that I can have an immediate Stop Loss and Profit Take and not to have to modify the order later.

Now thinking of sending an Alert() and Comment() and place the order manually, but this negates the automatic trading of my EA.

Ofcours it can work I have made myself an EA that can move a pending trade with price working on ECN

So there is still something you can do....

only if you are registered at DonnaForex you can check it http://www.donnaforex.com/forum/index.php?topic=4487.0

 
ernest02:
The problem is that if the "if" statement is not true it goes to the next statement which is the OrderSend operation and the pending order is placed. Will I have to add a check for certain conditions and use a Return(0) statement to make sure it goes back to Start() before doing the OrderSend? Or would it be better to loop through until one or other condition is true, rather than send it back to Start() every time?

if the if is false, you don't do anything.
if(condition){
   newprice= ..
   if (!OrderModify(..))
      alert(..);
}
 

Guys, here is something strange! I discovered that my PriceTS external variable always had the same value of 100 - no matter what I set it as an external variable. When I set it in the code it stayed correct. So eventually I changed the name from PriceTS to just PTS and there it works! (I mean reading the correct value from the external variable) Could the word 'Price" in the variable be responsible? Maybe a reserved word/variable - even when used as PriceTS? Or how does one understand this?

Now I am going to try the code again and see if this makes a change.

 
ernest02:

Maybe a reserved word/variable - even when used as PriceTS?

Not as far as I know . . . reserved words
 
deVries:

Ofcours it can work I have made myself an EA that can move a pending trade with price working on ECN

So there is still something you can do....

only if you are registered at DonnaForex you can check it http://www.donnaforex.com/forum/index.php?topic=4487.0


I went and registered at the Forum you indicated and found your thread about the trailing stop on the pending order. I also saw that one of the posts had an attachment which I think must be the EA you wrote, but I could not find a way to access and download it.

Is it at all possible that you can post it on this Forum? I am sure there will be many that can use your EA.

 

WHRoeder,

I added some code in the line that you have recommended, but now the EA does not want to run. I obviously made a mistake somewhere.

It is so frustrating! Here is the code. See if you can find the error.

        for (Count = OrdersTotal()-1; Count >= 0; Count--)
                    if (OrderSelect(Count, SELECT_BY_POS)
                    && OrderType() == OP_SELLSTOP
                    && OrderMagicNumber() == MagicNumber
                    && OrderSymbol() == Symbol())
                    
                    if (Bid > dSellPrice + (PTS * 2))
                    {
                    dSellPrice = dSellPrice + PTS;
                    bool Modified = OrderModify(OrderTicket(),dSellPrice,OrderStopLoss(),OrderTakeProfit(),0,Red);
                    {                       
               // Error handling
                  if(Modified == false)
                     {
                        ErrorCode = GetLastError();
                        ErrDesc = ErrorDescription(ErrorCode);

                        ErrAlert = StringConcatenate("Modify Pending Order - Error ",ErrorCode,": ",ErrDesc, " Bid is ", Bid);
                        Alert(ErrAlert);

                        ErrLog = StringConcatenate("OrderTicket: ",OrderTicket());
                        Print(ErrLog);
                                              
                   }
            }
     }

 
ernest02:

I went and registered at the Forum you indicated and found your thread about the trailing stop on the pending order. I also saw that one of the posts had an attachment which I think must be the EA you wrote, but I could not find a way to access and download it.

Is it at all possible that you can post it on this Forum? I am sure there will be many that can use your EA.


I was paid to make the EA .... but if you search there I shared more

I had also to do a learning proces and by programming some stuff you find difficulties you don't find with backtesting

but if you logged in then can find more programs i made and shared there... most in post one of topic to find

you have now an idea what all is possible with moving pending trades with the price

Reason: