How to modify this order

 

Could someone please share with me what the code might look like if I would like to modify this order.

I know that you can only set entry orders ~5 pips (broker buffer) away from the market price. I have pending BuyStop for 1.8580. When the market moves away from this BuyStop I want to be able to modify it to enter earlier and at a better price if possible.

Let's say, modify order if (Ask>=Threshold) && ( (Ask+BrokerBuffer) < BuyStop)

threshold=originalBuyStop - 10*Points

1.8575 Ask, BuyStop is set at 1.8580

1.8574 Ask, BuyStop is modified to 1.8579

1.8573 Ask, BuyStop is modified to 1.8578

1.8572 Ask, BuyStop is modified to 1.8577

1.8571 Ask, BuyStop is modified to 1.8576

1.8570 Ask, BuyStop is modified to 1.8575

threshold=1.8570, so no longer need to modify orders.

I'm very bad at using counters to go through the orders and I'm not totally sure how to call up the existing BuyStop order. If someone could put this into code for me, I would really appreciate it!

Mucho Gracias,

dee