View Single Post
  #8 (permalink)  
Old 12-15-2006, 10:29 PM
Eaglehawk's Avatar
Eaglehawk Eaglehawk is offline
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
Reply With Quote