Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course
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
  #1 (permalink)  
Old 12-12-2006, 07:05 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Need help with simple EA problem - newbie

Hello Everyone!

I'm trying to hobble together an EA from a template program and am running into a few problems with the code and was hoping that someone could help (it's probably riduculously easy but I'm still lost).

The theory is simple:
- enter and go short if the RSI crosses up over 50
- enter and go long if the RSI crosses down 50

The exists are strictly based on TP and SL.

With this strategy, multiple open orders can accumulate. The problem is that the EA seems to only open a new order if the previous one has closed.

Can anyone please help and show me how the code needs to be modified to allow multiple open positions at the same time each time a new entry signal is given and exit only if a TP or SL has been reached.

Thanks in advance!



...first learning to crawl...then one day run...
Attached Files
File Type: mq4 RSI_Cross Market Orders.mq4 (4.7 KB, 22 views)

Last edited by mikep; 12-12-2006 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
  #2 (permalink)  
Old 12-13-2006, 03:27 AM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
PHP Code:
int numorder OrderSend(Symbol(), OP_BUYdLotsAsknSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenBuy); 
You're setting an OrderSend() function as an integer. Try changing to;

PHP Code:
   {
   
OrderSend(Symbol(), OP_BUYdLotsAsknSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenBuy); 
   } 
Should do the trick. It works on my computer.
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
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
  #3 (permalink)  
Old 12-13-2006, 06:28 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
thank you but still not working...

Eaglehawk,

Thanks for your input - it is appreciated!

I tried your recommendation but it didn't seem to fix it.
I've attached a 2 day sample backtest result as well as a screen shot to show what happened versus what should have happened. During the time frame it only executed 3 trades when it should have executed something like 30.

Do you or anyone else out there have any more ideas?

Attached Images
File Type: gif gbp rsi sample.gif (18.2 KB, 32 views)
Attached Files
File Type: htm StrategyTester.htm (5.4 KB, 14 views)
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
  #4 (permalink)  
Old 12-13-2006, 11:03 PM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
did you change the settings on both of the ordersend functions? (i found two).

on my tester it got much more than three orders.

hope this helps.
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
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
  #5 (permalink)  
Old 12-13-2006, 11:23 PM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
here are the results i've had.

notepad file has a number on the right, of the take profits and stop losses.
Attached Images
File Type: gif Rsi Tester.gif (7.3 KB, 21 views)
Attached Files
File Type: htm Rsi Tester.htm (131.2 KB, 11 views)
File Type: txt Rsi Take Profits and Stop Losses.txt (37.6 KB, 9 views)
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
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
  #6 (permalink)  
Old 12-14-2006, 12:34 AM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Yes I changed both order fuctions - one for the OP_Buy and the OP_Sell.

I took a quick snapshot of only two days on a 5min chart to show that with many crosses the only ones that are executed are those where previous open orders have closed.

I attached the "fixed" EA version based on your recommendations.

I took a look at your results and noticed that while you have a lot more orders it’s because of you the test dates. Also, the results still show that only one order is in play at one time.

….hmmmm…...this is bumming me out….
Attached Files
File Type: mq4 RSI_Cross Market Orders FIX.mq4 (4.7 KB, 11 views)
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
  #7 (permalink)  
Old 12-15-2006, 03:08 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Question almost there...hopefully...

Guys - I know there's quite a few senior and experienced programmers out there - please help - again, I believe this is probably a simple problem that would take 5 min for the "mistake" to be found by someone with the skillset which alot of you have.

I'll put the code here to make it easier for someone to review...

Thanks again to Eaglehawk for stepping up and trying to help.

PHP Code:

extern string sNameExpert 
"RSI Cross";
extern int nAccount =0;
extern double dBuyStopLossPoint 25;
extern double dSellStopLossPoint 25;
extern double dBuyTakeProfitPoint 50;
extern double dSellTakeProfitPoint 50;
extern double dBuyTrailingStopPoint 0;
extern double dSellTrailingStopPoint 0;
extern double dLots 1;
extern int nSlippage 3;
extern color colorOpenBuy Blue;
extern color colorCloseBuy Aqua;
extern color colorOpenSell Red;
extern color colorCloseSell Aqua;


void deinit() {
   
Comment("");
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){
   

double LongRSI=iRSI(Symbol(),Period(),14,PRICE_OPEN,2);
double ShortRSI=iRSI(Symbol(),Period(),14,PRICE_OPEN,1);



   if(
AccountFreeMargin() < (1000*dLots)){
      Print(
"We have no money. Free Margin = " AccountFreeMargin());
      return(
0);
   }
   
   
bool lFlagBuyOpen falselFlagSellOpen falselFlagBuyClose falselFlagSellClose false;
   
   
lFlagBuyOpen = (LongRSI>=50 && ShortRSI<50);
   
lFlagSellOpen = (LongRSI<=50 && ShortRSI>50);
   
lFlagBuyClose False;
   
lFlagSellClose False;
   
   if (!
ExistPositions()){

      if (
lFlagBuyOpen){
         
OpenBuy();
         return(
0);
      }

      if (
lFlagSellOpen){
         
OpenSell();
         return(
0);
      }
   }
   if (
ExistPositions()){
      if(
OrderType()==OP_BUY){
         if (
lFlagBuyClose){
            
bool flagCloseBuy OrderClose(OrderTicket(), OrderLots(), BidnSlippagecolorCloseBuy);  
            return(
0);
         }
      }
      if(
OrderType()==OP_SELL){
         if (
lFlagSellClose){
            
bool flagCloseSell OrderClose(OrderTicket(), OrderLots(), AsknSlippagecolorCloseSell);  
            return(
0);
         }
      }
   }
   
   if (
dBuyTrailingStopPoint || dSellTrailingStopPoint 0){
      
      for (
int i=0i<OrdersTotal(); i++) { 
         if (
OrderSelect(iSELECT_BY_POSMODE_TRADES)) { 
            
bool lMagic true;
            if (
MAGIC && OrderMagicNumber() != MAGIC)
               
lMagic false;
            
            if (
OrderSymbol()==Symbol() && lMagic) { 
               if (
OrderType()==OP_BUY && dBuyTrailingStopPoint 0) { 
                  if (
Bid-OrderOpenPrice() > dBuyTrailingStopPoint*Point) { 
                     if (
OrderStopLoss()<Bid-dBuyTrailingStopPoint*Point
                        
ModifyStopLoss(Bid-dBuyTrailingStopPoint*Point); 
                  } 
               } 
               if (
OrderType()==OP_SELL) { 
                  if (
OrderOpenPrice()-Ask>dSellTrailingStopPoint*Point) { 
                     if (
OrderStopLoss()>Ask+dSellTrailingStopPoint*Point || OrderStopLoss()==0)  
                        
ModifyStopLoss(Ask+dSellTrailingStopPoint*Point); 
                  } 
               } 
            } 
         } 
      } 
   }
   return (
0);
}

bool ExistPositions() {
    for (
int i=0i<OrdersTotal(); i++) {
        if (
OrderSelect(iSELECT_BY_POSMODE_TRADES)) {
         
bool lMagic true;
         
         if (
MAGIC && OrderMagicNumber() != MAGIC)
            
lMagic false;

            if (
OrderSymbol()==Symbol() && lMagic) {
                return(
True);
            }
        } 
    } 
    return(
false);
}

void ModifyStopLoss(double ldStopLoss) { 
   
bool lFlagModify OrderModify(OrderTicket(), OrderOpenPrice(), ldStopLossOrderTakeProfit(), 0CLR_NONE); 
 


void OpenBuy() { 
   
double dStopLoss 0dTakeProfit 0;

   if (
dBuyStopLossPoint 0)
      
dStopLoss Ask-dBuyStopLossPoint*Point;
   
   if (
dBuyTakeProfitPoint 0)
     
dTakeProfit Ask dBuyTakeProfitPoint Point
   
   
OrderSend(Symbol(), OP_BUYdLotsAsknSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenBuy); 
   



void OpenSell() { 
   
double dStopLoss 0dTakeProfit 0;
   
   if (
dSellStopLossPoint 0)
      
dStopLoss Bid+dSellStopLossPoint*Point;
   
   if (
dSellTakeProfitPoint 0)
      
dTakeProfit Bid-dSellTakeProfitPoint*Point;
   
   
OrderSend(Symbol(),OP_SELLdLotsBidnSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenSell); 
   
    

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
  #8 (permalink)  
Old 12-15-2006, 10:29 PM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Quote:
Originally Posted by mikep
Guys - I know there's quite a few senior and experienced programmers out there - please help - again, I believe this is probably a simple problem that would take 5 min for the "mistake" to be found by someone with the skillset which alot of you have.

I'll put the code here to make it easier for someone to review...

Thanks again to Eaglehawk for stepping up and trying to help.

PHP Code:

extern string sNameExpert 
"RSI Cross";
extern int nAccount =0;
extern double dBuyStopLossPoint 25;
extern double dSellStopLossPoint 25;
extern double dBuyTakeProfitPoint 50;
extern double dSellTakeProfitPoint 50;
extern double dBuyTrailingStopPoint 0;
extern double dSellTrailingStopPoint 0;
extern double dLots 1;
extern int nSlippage 3;
extern color colorOpenBuy Blue;
extern color colorCloseBuy Aqua;
extern color colorOpenSell Red;
extern color colorCloseSell Aqua;


void deinit() {
   
Comment("");
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){
   

double LongRSI=iRSI(Symbol(),Period(),14,PRICE_OPEN,2);
double ShortRSI=iRSI(Symbol(),Period(),14,PRICE_OPEN,1);



   if(
AccountFreeMargin() < (1000*dLots)){
      Print(
"We have no money. Free Margin = " AccountFreeMargin());
      return(
0);
   }
   
   
bool lFlagBuyOpen falselFlagSellOpen falselFlagBuyClose falselFlagSellClose false;
   
   
lFlagBuyOpen = (LongRSI>=50 && ShortRSI<50);
   
lFlagSellOpen = (LongRSI<=50 && ShortRSI>50);
   
lFlagBuyClose False;
   
lFlagSellClose False;
   
   if (!
ExistPositions()){

      if (
lFlagBuyOpen){
         
OpenBuy();
         return(
0);
      }

      if (
lFlagSellOpen){
         
OpenSell();
         return(
0);
      }
   }
   if (
ExistPositions()){
      if(
OrderType()==OP_BUY){
         if (
lFlagBuyClose){
            
bool flagCloseBuy OrderClose(OrderTicket(), OrderLots(), BidnSlippagecolorCloseBuy);  
            return(
0);
         }
      }
      if(
OrderType()==OP_SELL){
         if (
lFlagSellClose){
            
bool flagCloseSell OrderClose(OrderTicket(), OrderLots(), AsknSlippagecolorCloseSell);  
            return(
0);
         }
      }
   }
   
   if (
dBuyTrailingStopPoint || dSellTrailingStopPoint 0){
      
      for (
int i=0i<OrdersTotal(); i++) { 
         if (
OrderSelect(iSELECT_BY_POSMODE_TRADES)) { 
            
bool lMagic true;
            if (
MAGIC && OrderMagicNumber() != MAGIC)
               
lMagic false;
            
            if (
OrderSymbol()==Symbol() && lMagic) { 
               if (
OrderType()==OP_BUY && dBuyTrailingStopPoint 0) { 
                  if (
Bid-OrderOpenPrice() > dBuyTrailingStopPoint*Point) { 
                     if (
OrderStopLoss()<Bid-dBuyTrailingStopPoint*Point
                        
ModifyStopLoss(Bid-dBuyTrailingStopPoint*Point); 
                  } 
               } 
               if (
OrderType()==OP_SELL) { 
                  if (
OrderOpenPrice()-Ask>dSellTrailingStopPoint*Point) { 
                     if (
OrderStopLoss()>Ask+dSellTrailingStopPoint*Point || OrderStopLoss()==0)  
                        
ModifyStopLoss(Ask+dSellTrailingStopPoint*Point); 
                  } 
               } 
            } 
         } 
      } 
   }
   return (
0);
}

bool ExistPositions() {
    for (
int i=0i<OrdersTotal(); i++) {
        if (
OrderSelect(iSELECT_BY_POSMODE_TRADES)) {
         
bool lMagic true;
         
         if (
MAGIC && OrderMagicNumber() != MAGIC)
            
lMagic false;

            if (
OrderSymbol()==Symbol() && lMagic) {
                return(
True);
            }
        } 
    } 
    return(
false);
}

void ModifyStopLoss(double ldStopLoss) { 
   
bool lFlagModify OrderModify(OrderTicket(), OrderOpenPrice(), ldStopLossOrderTakeProfit(), 0CLR_NONE); 
 


void OpenBuy() { 
   
double dStopLoss 0dTakeProfit 0;

   if (
dBuyStopLossPoint 0)
      
dStopLoss Ask-dBuyStopLossPoint*Point;
   
   if (
dBuyTakeProfitPoint 0)
     
dTakeProfit Ask dBuyTakeProfitPoint Point
   
   
OrderSend(Symbol(), OP_BUYdLotsAsknSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenBuy); 
   



void OpenSell() { 
   
double dStopLoss 0dTakeProfit 0;
   
   if (
dSellStopLossPoint 0)
      
dStopLoss Bid+dSellStopLossPoint*Point;
   
   if (
dSellTakeProfitPoint 0)
      
dTakeProfit Bid-dSellTakeProfitPoint*Point;
   
   
OrderSend(Symbol(),OP_SELLdLotsBidnSlippagedStopLossdTakeProfitsNameExpertMAGIC0colorOpenSell); 
   
    

perhaps turning your slippage to "0" or "1" might help a little?
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Are there any simple yet Profitable systems for a beginner/newbie??? blaze_survey General Discussion 5 10-09-2006 11:22 PM
Help!! simple color change indicator problem.. drgoodvibe Questions 3 07-16-2006 06:42 AM


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



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