How to send order at the close of the bar?
Page 1 of 614 123 ... LastLast
Results 1 to 10 of 35

Thread: How to send order at the close of the bar?

  1. #1
    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

  2. #2
    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.

  3. #3
    Thank you Ronald. Open of this pub is fine. I'll try it.
    Best regards, Q

  4. #4
    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.

  5. #5
    Quote Originally Posted by ;
    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/...5723409598.ex4

  6. #6
    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?

  7. #7
    Quote Originally Posted by ;
    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.

  8. #8
    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

  9. #9
    Quote Originally Posted by ;
    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...

  10. #10
    Quote Originally Posted by ;
    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/...6773845439.mq4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.