Forex



Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

EXCLUSIVE FORUM
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1591 (permalink)  
Old 02-14-2009, 07:13 PM
Member
 
Join Date: May 2008
Posts: 31
payback is on a distinguished road
Quote:
Originally Posted by rwb181 View Post
Hi Wiley,

Thanks for the help.
To be honest, I have been so busy working on a solution, I forgot that I posted the question.
I spent that day going through the mql4 manual and figured out a way to do it.
When it is time to start trading, I set a variable called "OpeningTime" equal to the current time. During the trading session and if a trade has been closed, I have the EA cycle through the order history and look for any orders that are from the given chart and EA and also have a closing time that is greater than "OpeningTime". It then compares the profit (or loss) of the order (using the OrderProfit() function) with what I have set (with an external variable) as being enough. I set it up so that I can stop trading if I made enough of a profit and/or if I have lost a given amount.
Backtesting has shown that it really doesn't improve the results of an already optimized EA any (in fact, more often it makes them worse), which is to be expected because we never know if the next trade (which I have now eliminated) will make things better or worse.
It does allow me to set more stringent conditions from the start though. So, the EA can be optimized using the "get out, I've had enough" option from the start. And that does seem to make my results quite a bit better.

Thanks for your help.
Ron
no it is not what i need
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1592 (permalink)  
Old 02-15-2009, 02:47 AM
Junior Member
 
Join Date: Dec 2006
Location: north carolina
Posts: 15
tomhliles is on a distinguished road
this will get you the maximum loss

Code:
void history()
{max_loss=0;
int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Access to history failed with error (",GetLastError(),")");
        break;
       }
       if (OrderSymbol()==Symbol()&&OrderProfit()>=max_loss)max_loss=OrderProfit();
       {
       //code
       }

}
}
__________________
trendchaser.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1593 (permalink)  
Old 02-15-2009, 03:31 AM
Senior Member
 
Join Date: Nov 2006
Posts: 307
luxinterior is on a distinguished road
Quote:
OrderSymbol()==Symbol()&&OrderProfit()>=max_loss
I'm sure it was just a typo but...

If you're looking for the maximum loss the comparison operator should be the 'less than (<)' not the 'greater than (>)'.

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1594 (permalink)  
Old 02-15-2009, 04:32 AM
increase's Avatar
Senior Member
 
Join Date: May 2006
Posts: 843
increase is on a distinguished road
Quote:
Originally Posted by increase View Post
Trying to use the attached Dianpoli in an EA I added arrows to read those in icustom, but my icustom line does not pick the up, any help please?

Here is what I use in the EA val2 = iCustom(Symbol(), Period(), "test3",300,15,1,1,0); & val3 = iCustom(Symbol(), Period(),"test3",300,15,1,2,0);
Never seem to get anyone to help, guys please respond
__________________
New to Forex? Get all you need for Free at my site Click Here
You can also get my Hot Forex System (scroll to the bottom of the page): Click Here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1595 (permalink)  
Old 02-15-2009, 04:45 PM
Junior Member
 
Join Date: Feb 2009
Posts: 2
anono is on a distinguished road
Thumbs up Automated Expert Advisor Builder

Fastbrokersfx has a free (they call exclusive) Automated Expert Advisor Builder.

They say, "FastBrokersFX offers a free Expert Advisor Builder. With us you don't need to be an experienced programmer to design your trading robots for MT4. Just a few clicks, save your generated EA file and you're done!"

You can create one by clicking on that link from their home page:
Fastbrokersfx | Forex Trading | Forex ECN Access |

Good luck!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1596 (permalink)  
Old 02-15-2009, 08:45 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by increase View Post
Never seem to get anyone to help, guys please respond
With a moderate amount of guess work, I would suggest that the problem is with the indicator, or your extension to it, and not your use of iCustom. Perhaps it would be better to assign buffers 2 and 3 together with the alerts? (Though I couldn't work out how/when their index-zero ([0]) values would be assigned anyhow.)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1597 (permalink)  
Old 02-16-2009, 12:31 PM
Junior Member
 
Join Date: Feb 2009
Posts: 13
YenTrader2 is on a distinguished road
Price Data Information

My exits and entry are based on signals generating a condition on the open of the next bar (entry and exit), should I be using the open prices for indicators and moving averages? I always have used end of day data for stock trades, so naturally that's what I've gravitated toward. What's the consensus out there?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1598 (permalink)  
Old 02-16-2009, 06:52 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 515
Beno is on a distinguished road
Just thinking

how do you set a trailing stop at the pairs minimum Stop Level so if the stop level is at 4 pip or 25 pip the sl will kick in at that depending on the pair.
I should say that how do you use the contract specification for each pair.

Cheers

Beno

Last edited by Beno; 02-16-2009 at 07:08 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1599 (permalink)  
Old 02-16-2009, 10:34 PM
Junior Member
 
Join Date: Jan 2009
Posts: 18
PEDCORD is on a distinguished road
Sidus_Bago indicator

Hi increase,

I wonder if you can help me to code Sidus_Bago to be a MTF indicator. I think this indicator very good too.

Sidus_Bago is here:
Sidus System confirmation' indicator?

Thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1600 (permalink)  
Old 02-17-2009, 04:59 AM
Junior Member
 
Join Date: Feb 2009
Location: Perth, Oz
Posts: 17
Couso is on a distinguished road
Can anyone help me with this EA?

Hi all,
I've had a go at my first EA but it won't compile; I get an error "'\end of program' - unbalanced left parenthesis" and I've gone through it a few times but can't find the problem. Don't worry about the logic of the trading strategy (unless you're keen), I'll work on that once it compiles and runs...
Apparently I don't have permission to attach files, so sorry about the cut and paste too.

Thanks,

Rob,
Perth, Aus

//---------------

//+------------------------------------------------------------------+
//| Rob_Ea.mq4 |
//| Rob Cousins |
//| |
//+------------------------------------------------------------------+
#property copyright "Rob Cousins"
#property link ""

#define MAGICMA 20090216

//---- input parameters
extern double Lots;
extern int Short_MA=5;
extern int Long_MA=15;
extern double Stoch_Upper=70.0;
extern double Stoch_Lower=30.0;
extern double RSI_Upper=80.0;
extern double RSI_Lower=20.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}

string Current_Indication()
{

// Moving Average variables
double MA_Short;
double MA_Long;
string Current_MA_Indicator;
string Previous_MA_Indicator;
string MA_Indicator;


// Stochastic Variables
string Current_Stoch_Indicator;
string Previous_Stoch_Indicator;
string Stoch_Indicator;

// RSI Variables
string Current_RSI_Indicator;
string Previous_RSI_Indicator;
string RSI_Indicator;

// --------------------------------------
// first get MAs and check for a MA Cross
// --------------------------------------

MA_Short=iMA(NULL,0,Short_MA,0,1,PRICE_MEDIAN,0);
MA_Long=iMA(NULL,0,Long_MA,0,0,PRICE_MEDIAN,0);

if (MA_Short>MA_Long) Current_MA_Indicator="BUY";
if (MA_Short<MA_Long) Current_MA_Indicator="SELL";

// set the previous and current value using the shifted MA (the last '1' in the options)

if (iMA(NULL,0,Short_MA,0,1,PRICE_MEDIAN,1)>iMA(NULL, 0,Long_MA,0,0,PRICE_MEDIAN,1)) Previous_MA_Indicator="BUY";
if (iMA(NULL,0,Short_MA,0,1,PRICE_MEDIAN,1)<iMA(NULL, 0,Long_MA,0,0,PRICE_MEDIAN,1)) Previous_MA_Indicator="SELL";

if ((Current_MA_Indicator=="BUY") && (Previous_MA_Indicator=="BUY")) MA_Indicator="BUY";
if ((Current_MA_Indicator=="SELL") && (Previous_MA_Indicator=="SELL")) MA_Indicator="SELL";


// ----------------------------
// Stochastic Indicator check
// ----------------------------

if(iStochastic(NULL,0,6,3,3,MODE_SMA,0,MODE_MAIN,0 )>Stoch_Upper) Current_Stoch_Indicator="BUY";
if(iStochastic(NULL,0,6,3,3,MODE_SMA,0,MODE_MAIN,0 )<Stoch_Lower) Current_Stoch_Indicator="SELL";

if(iStochastic(NULL,0,6,3,3,MODE_SMA,0,MODE_MAIN,1 )>Stoch_Upper) Previous_Stoch_Indicator="BUY";
if(iStochastic(NULL,0,6,3,3,MODE_SMA,0,MODE_MAIN,1 )<Stoch_Lower) Previous_Stoch_Indicator="SELL";

if ((Current_Stoch_Indicator=="BUY") && (Previous_Stoch_Indicator=="BUY")) Stoch_Indicator="BUY";
if ((Current_Stoch_Indicator=="SELL") && (Previous_Stoch_Indicator=="SELL")) Stoch_Indicator="SELL";


// ----------------------------
// RSI Indicator check
// ----------------------------

if(iRSI(NULL,0,3,PRICE_CLOSE,0)>RSI_Upper) Current_RSI_Indicator="BUY";
if(iRSI(NULL,0,3,PRICE_CLOSE,0)<RSI_Lower) Current_RSI_Indicator="SELL";

if(iRSI(NULL,0,3,PRICE_CLOSE,1)>RSI_Upper) Previous_RSI_Indicator="BUY";
if(iRSI(NULL,0,3,PRICE_CLOSE,1)<RSI_Lower) Previous_RSI_Indicator="SELL";

if ((Current_RSI_Indicator=="BUY") && (Previous_RSI_Indicator=="BUY")) RSI_Indicator="BUY";
if ((Current_RSI_Indicator=="SELL") && (Previous_RSI_Indicator=="SELL")) RSI_Indicator="SELL";


//----------------------------------------
// Figure out if you're in a buy or sell situation
//----------------------------------------

if((MA_Indicator=="BUY") && (Stoch_Indicator=="BUY") && (RSI_Indicator=="BUY") return("BUY");
if((MA_Indicator=="SELL") && (Stoch_Indicator=="SELL") && (RSI_Indicator=="SELL") return("SELL");


}



//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
string Current_Trade(string symbol)
{

//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false )
{
return ("NONE");
break;
}
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) return("BUY");
if(OrderType()==OP_SELL) return("SELL");
}
}

}


//----------------------------------------------------------------------
// If the signal has changed direction the first thing to do is Close
// the current open trade before opening another.
//-----------------------------------------------------------------------

void CloseTrade(string symbol)

{
// double ma;
//---- go trading only for first tiks of new bar
// if(Volume[0]>1) return;

//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break; // there are no open trades
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
// leaving both options for the moment in case I want to do it differently
// eg have a different colour, or whatever. Otherwise the two commands are the same
// and you'd only need one. Except the different prices I suppose... Doh!

if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
}
//----
}


//-----------------------------------------------------------
// Open a position if that's what the tea leaves say
//------------------------------------------------------------

void OpenTrade(string symbol,string Type)
{

int res;

//---- buy conditions
if(Type=="BUY") OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"ROB EA TEST",MAGICMA,0,Blue);

//---- sell conditions
if(Type=="SELL") OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"ROB EA TEST",MAGICMA,0,Red);

}





//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+


void start()
{
//----
//---- calculate open orders by current symbol

//--- If there are no open trades, then simply open one...

if(Current_Trade(Symbol())=="NONE") OpenTrade(Symbol(),Current_Indication());

// But if there is an open trade we need to close it first before opening the new one.

if ((Current_Trade(Symbol())=="BUY") && (Current_Indication()=="SELL"));
{
CloseTrade(Symbol());
OpenTrade(Symbol(),Current_Indication());
}
if ((Current_Trade(Symbol())=="SELL") && (Current_Indication()=="BUY"));
{
CloseTrade(Symbol());
OpenTrade(Symbol(),Current_Indication());
}
return;

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop

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

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:17 PM.



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