| New signals service! | |
|
|||||||
| 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 |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
__________________
MQL4 programming is easy ^^ |
|
|||
|
hi
could any one please convert this simple expert advisor cross over to ,, smoothed one
many thanx //+------------------------------------------------------------------+ //| Rossman1.mq4 | //| Rossman | //| | //+------------------------------------------------------------------+ #property copyright "Rossman" //declare external variables to be used in start function extern int MAperiodSlow=10; extern int MAperiodFast=5; extern int stopLoss=150; extern int takeProfit=300; extern double lots=1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- //declare local variables to be used below //total is used to make sure no order is placed if an order is open //cnt stands for count and is used in the for loop that closes open orders int total, cnt; //maSlow and maFast are the 2 moving averages for the current bar in this EA //maSlowPrevious and maFastPrevious are are the 2 moving averages for the //previous bar. They are used to determine if the slow and fast moving averages have crossed double maSlow,maSlowPrevious,maFast,maFastPrevious; //I use simple moving average and the close price to calculate the moving average maSlow = iMA(NULL,0,MAperiodSlow,0,MODE_SMA,PRICE_CLOSE,0); maSlowPrevious = iMA(NULL,0,MAperiodSlow,0,MODE_SMA,PRICE_CLOSE,1); maFast = iMA(NULL,0,MAperiodFast,0,MODE_SMA,PRICE_CLOSE,0); maFastPrevious = iMA(NULL,0,MAperiodFast,0,MODE_SMA,PRICE_CLOSE,1); //OrdersTotal() returns the number of open orders total=OrdersTotal(); //for loop counts through the open orders. Order 1 is labeled 0 so we start with //cnt=0 and end with cnt<total not cnt<=total and we count up through the orders with cnt++ for(cnt=0;cnt<total;cnt++) { //select the order from open trades by the position which is the value of cnt OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); //if the order is a buy order (ie long position) if(OrderType() == OP_BUY) { //and if the fast moving average is less than the slow moving average if(maFast<maSlow) { //close the selected order OrderClose(OrderTicket(),OrderLots(),Bid,3,DarkGre en); return(0); } } //if not buy order, then it is a sell order (ie short position) else { //and if the fast moving average is greater than the slow moving average if(maFast>maSlow) { //close the selected order OrderClose(OrderTicket(),OrderLots(),Ask,3,Maroon) ; return(0); } } return(0); } //if the total number of open orders is less than one (ie there aren't any) if(total<1) { //and if the fast moving average is greater than the slow moving average and the fast moving average was less than //the slow moving average one unit of time ago (this means the fast moving average has crossed up through the slow moving average) if(maFast>maSlow && maFastPrevious<maSlowPrevious) { //make a buy order at the ask price for the number of lots in the external variable 'lots' with a stoploss equal to //the external variable 'stopLoss' and a limit equal to the external variable 'take profit' OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stopLoss*Point,Ask+takeProfit*Point,"Rossman1-buy",12055,0,Lime); return(0); } //or if the fast moving average is less than the slow moving average and the fast moving average was greater than //the slow moving average one unit of time ago (this means the fast moving average has crossed down through the slow moving average) if(maFast<maSlow && maFastPrevious>maSlowPrevious) { //make a sell order at the bid price for the number of lots in the external variable 'lots' with a stoploss equal to //the external variable 'stopLoss' and a limit equal to the external variable 'take profit' OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+stopLoss *Point,Bid-takeProfit*Point,"Rossman1-sell",12055,0,Red); return(0); } return(0); } //---- return(0); } //+------------------------------------------------------------------+ |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Expert Advisor Moving Average Cross GBP/USD time frame H1 | haba | Expert Advisors - Metatrader 4 | 1 | 03-10-2007 12:55 PM |
| Request for custom crossover expert | thn5625 | Expert Advisors - Metatrader 4 | 2 | 01-26-2007 06:22 PM |
| 50-34 Expert advisor | geisebhum | Suggestions for Trading Systems | 4 | 12-20-2006 05:45 PM |
| CCI Expert Advisor | rodrigokaus | Expert Advisors - Metatrader 4 | 10 | 09-29-2006 06:31 PM |