script to close orders only on new bar - MetaQuotes MetaTrader MQL Programming | futures trading

Go Back

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > MetaTrader > MetaQuotes MetaTrader MQL Programming

script to close orders only on new bar
Started:February 7th, 2013 (08:38 AM) by philtrader Views / Replies:805 / 1
Last Reply:February 7th, 2013 (08:38 AM) Attachments:0

Welcome to

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

script to close orders only on new bar

Old February 7th, 2013, 08:38 AM   #1 (permalink)
Trading Apprentice
Futures Experience: Advanced
Platform: NinjaTrader, MT4
Favorite Futures: forex
Posts: 3 since Jul 2011
Thanks: 4 given, 0 received

script to close orders only on new bar


I trying to create a script that closes all existing orders only when a new bar is detected.
It seems the code below always get executed even when new bar is same as old bar.
Thanks to help.

static int old_bars = 0; // remember the amount of bars already known
if (old_bars != Bars) // if a new bar is received
for (int i = OrdersTotal() - 1; i >= 0; i--)
int ticket=OrderTicket();
double lots=OrderLots();
} old_bars = Bars; // remember how many bars are known

Reply With Quote

Old February 7th, 2013, 08:38 AM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.


Reply > Futures Trading, News, Charts and Platforms > Platforms and Indicators > MetaTrader > MetaQuotes MetaTrader MQL Programming > script to close orders only on new bar

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

An Afternoon with FIO trader bobwest

Elite only

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute trade intrabar on bar close indicator spinnybobo NinjaTrader 3 April 2nd, 2012 02:59 PM
Needed Bid / Ask bar script for thinkorswim Rad4633 ThinkOrSwim 3 October 8th, 2011 02:05 PM
Trade intra-bar or at close of bar? r3algood The Elite Circle 7 October 4th, 2011 01:20 PM
Colour Bar Script Assistance zt379 NinjaTrader Programming 10 March 17th, 2011 09:20 PM
Close[0] not waiting until bar close dsraider NinjaTrader Programming 4 February 11th, 2010 05:49 PM

All times are GMT -4. The time now is 04:19 PM.

Copyright © 2016 by All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts

Page generated 2016-10-21 in 0.08 seconds with 19 queries on phoenix via your IP