• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 4:29am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 4:29am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

EA open position on demo, but not open position on real account. Any Comment 7 replies

Close Losing Position, Set Trailing Stop to Winning Position 2 replies

Any good EA to Close/Manage Open position? 0 replies

Please help! - How to automatically close open position after 1 hour? 5 replies

Newbie help. Open/Close position. 3 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

program: open a position when (close-open)==**

  • Post #1
  • Quote
  • First Post: Oct 2, 2007 1:57pm Oct 2, 2007 1:57pm
  •  dogberry
  • | Joined Jul 2007 | Status: Member | 283 Posts
Hi, I want to write an expert advisor so that MT can automatically open a position when (close-open) at 8:00am in H4 frame is a certain value. Could anyone give me some help how I can import the (close-open) values to the expert advisor? It seems Hour() is used to get the hour values (8:00am).
Many thanks in advance!
  • Post #2
  • Quote
  • Oct 2, 2007 5:07pm Oct 2, 2007 5:07pm
  •  tesla
  • Joined Oct 2006 | Status: Friendly Neighborhood Programmer | 533 Posts
PHP Code
     // current 4hr bar close-open
    
double dDiff = iClose(NULL,PERIOD_H4,0) - iOpen(NULL,PERIOD_H4,0);
    
    
// previous 4hr bar close-open
    
double dDiff = iClose(NULL,PERIOD_H4,1) - iOpen(NULL,PERIOD_H4,1); 
 
 
  • Post #3
  • Quote
  • Edited at 12:55pm Oct 7, 2007 10:39am | Edited at 12:55pm
  •  dogberry
  • | Joined Jul 2007 | Status: Member | 283 Posts
Thank you so much, tesla. One more question, I want to know if a shortSMA is on a up or down trend (the current SMA is bigger than the previous SMA), and wrote code,

shortEma = iMA(NULL,PERIOD_H4,8,0,MODE_SMA,PRICE_CLOSE,0);
longEma = iMA(NULL,PERIOD_H4,13,0,MODE_SMA,PRICE_CLOSE,0);
shortEmap = iMA(NULL,PERIOD_H4,8,0,MODE_SMA,PRICE_CLOSE,1);
if((shortEma-longEma)<25*Point && (shortEma-shortEmap)>25*Point)

Unfortunately, the second part in "if" is not working. Even I change the second part to "(shortEma-shortEmap)>2000*Point", nothing changed when I tested it. Could you give me some ideas why it's not working?
Many thanks again.


Quoting tesla
Disliked
PHP Code
     // current 4hr bar close-open
    
double dDiff = iClose(NULL,PERIOD_H4,0) - iOpen(NULL,PERIOD_H4,0);
 
    
// previous 4hr bar close-open
    
double dDiff = iClose(NULL,PERIOD_H4,1) - iOpen(NULL,PERIOD_H4,1); 
Ignored
 
 
  • Post #4
  • Quote
  • Last Post: Oct 8, 2007 1:23am Oct 8, 2007 1:23am
  •  tesla
  • Joined Oct 2006 | Status: Friendly Neighborhood Programmer | 533 Posts
Just eyeballing it, the code looks fine. I'm guessing that there just aren't that many instances where an ema changes by more than 25 pips in one bar. Try testing with a smaller value (not larger like the 2000 you're using). Also... outputting values with Print helps tremendously.
 
 
  • Platform Tech
  • /
  • program: open a position when (close-open)==**
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022