Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  #671 (permalink)  
Old 02-08-2008, 06:52 AM
Junior Member
 
Join Date: Feb 2008
Posts: 7
ableze_joepardy is on a distinguished road
Plz correct my code (basic EMA, STOC etc.)

hi.. im new here n new to mql4 coding.. i've construct few codes based on specific condition.. hope u guys can help me to correct if theres any mistake..

okay.. lets begin


1) EMA CROSS
BUY if:
- EMA 5 > EMA 18
- both of the line is upward
- different between current n previous price for EMA5 >= 10pips

Attachment 53944

currently im using this:
Code:
double EMA5 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, 0);
double EMA5_prev = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, 1);

double EMA18 = iMA(NULL, 0, 18, 0, MODE_EMA, PRICE_CLOSE, 0);
double EMA18_prev = iMA(NULL, 0, 18, 0, MODE_EMA, PRICE_CLOSE, 1);

if (EMA5 > EMA18) {

     if ( EMA5 - EMA5_prev >= 10 && EMA18 > EMA_prev) {

           Order = BUY;

     }

}


<-- BUY CODE -->


2) RSI
Code:
double RSI = iRSI(NULL, 0, 18, PRICE_CLOSE, Current + 0);
double RSI_prev = iRSI(NULL, 0, 18, PRICE_CLOSE, Current + 1);

if (RSI > 50 && RSI > RSI_prev) {
    
     Order = BUY;

}

<-- BUY CODE -->

3) STOCH

Buy when the Oscillator (either %K or %D) falls below a specific level (e.g., 20) and then rises above that level. Sell when the Oscillator rises above a specific level (e.g., 80) and then falls below that level
Code:
double STOCH_K = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
double STOCH_D = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);

if (STOCH_K < 20 || STOCH_D < 20) {

     Order = BUY;

}
<--- BUY CODE --->
* i think i've skipped the red one.. dont know how to do that part..

Buy when the %K line rises above the %D line and sell when the %K line falls below the %D line
Code:
double STOCH_K = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
double STOCH_D = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);

if (STOCH_K > STOCH_D) {

    Order BUY;

} else 

if {STOCH_K < STOCH_D) {

    Order SELL;

}

<--- BUY & SELL CODE --->

4) In Stoc coding, MODE_MAIN indicates for what? MODE_SIGNAL indicates for what?

5) how to put auto close and auto on timer for EA?
eg: set open at 8am and close at 5pm

6) how to put disable EA on other chart when a post is opened?
such as use an EA on 2 pairs (GU and EJ) when a post on GU is opened then disable EA on EJ..


sorry if this question is quite basic.. hope u guys can teach me.. thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #672 (permalink)  
Old 02-10-2008, 08:19 PM
Member
 
Join Date: Oct 2006
Posts: 71
Big Be is on a distinguished road
A Tricky Stoploss - can you help with this?

I have put together a trend riding EA. When profit hits a certain level, I want to move the stoploss for PART of the open lots, to that profit level. I would let the rest of the lots be (or move the stoploss for the rest up to break even).
I am not using a Take Profit.

How do I code this?

Thanks,
Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #673 (permalink)  
Old 02-10-2008, 09:32 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by Big Be View Post
... When profit hits a certain level, I want to move the stoploss for PART of the open lots, to that profit level. ..
How do I code this?

Thanks,
Big Be
You cannot do that unless you have multiple positions : there may be only one SP/TP by position. But you can close a part of a position : just put the number of lots you want to close in the OrderClose(..) function.
What you also can do (it depends of your broker) is to place a pending stop (hedge) for the part you want : then later you have to do a "CloseBy" command or function.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #674 (permalink)  
Old 02-10-2008, 11:10 PM
Junior Member
 
Join Date: Apr 2007
Posts: 17
la totona is on a distinguished road
Quote:
Originally Posted by SIDDESH View Post
Hi,

Can you please give the code for previous bar.

This can be used in the EA to limit placing the orders when the previous bar is more than certain height.

Regards,

SIDDESH
Siddesh and others that can help:

The code for the previous bar is below:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);


if (close[1]<indicatorpast && close[0]>indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();

but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);

if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();

But this statement it is not performing.

Do you know what is happen? Because i think there arent errors in the statement.

The question is why is not opening at the exact point of cross when close[0]==Indicatornow? If the function would be with ==, we will prevent the open of orders above the point of crooss between the indicator and the close of the present bar but is not funtioning with this type of relationship between the variables.

Last edited by la totona; 02-14-2008 at 10:42 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #675 (permalink)  
Old 02-11-2008, 11:58 PM
Member
 
Join Date: Jan 2006
Posts: 30
DooMGuarD is on a distinguished road
#import question

hi all

i ned to cal this API function in MT4

int GetMouseMovePoints(
UINT cbSize // size of the MOUSEMOVEPOINT struct
LPMOUSEMOVEPOINT lppt, // pointer to current mouse move point
LPMOUSEMOVEPOINT lpptBuf, // buffer to store the points
int nBufPoints, // how many points the buffer can store
DWORD resolution // resolution of the points
);

please tell me the #import clausule

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #676 (permalink)  
Old 02-12-2008, 01:08 AM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,322
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by DooMGuarD View Post
hi all

i ned to cal this API function in MT4

int GetMouseMovePoints(
UINT cbSize // size of the MOUSEMOVEPOINT struct
LPMOUSEMOVEPOINT lppt, // pointer to current mouse move point
LPMOUSEMOVEPOINT lpptBuf, // buffer to store the points
int nBufPoints, // how many points the buffer can store
DWORD resolution // resolution of the points
);

please tell me the #import clausule

thanks
Moved your question to this thread.
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #677 (permalink)  
Old 02-12-2008, 01:53 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
One trade per bar?

I know this has been covered before, but can someone show me some code to allow only 1 trade per bar?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #678 (permalink)  
Old 02-12-2008, 02:28 AM
Member
 
Join Date: Oct 2006
Posts: 71
Big Be is on a distinguished road
RE: A Tricky StopLoss

Michel,
Thanks.
I was afraid of that.

Now I have to learn "fun with Magic Numbers".

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #679 (permalink)  
Old 02-12-2008, 09:03 AM
Dan7974's Avatar
Senior Member
 
Join Date: Jul 2006
Posts: 264
Dan7974 is on a distinguished road
Question!!!

How do I code this?
If previous 6 trades were a loss, I tried this, and it won't work!!!

PHP Code:
int MTL;
extern MaxTradeLoss=6;

int start()
 {
    for(
int b=0;b<MaxTradeLoss;b++)
     {
      if(
OrderSelect(b,SELECT_BY_POS,MODE_HISTORY)==true)
       {
        if(
OrderSymbol()==Symbol() && OrderProfit()<0)
         { 
          
MTL++;
         }
       }
     }
   
MTL=0;

  return(
0);
 } 
__________________
God Bless Everyone, and their trading logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #680 (permalink)  
Old 02-12-2008, 09:15 AM
azmel's Avatar
Senior Member
 
Join Date: Dec 2007
Location: United Kingdom
Posts: 194
azmel is on a distinguished road
Quote:
Originally Posted by Dan7974 View Post
How do I code this?
If previous 6 trades were a loss, I tried this, and it won't work!!!

PHP Code:
int MTL;
extern MaxTradeLoss=6;

int start()
 {
    for(
int b=0;b<MaxTradeLoss;b++)
     {
      if(
OrderSelect(b,SELECT_BY_POS,MODE_HISTORY)==true)
       {
        if(
OrderSymbol()==Symbol() && OrderProfit()<0)
         { 
          
MTL++;
         }
       }
     }
   
MTL=0;

  return(
0);
 } 
your statement MTL=0; pretty much sets MTL to zero regardless what it counted in the "for" loop. That line should be before the "for" loop and not after.

Last edited by azmel; 02-12-2008 at 09:18 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 12:29 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.