PDA

View Full Version : How to send order at the close of the bar?



byoxky78
08-01-2008 07:26, 07:26 AM
Hello everyone, I'm a begginer in MT programming and I have stuck at one thing. How to send a market order at the close of a bar? Indiors is calculated by me in the close and the order remains send intrabar.
Please assist

guixxe1594
09-02-2022 12:33, 12:33 PM
Well...

PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>
intBarCount</span><span style=”color: #007700”>;

</span><span style=”color: #0000BB”>init</span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>1</span><span style=”color: #007700”>;

</span><span style=”color: #0000BB”>Beginning </span><span style=”color: #007700”>()


if(</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>!=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(...);
</span><span style=”color: #0000BB”></span> </span> </code>
Basically, the EA will put trades in the open of the new bar.

Another option is:
PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>
intTimeCount</span><span style=”color: #007700”>;


</span><span style=”color: #0000BB”>start</span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>TimeCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Period</span><span style=”color: #007700”>();

</span><span style=”color: #0000BB”>datetimeBarEnd</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Timing </span><span style=”color: #007700”>#91;</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>#93; (</span><span style=”color: #0000BB”>TimeCount</span><span style=”color: #007700”>*</span><span style=”color: #0000BB”>60</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”>intSecondsToBarEnd</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>BarEnd</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>TimeCurrent</span><span style=”color: #007700”>();

if(</span><span style=”color: #0000BB”>SecondsToBarEnd</span><span style=”color: #007700”>lt;=</span><span style=”color: #0000BB”>5</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(...)
</span><span style=”color: #0000BB”></span> </span> </code> This piece of code puts an order when there is less than 5 seconds left in a bar.

byoxky78
09-02-2022 13:55, 01:55 PM
Thank you Ronald. Open of this pub is fine. I'll try it.
Best regards, Q

Jolabejo
09-02-2022 15:18, 03:18 PM
Wish I could get some help over. I'm only a trader who would like to get help as I've hunting for it because a while ago.

I currently looking to get an script or an EA where it could open my trades at the following opening candle or the end of current candles.

I found difficulties to start the trade exactly at the opens of their new candles although I'm currently using hotkey buy / sell scripts. It always been pips.

So wish could get a little hand out of here.

byoxky78
09-02-2022 16:40, 04:40 PM
Wish I could get some help over here as well. I am just a trader who wish to get help as I've hunting for it because a while ago.

I currently searching to get an script or a EA where it might open my transactions at the next opening candle or the conclusion of current candles.

I discovered difficulties to start the trade exactly at the opens of the new candles although I am currently using hotkey buy / sell scripts. It always been late several pips.

So want might get a small hand from here.

Mphpopular mph, I made a script with Ronald's code but it isn't opening the order on the start of the bar yet
Ronald, will you examine the code and fix what is wrong?
Thank you

PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>intBarCount</span><span style=”color: #007700”>;
</span><span style=”color: #0000BB”>intinit</span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>1</span><span style=”color: #007700”>;
return(</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”>intstart</span><span style=”color: #007700”>()

if(</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>! =</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(</span><span style=”color: #0000BB”>Symbol</span><span style=”color: #007700”>(),</span><span style=”color: #0000BB”>OP_BUY</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0.1</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>Ask</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>3</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #DD0000”>”BuyOrder”</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>255</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>Blue</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”></span> </span> </code> https://www.nigeriaforextrading.com/attachments/1519363765723409598.ex4

Jolabejo
09-02-2022 18:02, 06:02 PM
I will test this out the following week because tonight will going to market close.

Particularly, I think what I needed is juz an EA whereby it could start trades in the end of the bar / open of the bar, then I can attach it when I desire, and juz dis-attach it as it has already open the transactions. It is the best if a script is to do that. However an EA with above purpose is adequate for me as I just want to start transactions in the most precise accurate value of the bar.

Notice: Can post some charts whereby it did not open in the opening of bars? Can it involving disperse stuff?

guixxe1594
09-02-2022 19:24, 07:24 PM
mph, I made a script with Ronald's code but it is not launching the order on the open of the bar yet
Ronald, can you examine the code and fix what's wrong?
Thank you

PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>intBarCount</span><span style=”color: #007700”>;
</span><span style=”color: #0000BB”>intinit</span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>1</span><span style=”color: #007700”>;
return(</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”>intstart</span><span style=”color: #007700”>()

if(</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>! =</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(</span><span style=”color: #0000BB”>Symbol</span><span style=”color: #007700”>(),</span><span style=”color: #0000BB”>OP_BUY</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0.1</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>Ask</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>3</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #DD0000”>”BuyOrder”</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>255</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>,</span><span style=”color: #0000BB”>Blue</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”></span> </span> </code> EX4 documents are useless to me.

But if it is a script, it won't work because scripts run just on the tick for which they were enabled.

It Has to Be an EA. And make sure that after the OrderSend work, you place BarCount = Bars. This way, the EA understands the transaction was placed by it.

byoxky78
09-02-2022 20:47, 08:47 PM
Sorry Ronald, if had become the file. So it would not function as a script for mphpopular. I'll try it in my EA.
Thank you, enjoy
Dan

Jolabejo
09-02-2022 22:09, 10:09 PM
EX4 files are useless to me.

But if it is a script, then it won't function because scripts run only on the tick for which they were enabled.

It needs to be an EA. And be certain after the OrderSend function, you place BarCount = Utilities. This way, the EA knows the trade was placed by it. Mine to get one for me? As I really dunno the way to writes the EA code outside....
Juz wish to have one... But plz do ignore me whether it is troublesome. Cause I know making an EA requires a lot of time...

byoxky78
09-02-2022 23:31, 11:31 PM
Properly...

PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>
intBarCount</span><span style=”color: #007700”>;

</span><span style=”color: #0000BB”>init</span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>1</span><span style=”color: #007700”>;

</span><span style=”color: #0000BB”>start</span><span style=”color: #007700”>()


if(</span><span style=”color: #0000BB”>BarCount</span><span style=”color: #007700”>!=</span><span style=”color: #0000BB”>Bars</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(...);
</span><span style=”color: #0000BB”></span> </span> </code>
Basically, the EA will put trades in the start of the new pub.

Another alternative is:
PHP Code: <code><span style=”color: #000000”> <span style=”color: #0000BB”>
intTimeCount</span><span style=”color: #007700”>;


</span><span style=”color: #0000BB”>begin </span><span style=”color: #007700”>()

</span><span style=”color: #0000BB”>TimeCount</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Period</span><span style=”color: #007700”>();

</span><span style=”color: #0000BB”>datetimeBarEnd</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>Time</span><span style=”color: #007700”>Number 91;</span><span style=”color: #0000BB”>0</span><span style=”color: #007700”>Number 93; (</span><span style=”color: #0000BB”>TimeCount</span><span style=”color: #007700”>*</span><span style=”color: #0000BB”>60</span><span style=”color: #007700”>);

</span><span style=”color: #0000BB”>intSecondsToBarEnd</span><span style=”color: #007700”>=</span><span style=”color: #0000BB”>BarEnd</span><span style=”color: #007700”>-</span><span style=”color: #0000BB”>TimeCurrent</span><span style=”color: #007700”>();

if(</span><span style=”color: #0000BB”>SecondsToBarEnd</span><span style=”color: #007700”>lt;=</span><span style=”color: #0000BB”>5</span><span style=”color: #007700”>)</span><span style=”color: #0000BB”>OrderSend</span><span style=”color: #007700”>(...)
</span><span style=”color: #0000BB”></span> </span> </code> This piece of code puts an order when there is significantly less than 5 seconds left at a pub. Ronald, I left EA's with both codes and wont work. That the expresion BarCount! = Bars is always true, BarCount variable is different than Bars variable because we've got BarCount = Bars - 1 at the init() function, so it puts an order at each tick.
Can you look at my attached EA and see what's wrong, perhaps you can make it work.
Thanks, Dan
https://www.nigeriaforextrading.com/attachments/151936376773845439.mq4

guixxe1594
09-03-2022 00:54, 12:54 AM
The code is functioning as it is according to the egy tester along with my broker.

Is there a smiley face in the top right hand corner of the chart you're trading?

byoxky78
09-03-2022 02:16, 02:16 AM
Of corse I've the smiley. It is sending the order at every tick, at first tick, not in open of the bar.

guixxe1594
09-03-2022 03:38, 03:38 AM
I just took one of my existing EAs and establish that instead.

Just make certain EachTickMode is set to false so that it'll open trades in the start of the second pub.
https://www.nigeriaforextrading.com/attachments/15193637691944389660.mq4

OXNWLGOC28SALVAME
09-03-2022 05:00, 05:00 AM
How about That?

Inserted Code //-- proceed trading only for first tiks of new pub if(Volume#91;0#93;gt;1) return; else OrderSend(...)

Jolabejo
09-03-2022 06:23, 06:23 AM
I just took one of my current EAs and place that instead.

Simply make sure EachTickMode is set to false so that it'll open transactions at the start of the next bar. Tq very much. Employing rightnow.... Working great.... Really alot of thanks

Edit:
It working great it opening transactions. But I juz found out, it's simply buy script... Anyone could change it to bcome market script. . TQ very much

byoxky78
09-03-2022 07:45, 07:45 AM
Tq very much. Employing rightnow.... Working good.... Really alot of thanks

Edit:
It working good it opening transactions. But I juz found out, it is simply buy script... Anyone could change it to bcome sell script. . TQ very much I created the sell EA too. The matter is it is not working for me. The transaction is being opened by it at tick on a 1 min chart. What are you doing that is working for you?
The way it works is when is no additional transaction on such pair/acc, takes a position within 3 pip slipeage and creates a sound, then you'll need to remove it in the chart until you shut the place, or reach on the EA button so that it will not take a different transaction. You can modify the size of the transaction in increments of 1 minilots, 0.1 Lot.
This is your sell EA too:
https://www.nigeriaforextrading.com/attachments/1519363770611596440.mq4

byoxky78
09-03-2022 09:07, 09:07 AM
How about this?

Inserted Code //-- go trading just for first tiks of new pub if(Volume#91;0#93;gt;1) return; otherwise OrderSend(...) OK, this worked for me personally and it's much simple to execute. Thanks a thousand ydaudw
Here are the new EA's. As I analyzed so far one trade opens on the tick of the pub. You need to stop it or another trade may be taken by it.
Test this EA's on a demo acc and use them at your own risk.
https://www.nigeriaforextrading.com/attachments/1519363772387590974.mq4
https://www.nigeriaforextrading.com/attachments/1519363774812461629.mq4

Jolabejo
09-03-2022 10:29, 10:29 AM
Thanks, I willl try it out by tomoro since now 1am in the morning....

I did find the problem of slippage in hour ago where the price was moving too faz and the EA is neglect to take the trade... Very sad...

byoxky78
09-03-2022 11:52, 11:52 AM
Thanks, I willl try it out by tomoro since today already 1am in the morning....

I did locate the problem of slippage in hour past whereby the price was going too faz and the EA is neglect to spend the trade... Very sad... This EA's have a slippage of 3 pips. If the price moves to fast and from the time the order reaches the broker it moved more than 3 pips will not take the transaction. In case you need more slippage alter the EA in this line:
Inserted Code OrderSend(Symbol(),OP_BUY,TradeSize,Ask,3,0,0,Buy Order,0,0,Blue); Rather than nr 3 put your nr and hit the Compile button

Jolabejo
09-03-2022 13:14, 01:14 PM
Now will test it out. The slipage will be changed by me based on my favor. Will report back if I did saw anything

Jolabejo
09-03-2022 14:36, 02:36 PM
Now is another matter. If I attach the exact same EA on exactly the same time on both graph. Will it requires commerce for both or will not take for both number issue? Like I tried juz I place the EA on my both charts, and the transactions weren't taken by both.

Or can it be there's a requirement rules where you must attach the EA to the graph at 5minutes before in order to allow the Ea work properly?

Jolabejo
09-03-2022 15:58, 03:58 PM
I am not certain why this happne. I tried on both the demo and real. All cant works and send out this for me.
https://www.nigeriaforextrading.com/attachments/1519363795567757126.png

guixxe1594
09-03-2022 17:21, 05:21 PM
Now is another matter. If I attach the exact same EA on precisely the exact same time on both graph. Will it won't take for the two number issue or commerce for both? As I attempted juz today, I set the EA on my both charts, and both didn't take the trades.

Or can it be there's a requirement rules whereby you must join the EA to the graph at 5minutes earlier in order to let the Ea operate properly?
You can only join one EA per chart. If you want EAs, you require charts.

As for your other post. . .it looks just like your lot size is not permitted from the broker. What lot size are you currently using?

Jolabejo
09-03-2022 18:43, 06:43 PM
1) Juz a 0.1 normal lot size. REal and demonstration all cant work out... Dunno why...
(Edit)
Response: I juz test it outside wif 1.0 lot size. It's currently working. Seems like the EA only able to take 1.0 lot but not able to take 0.1??? Hehe

two ) I supposed erm, If I attach the the open EA on GU and EU chart.... Will trades open in the chart? Or they open either 1 due to there is not any number?

guixxe1594
09-03-2022 20:05, 08:05 PM
If was coded by mepersonally, you only need to worry about magical numbers if they are on precisely the exact same pair, but different time frames.

If it's another EA, I recommend you use a magical number, just in case.

Jolabejo
09-03-2022 21:28, 09:28 PM
I using the buy EA that you posted. It working nicely. However, the I using the sEll. Does not work nicely. But I very thanks and thankful for what he is trying to achieve for me personally....

4xq, million thanks to you.
Ronald, billion due to you

guixxe1594
09-03-2022 22:50, 10:50 PM
My ea can perform both buy and sell, just set the extended value to false...

byoxky78
09-04-2022 00:12, 12:12 AM
My ea can perform both buy and sell, only put the long value to bogus... Ronald, where is the EA? You posted one of mine with a comment modifiion

byoxky78
09-04-2022 01:34, 01:34 AM
I using the buy EA that posted by you. It functioning. But the I using the sEll from. Does not work well. But I really thanks and thankful for that which he is hoping to achieve for me personally....

, million thanks to you.
Ronald, billion thanks for you personally What time frame chart are you currently using and wich EA? You have to use the ones which begin with 01...

guixxe1594
09-04-2022 02:56, 02:56 AM
You are right, I don't find an EA with my own templates.

Here it is.

For long, set DirectionLong to authentic, reverse for brief.
https://www.nigeriaforextrading.com/attachments/1519363797799307192.mq4

byoxky78
09-04-2022 04:19, 04:19 AM
Thanks, Ronald

Jolabejo
09-04-2022 05:41, 05:41 AM
What time period chart are you using and wich EA? You've got to use those which start with 01.... 15m TF. The buy and sell EA in post.
Now testing the version from ronald. Thanks

Jolabejo
09-04-2022 07:03, 07:03 AM
Thank you Ronald, it working good now.... SEtting it as I juz and my hotkey loved it. Really ease me alot....

Thank you for all your hardwork and atttention for me personally. .

minemu
09-04-2022 08:25, 08:25 AM
Hello Ronald, I'd love to ask you that if it's possible to make an EA that's much like the Straddle Route EA but can open more than 1 buy stop/sell stop on each side of the current price. Thank you very much.

guixxe1594
09-04-2022 09:48, 09:48 AM
Start looking for my grid , I think I've already set that up for you.