• Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)

Suggestion Need a help for making an mt4 script

thomas123

New Member
Credits
0
Hi everyone...
I need an mt4 script that can put one buy stop order and one sell stop order by DISTANCE from the OPEN PRICE of a specified candle. No SL and TP needed.

For example:
In the script settings, I set the trading time start at 12:15, distance 10 pips, and lot size 1. When the time comes up (12:15) and it detects the open price of candle 12:15 is 1.12345, so the script immediately put a buy stop at 1.12445 and a sell stop at 1.12245. Can someone help to create or share it if you have one please?

Thank you
1f64f.png

Best regards, Shakka.
 
Check.

StartHour // hour of placing an order
StartMin // minute of placing an order

EndHour // hour of order deletion
EndMin // minute of order deletion

Start_Lot // volume

dist_order // distance from the opening price of the candle

Magic // magic number for the order
 

Attachments

Ок.:хорошо:
Ok shipr, found a problem here.
Once after I attached the script into a chart, there was no a setting window appear, instead it placing stop order immediately. I cannot change the inputs setting. Can you fix it?
Thank you
 
---------------------------------------

1. open the editor. F4
2. as in the picture, add this line: #property show_inputs
3. compile the code. F7

The settings should appear.
 

Attachments

  • _01.png
    _01.png
    52.5 KB · Views: 58
Check.

StartHour // hour of placing an order
StartMin // minute of placing an order

EndHour // hour of order deletion
EndMin // minute of order deletion

Start_Lot // volume

dist_order // distance from the opening price of the candle

Magic // magic number for the order


##########=========########

i want to backtest about this system, if ok early give information
 
Remade.

Check.


Advisor.

1. drop the Expert into the advisors folder.

2. The Expert Advisor Places two stop orders at the specified time.

3. Expert Advisor Deletes the remaining order at the specified time.

4. The expert itself is unloaded from the chart, with the removal of the last order by it.

-------------------------------

ps Delete the script, it's not working.
 

Attachments

Remade.

Check.


Advisor.

1. drop the Expert into the advisors folder.

2. The Expert Advisor Places two stop orders at the specified time.

3. Expert Advisor Deletes the remaining order at the specified time.

4. The expert itself is unloaded from the chart, with the removal of the last order by it.

-------------------------------

ps Delete the script, it's not working.
Hello shipr, your help is highly appreciated.
I have some request.
For point no 2, can you please modify it to place stop order exactly from open price/open value of chosen candle? Must exactly the open price/value not the running price. As a benchmark, that open price/value can be seen in the data window.
For point no 3, can be removed, it is not needed.
For point no 4, the EA can trades every day without needing to be reattached everytime.
Add an One Cancel Other (OCO) feature, that can be turned ON or OFF. E.g. buy stop get triggered, delete the sell stop, and vice versa.
Thank you..
Best regards, Shakka.
 
Last edited:
1. №2 Позицию можно открыть только по цене открытия свечи.
Ордер не может быть размещен по цене открытия свечи. Минимально допустимое расстояние для каждого брокера разное.
Установите dist_order = 0; И вы увидите, какова минимальная стоимость пипсов, на которую размещается ордер у вашего брокера.
Or I misunderstood you.
ps Для SELL_STOP я не стал добавлять минимальное размещение ордера. Я исправлю это.

2. №3 можно сделать..
3. №4 можно сделать..
 
Last edited:
Explain with an example. What should happen. How orders should be placed. For example:
1. The time set in the parameters has come.
2. A new candle has been opened.
3. Next what?
4. Where should the BUY_STOP order be placed?
4.1. At what price?
4.2. What should happen when the opposite order is triggered?
5. Where should the SELL_STOP order be placed?
And so on...

ps Try to explain point by point, otherwise it is not possible to ask clarifying questions. And also, understanding can leave us, and never return.
 
Remade.

Check.
Hello shipr...
I found some problems, as follows:
1. The OCO is not working.
2. For safety, can it stop placing new order if I delete the position manually?
3. I noticed that the buy stop order distance was calculated from ask price. Can you make it from bid price instead of ask price?
4. In the input setting, first and second column is not in English.
20230714_115405.jpg

Thank you
 

Attachments

  • 20230714_115405.jpg
    20230714_115405.jpg
    1.7 MB · Views: 215
Last edited:
Remade.

Check.
Hi shipr, same problem here:
1. After EA placed stop order, and I deleted it manually, it kept replacing the new stop order. Only after I removed the EA, then no more order were placed.
2. I noticed that the buy stop order distance was calculated from ask price. Can you make it from bid price instead of ask price?
Thanks
 
Hi shipr, another question. Can it work everyday at the same time without needing to be reattached?
Hi shipr, same problem here:
1. After EA placed stop order, and I deleted it manually, it kept replacing the new stop order. Only after I removed the EA, then no more order were placed.
2. I noticed that the buy stop order distance was calculated from ask price. Can you make it from bid price instead of ask price?
Thanks
Once the above problem solved, can you add this parameter please.
In the EA setting, there are start hour and start min. Please add start seconds. What is it used for? The following is an example case of why we need it. Hope it explained it clearly.
E.g. if I set start trading at 18:37:05, it will place stop order 5 seconds after the opening of candle 18:37 (in this case use 1 min timeframe). The open price of candle 18:37 is now become a historical data, can be seen and printed in data window, permanently unchanged. So, there is 5 secs delay, can be used for the EA to notice that open price. By this way, when the trading time has come which is 18:37:05, it will make the EA accurately place stop order X pips away calculated from that open price. Does it make sense and possible to be coded?
Thank you
1f64f.png
 
1. At the specified time, the adviser places 2 opposite orders.

2. If one placed order works, then the second one is deleted.


3. If the distance from the open candle turns out to be unacceptable,
the expert will calculate the placement of the order,
based on the current price.


4. Time of placing orders, entered in the input field, red.
If the time is set correctly, the input field will change color from red to blue.

Change the time in the input field, on the chart with a mouse click and keyboard and press Enter.

The rest of the settings can be found in the Expert Options.

--------------------------------------------------------------------------------

_01.png _02.png _03.png _04.png _05.png
 

Attachments

  • _01.png
    _01.png
    13.2 KB · Views: 48
  • _02.png
    _02.png
    12.1 KB · Views: 46
  • _03.png
    _03.png
    27.9 KB · Views: 46
  • _04.png
    _04.png
    32.3 KB · Views: 47
  • _05.png
    _05.png
    31.1 KB · Views: 47
  • !exp_STOP_Order_2A.ex4
    !exp_STOP_Order_2A.ex4
    17.8 KB · Views: 8
1. At the specified time, the adviser places 2 opposite orders.

2. If one placed order works, then the second one is deleted.


3. If the distance from the open candle turns out to be unacceptable,
the expert will calculate the placement of the order,
based on the current price.


4. Time of placing orders, entered in the input field, red.
If the time is set correctly, the input field will change color from red to blue.

Change the time in the input field, on the chart with a mouse click and keyboard and press Enter.

The rest of the settings can be found in the Expert Options.

--------------------------------------------------------------------------------

View attachment 157980 View attachment 157981 View attachment 157982 View attachment 157983 View attachment 157984

Hi shipr, nice improvement, thank you...
But, there are something need to be fixed:
1. For simplicity, you may remove the tp and sl, since I dont use it.
2. Place buy stop order should be following bid price, not ask price.
3. EA should be strictly place stop order based on open price of a candle, not current running price. Placing accurately, not even 0.01 pips difference.

Below is an example of inaccurate execution of the EA. I set the distance 10 pips away.
20230720_113512.jpg
Open price candle 05:29 is 0.68289
- It place buy stop at 0.68396❌ (it should be at 0.68389✔)
- It place sell stop at 0.68184 ❌ (it should be at 0.68189✔)

Kind regards,
Shakka
 

Attachments

  • 20230720_113512.jpg
    20230720_113512.jpg
    2.6 MB · Views: 166
Last edited:
3. It is not possible to simultaneously place two opposite pending orders at the opening price of a new bar.

I don't understand where you want to put pending orders.

Show in the picture where you want to put them?
 

Attachments

  • _01.png
    _01.png
    8 KB · Views: 36
Back
Top