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 Thread Tools Display Modes
  #421 (permalink)  
Old 10-17-2007, 09:56 PM
Member
 
Join Date: Sep 2007
Posts: 67
Ronald Raygun is on a distinguished road
Need a little help refining this EA

I have this ea which is a modified version of the "GAPS EA" found elsewhere on this forum.

Anyway, attached is a copy of the code.


Code:

#property link      ""
//---- input parameters
extern int    min_gapsize = 1;
extern double lotsize_gap = 5;
extern int MagicNumber = 10;
//----
datetime order_time = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
/* 
 Thing to be done in future in this program to make it more efficient
 and more powerful:
   1. Make the dicission of the quantity of lots used according to 
      the scillators;
   2. This program will catch the gaps.
 Things to ware of:
   1. the spread;
   2. excuting the order not on the gap ends a little bit less.
*/
// Defining the variables to decide.
   Print("order time", order_time);
   double current_openprice = iOpen(Symbol(), 0, 0);
   double previous_highprice = iHigh(Symbol(), 0, 1);
   double previous_lowprice = iLow(Symbol(), 0, 1);
   double point_gap = MarketInfo(Symbol(), MODE_POINT);
   int spread_gap = MarketInfo(Symbol(), MODE_SPREAD)+1;
   datetime current_time = iTime(Symbol(), 0, 0);
// catching the gap on sell upper gap
   if(current_openprice > previous_highprice + (min_gapsize + spread_gap)*point_gap &&
      current_time != order_time)
     {
       int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0, 
                              previous_highprice + spread_gap, 
                             "Gapped Up Sell  " + Symbol()+  "  " +Period()+ "", MagicNumber, 0, Red);
       order_time = iTime(Symbol(), 0, 0);
       Print("I am inside (sell) :-)", order_time);
       //----
       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
     }
//catching the gap on buy down gap
   if(current_openprice < previous_lowprice - (min_gapsize + spread_gap)*point_gap &&
      current_time != order_time)
     {
       ticket = OrderSend(Symbol(), OP_BUY, lotsize_gap, Ask, 0, 0, 
                          previous_lowprice - spread_gap,
                          "Gapped Down Buy  " + Symbol()+  "  " +Period()+ "", MagicNumber, 0, Green);
       order_time = iTime(Symbol(), 0, 0);
       Print("I am inside (buy) :-)", order_time);
       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+


Whenever I put this into the strategy tester, it doesn't open trades. A quick peek at the journal tells me that there were plenty of order times made. What did I do wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #422 (permalink)  
Old 10-19-2007, 05:24 AM
Junior Member
 
Join Date: Apr 2007
Posts: 11
dharsant is on a distinguished road
Help: Basic Histogram Question

This is probably really easy and I'm looking past something, but I'm out of resources and can't find an answer.

All I'm trying to do is recall the value of the previously drawn histogram bar.

Any ideas?

I.e. Close[1] shows the last closed bar on the chart.....

So what would show the last drawn histogram bar on this separate window indicator?

Thanks for any advice in advance.

-dharsant
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #423 (permalink)  
Old 10-20-2007, 01:46 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 682
wolfe is on a distinguished road
Quote:
Originally Posted by dharsant View Post
This is probably really easy and I'm looking past something, but I'm out of resources and can't find an answer.

All I'm trying to do is recall the value of the previously drawn histogram bar.

Any ideas?

I.e. Close[1] shows the last closed bar on the chart.....

So what would show the last drawn histogram bar on this separate window indicator?

Thanks for any advice in advance.

-dharsant

Which indicator are you calling? Just set the shift to call the previous bar.

Example, for a current bar moving average:
iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,0);

For a previous bar moving average:
iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,1);

The last parameter when calling an indicator signifies how many bars from current will be read.

Hope this is what you were looking for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #424 (permalink)  
Old 10-21-2007, 04:46 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 256
Beno is on a distinguished road
Coding Help Needed Please

I am trying to use a couple of different indicators in an ea but can't seem to work out how to implement them in to the system. What part of the indicator do I use to say buy or sell. How do I get Slope Direction Line into part of an EA.

Cheers

Beno
Attached Files
File Type: mq4 Slope Direction Line.mq4 (4.3 KB, 9 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #425 (permalink)  
Old 10-21-2007, 09:16 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 256
Beno is on a distinguished road
I have probably not explained myself quite right.

I am trying to find out what I need to put into iCustom this is what I have done below.
double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price)

And what I need to do to generate buy and sell signal from Slope Direction Line Indicator for my EA. Below is what I have done so far, it compiles but no positions are being generated.

bool Long = TML && SDL && HeikenAshiOpen < HeikenAshiClose && hasOpen < hasClose;
bool Short = TMS && SDL && HeikenAshiOpen > HeikenAshiClose && hasOpen > hasClose;

Any help would be great

Cheers

Beno
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #426 (permalink)  
Old 10-21-2007, 09:51 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Firstly the iCustom call needs two additional arguments at the end, namely which of the indicator buffers to read from, and which index to read at.

Secondly, "SDL" is a double number, so to just put "SDL" as a condition shows some confusion; possibly it compiles as "SDL != 0", and possibly that's what is meant.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #427 (permalink)  
Old 10-21-2007, 10:15 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 256
Beno is on a distinguished road
Gidday ralph.ronnquist

so should i create another sdl line something like SDLL = long SDLS = short ?

I think i'm right in saying that on the SDL indi

uptrend = buffer 1 & Index 1 colour Blue
dntrend = buffer 2 & Index 2 Colour Red

If so where would I put them. do I put them at the end of the iCustom line.

double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price,1,1,shift);

or am I way off track
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #428 (permalink)  
Old 10-21-2007, 10:28 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
The statement:
PHP Code:
double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price,1,shift); 
makes SDL hold the value of the second buffer (Uptrend) at the given "shift" bar.

(Note that you had a repeated ",1", which looked like a typo. In any case it should't be there)

So, yes, if you want to read off both Uptrend and Dntrend, then you'll need two variables to hold the values. As you say, Uptrend is 1 and Dntrend is 2.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #429 (permalink)  
Old 10-21-2007, 11:06 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 256
Beno is on a distinguished road
Gidday ralph

Thanks for the help It's working I can go to sleep now.



Cheers

Beno
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #430 (permalink)  
Old 10-22-2007, 02:20 AM
Junior Member
 
Join Date: Apr 2007
Posts: 11
dharsant is on a distinguished road
Quote:
Originally Posted by wolfe View Post
Hope this is what you were looking for.
It sent me in the right direction- thanks man, really appreciated.

My new issue is that when my if statement is called....

It goes off the previous indicator bar's value in relation to the current bar, and sends an Alert(); that I created... about 20 times.

How would I go about having it only send the once?

I tried created and on/off switch using variables-- doesn't work in MQL4 unfortunately.

Then I thought about Timers... if there was a timer I could create that only Alerted once over a 20 sec period that would work too....

But I'm a loss as to an idea that would actually be possible in MQL4.

Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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 On
Forum Jump

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


All times are GMT. The time now is 01:47 AM.



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