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

 

My EA calculates a buy or sell price and then places a pending order. I have noticed that the price often moves after the pending order has been placed in the wrong direction and if I could move/change the price that was calculated in the direction of the market price before placing the pending order I will get a better price to enter.

I have tried to write a little code to do this, but it is not working. I need some help from the gurus to solve this problem:

The code checks to see when the market price differs from the calculated price with a value of 2 * PriceTS (similar to a trailing stop) and then moves it in that direction by 1* PriceTS.

Here is the the three lines of code that does not work:

while (Bid > SellPrice)
{
if (Bid > SellPrice + (PriceTS * 2 * UsePoint));
SellPrice = Bid + (PriceTS * UsePoint);
}
 

Don't you mean . . .

while (Bid > SellPrice + (PriceTS * 2 * UsePoint) )
{
SellPrice = Bid + (PriceTS * UsePoint);
}

but while you are in this loop Bid will become stale . . .

 
  1. Drop the loop it does nothing.
  2. Drop the semicolon after the if so the assignment is done as part of the if.
  3. modify the order, setting a variable doesn't do anything.
 

Sorry! I retyped the code form my EA quickly and of course the semicolon after the if statement should not be there.

I want this code to work like a Trailing Stop and move the price every time the price moves e.g. 10 pips higher (2 * PriceTS) the calculated entry price should move with a number of pips = PriceTS in the same direction. (Opposite for Buy and Sell orders of course). When the while statement becomes false the code then activates the OrderSend command with the altered price.

I understand the loop does nothing. How can I then achieve my objective? Any ideas of what the code should look like?

 
RaptorUK I am going to try your suggestion. Thanks a lot for that! Will let you know.
 

Sorry RaptorUK! Tried your suggested code but things are still the same. The price does not get changed or moved in the direction of the market price.

There must be a way to do this!

 
ernest02:

Sorry! I retyped the code form my EA quickly and of course the semicolon after the if statement should not be there.

I want this code to work like a Trailing Stop and move the price every time the price moves e.g. 10 pips higher (2 * PriceTS) the calculated entry price should move with a number of pips = PriceTS in the same direction. (Opposite for Buy and Sell orders of course). When the while statement becomes false the code then activates the OrderSend command with the altered price.

I understand the loop does nothing. How can I then achieve my objective? Any ideas of what the code should look like?


if(     )
maybe
 
ernest02:

Sorry! I retyped the code form my EA quickly and of course the semicolon after the if statement should not be there.

I want this code to work like a Trailing Stop and move the price every time the price moves e.g. 10 pips higher (2 * PriceTS) the calculated entry price should move with a number of pips = PriceTS in the same direction. (Opposite for Buy and Sell orders of course). When the while statement becomes false the code then activates the OrderSend command with the altered price.

I understand the loop does nothing. How can I then achieve my objective? Any ideas of what the code should look like?

So what you want is . . . .

if (Bid > PendingOrderOpenPrice + (2 * PriceTS) )  PendingOrderOpenPrice += PriceTS;
 
That looks great RaptorUK. But will it not do this action only once and not again? If the price moves further I need the action to take place again. Also if the Bid is not greater than the Pending OrderOpenPrice at that particular cycle/ moment nothing will happen?
 
ernest02:
That looks great RaptorUK. But will it not do this action only once and not again? If the price moves further I need the action to take place again. Also if the Bid is not greater than the Pending OrderOpenPrice at that particular cycle/ moment nothing will happen?

After it happens the first time PendingOrderOpenPrice has been changed by PriceTS, if price moves again by more than PriceTS PendingOrderOpenPrice will again be changed by PriceTS . . . . the issue I see is when do you actually place this order ?

It's a little hard to give more specific advice/suggestions without seeing more code or just getting a better understanding of how things work in your EA and what you are trying to make happen.

 

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.

Reason: