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 (1) Thread Tools Display Modes
  #1101 (permalink)  
Old 07-26-2008, 06:02 AM
Senior Member
 
Join Date: Feb 2007
Posts: 947
FerruFx is on a distinguished road
Quote:
Originally Posted by MrPip View Post
Be careful when using OrderComment() to identify trades. Sometimes the broker will add characters to the comment.

It is best to use

if (StringFind(OrderComment(), UserComment, 0) > 0)
{
// order identified by UserComment found in OrderComment
}


instead of

if (OrderComment() == UserComment)
{
// order might be identified by UserComment
// if OrderComment was not changed by broker
}

Robert
Exactly ... And also, sometimes the original comment coded in the EA is too long and will be troncated by the platform (not sure if the rest of the comment is in the "memory" but it is not display in comment column).

FerruFx
__________________
THE HEART of FOREX & THE PROBABILITY METER - Trade with 100% confidence and ... Stress Less!!!
Coding services: Experts Advisors, indicators, alerts, etc ... more info by PM
NEW: video presentation of the Probability Meter ... 24hrs action on the website
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1102 (permalink)  
Old 07-27-2008, 09:20 AM
Junior Member
 
Join Date: Apr 2008
Posts: 1
pete_36 is on a distinguished road
need help with my EA

hi,

i am working on an EA that opens long and short positions simultaneously and i am facing this problem...when both type of positions are open, say first one is short and second is long...the EA will not close the long position if the short is still open, it will wait for the short to be closed and then close the long when conditions are met and vice versa. herebelow is the part of the EA where it should close the open positions:

//---- Close Open Positions

for(int cnt=0; cnt<total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
{
//-- Close Long
if(OrderSymbol() == Symbol() && OrderType()==OP_BUY && rsi1>75 && rsi<75)
{
OrderClose(OrderTicket(),OrderLots(),Bid,5,Green);
LotL=Lot;
}

//-- Close Short
if(OrderSymbol() == Symbol() && OrderType()==OP_SELL && rsi1<25 && rsi>25)
{
OrderClose(OrderTicket(),OrderLots(),Ask,5,Red);
LotS=Lot;
}
}
}

*where rsi1 is the previous rsi and rsi is the current reading
*LotL & LotS is a multiplier of the original Lot, i have set it to open a maximum of 3 positions each side, so when closing one type of open positions, LotL & LotS will be reset to the original size

the EA is working as intended when opening positions but the problem is with closing open positions, i think the EA in the loop part is not reading all of the open positions but only the first one... any help fixing this is really appreciated!!

cheers!
pete
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1103 (permalink)  
Old 07-27-2008, 09:36 PM
Member
 
Join Date: May 2008
Posts: 54
fireslayer26 is on a distinguished road
I'm trying to add the "Pips to activate Trailing stop" feature. What I changed is in red. What else needs to be added?

Code:
extern string Remark1 = "== Main Settings ==";
extern int MagicNumber = 54321;
extern bool SignalMail = False;
extern bool EachTickMode = true;
extern double Lots = 4;
extern int Slippage = 2;
extern  bool UseStopLoss = false;
extern int StopLoss = 100;
extern bool UseTakeProfit = false;
extern int TakeProfit = 15;
extern bool UseTrailingStop = true;
extern int TrailingStop = 45;
extern double    Pips_Activate_TS = 5;
extern bool MoveStopOnce = False;
extern int MoveStopWhenPrice = 50;
extern int MoveStopTo = 1;
extern int MaxConcurrentTrades = 2;


//Version 2.01

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;

   if (EachTickMode) Current = 0; else Current = 1;

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


{
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;



   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+


   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+


  

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
                  if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
                  if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
      if(Open[0] > Open[0+1] &&
         Open[0+1] >= Open[0+2] &&
         Open[0+2]>= Open[0+3] &&
         Open[0+3] >= Open[0+4] &&
         Open[0+4] >= Open[0+5] &&
         Open[0+5] >= Open[0+6]) Order = SIGNAL_SELL;
         
             if(Open[0] < Open[0+1] &&
         Open[0+1] <= Open[0+2] &&
         Open[0+2]<= Open[0+3] &&
         Open[0+3] <= Open[0+4] &&
         Open[0+4] <= Open[0+5] &&
         Open[0+5] <= Open[0+6]) Order = SIGNAL_BUY;  


   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(DecideToOpenTrade(OP_BUY) && TradeSlotsAvailable()) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
			} else {
				Print("Error opening BUY order : ", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(DecideToOpenTrade(OP_SELL) && TradeSlotsAvailable()) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
			} else {
				Print("Error opening SELL order : ", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1104 (permalink)  
Old 07-30-2008, 04:40 PM
Junior Member
 
Join Date: Feb 2008
Posts: 3
mifiglo is on a distinguished road
Unhappy Urgent : Need Help Developing an Expert Advisor for Custom Indicator

Hello fellow traders,
I have this little problem developing an Expert Advisor from a Custom indicator , I've tried the "iCustom" function but my indicator always returns the same value.
It returns something like 21473..., like that
I want the EA to be able to recognise when the sell and buy arrow signals are generated and it should perform the corresponding trade action (i.e. buy when the indicator says up and sell when it says down)
Here is the code of the indicator I would so much appreciate it if someone can come up with a solution ASAP.

################################################## ##################
--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| Zeus.mq4 |
//| Copyright © 2008, Sola Ajayi, Nerdymonk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Sola Ajayi, Nerdymonk"



#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_color2 Lime
#property indicator_width2 2


extern int SignalGap = 4;
//indicator buffers
int dist=24;
double b1[];
double b2[];
bool test= false;
bool test2 = false;


int init() {
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);
SetIndexArrow(1,233);
SetIndexArrow(0,234);
SetIndexBuffer(0,b1);
SetIndexBuffer(1,b2);
//---- name for DataWindow
SetIndexLabel(0,"Zeus Says Down");
SetIndexLabel(1,"Zeus Says Up");
//---- initialization done
return(0);
}
int start() {
int counted_bars=IndicatorCounted();
int nCountedBars=IndicatorCounted();
int i,limit,hhb,llb,l;
if(nCountedBars<0 || Bars<5) return(-1);
l=Bars-nCountedBars-1;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-1;
if(counted_bars>=1) limit=Bars-counted_bars-1;
if (limit<0) limit=0;
//Print ("Limit =", limit);
while(l>=0)
{
if(High[l+3]>High[l+4] && High[l+3]>High[l+5] && High[l+3]>High[l+2] && High[l+3]>High[l+1])
{
test = true;
}
if(Low[l+3]<Low[l+4] && Low[l+3]<Low[l+5] && Low[l+3]<Low[l+2] && Low[l+3]<Low[l+1])
{
test2 = true;
}
l--;
}

for (i=limit;i>=0;i--) {
hhb = iHighest(NULL,0,MODE_HIGH,dist,i-dist/2);
llb = iLowest(NULL,0,MODE_LOW,dist,i-dist/2);
if (i==hhb && test == true)
//sell arrow
b1[i]=High[hhb]+SignalGap*Point;
if (i==llb && test2 == true)
//buy arrow
b2[i]=Low[llb]-SignalGap*Point;
}
//----
return(0);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1105 (permalink)  
Old 07-30-2008, 07:24 PM
Junior Member
 
Join Date: Jun 2008
Posts: 3
masternico is on a distinguished road
winwin

hey guys,
eeeeeee ccccht

Last edited by masternico; 08-26-2008 at 11:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1106 (permalink)  
Old 07-31-2008, 05:14 AM
Senior Member
 
Join Date: Feb 2007
Posts: 947
FerruFx is on a distinguished road
Quote:
Originally Posted by mifiglo View Post
Hello fellow traders,
I have this little problem developing an Expert Advisor from a Custom indicator , I've tried the "iCustom" function but my indicator always returns the same value.
It returns something like 21473..., like that
I want the EA to be able to recognise when the sell and buy arrow signals are generated and it should perform the corresponding trade action (i.e. buy when the indicator says up and sell when it says down)
Here is the code of the indicator I would so much appreciate it if someone can come up with a solution ASAP.
Please post also the code lines with your iCustom() function

FerruFx
__________________
THE HEART of FOREX & THE PROBABILITY METER - Trade with 100% confidence and ... Stress Less!!!
Coding services: Experts Advisors, indicators, alerts, etc ... more info by PM
NEW: video presentation of the Probability Meter ... 24hrs action on the website
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1107 (permalink)  
Old 07-31-2008, 04:17 PM
Junior Member
 
Join Date: Jun 2008
Posts: 3
masternico is on a distinguished road
sorry, this is al i've got...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1108 (permalink)  
Old 07-31-2008, 10:41 PM
Junior Member
 
Join Date: Feb 2008
Posts: 3
mifiglo is on a distinguished road
Yeah thanks for offering to help

Quote:
Originally Posted by FerruFx View Post
Please post also the code lines with your iCustom() function

FerruFx
Yeah thanks for offering to help, i have fixed the problem already, it was a problem with my indicator.
However i noticed that my EA doesn't trade according to the Buy or Sell Arrows, here's my EA code.
Thanks in advance for your prompt reply,
//+------------------------------------------------------------------+
//| Anubis.mq4 |
//| Copyright © 2008, Sola Ajayi, NerdyMonk |
//| shollylabor@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Sola Ajayi, NerdyMonk"
#property link "shollylabor@gmail.com"

extern double TakeProfit = 500;
extern double Lots = 1;
extern double TrailingStop = 200;

double SS_SELL_0=0, SS_BUY_0=0;
bool SSIsBuy=false, SSIsSell=false;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int cnt,ticket,total;

SS_SELL_0 = iCustom(Symbol(),Period(),"zeus",4,0,0);
SS_BUY_0 = iCustom(Symbol(),Period(),"zeus",4,1,0);

if (SS_SELL_0 > 0) {SSIsSell=true;SSIsBuy=false;}
if (SS_BUY_0 > 0) {SSIsSell=false;SSIsBuy=true;}

if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if(SSIsBuy == true)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point,"zeus",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(SSIsSell == true)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"zeus",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(SSIsSell == true)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(SSIsBuy == true)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1109 (permalink)  
Old 07-31-2008, 11:53 PM
willmalou's Avatar
Member
 
Join Date: Apr 2006
Posts: 36
willmalou is on a distinguished road
Rsi Ea

This is my firs EA. It uses 2 rsi's crossing in 3 time frames. I have a problem with the ea taking trades against the crosses. Buying when it is supposed to sell, sell when suppose to buy. Could someone please look at the code and tell me where I went wrong. I haven't been able to see anything wrong.


I have attached the ea and a pic of the problem.
Attached Images
File Type: gif rsi wrong entry.gif (59.3 KB, 86 views)
Attached Files
File Type: mq4 RSI_Test.mq4 (10.9 KB, 7 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1110 (permalink)  
Old 08-01-2008, 01:51 AM
Junior Member
 
Join Date: Jul 2008
Posts: 2
BigA is on a distinguished road
Need help for EA code!

Hi all,


As you know the fx market is 24 hours, I am not comfortable to trade overnight without sitting in front of PC. So I am thinking the best way is program to protect the trade if the price moves towards my favorite direction. For example, if I opened 5 lots in total, when the profit is above 50 pips, it automatically move stop loss to break even. When the profit is above 100 pips, it moves to protect 30 pips.When the profit is above 200 pips, it moves to protect 50 pips. and so on.

I tried to code my self. But it doesn't work when I drag it into my chart and set it trading live. Any body could help me to have a look of my code and fix it? Many thanks.


#property copyright "x li"
#property link ""
#property show_confirm

//---- input parameters
extern int target1 =50;
extern int target2 =100;
extern int target3 =150;
extern int target4 =200;
extern int target5 =300;

extern int protect1 =0;
extern int protect2 =5;
extern int protect3 =50;
extern int protect4 =100;



//+-----------------------------------------------------------------------------+
//| script "move stoploss to protect(50->0;100->5;150->50;200->50;300->100)" |
//+-----------------------------------------------------------------------------+

int start()
{
bool result;
double stop_loss,point,EntryPrice,profit;
int cmd,total,error,i;
//----
total=OrdersTotal();
point=MarketInfo(Symbol(),MODE_POINT);
//----
for(i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
EntryPrice=OrderOpenPrice();

//---- buy orders are considered
if(cmd==OP_BUY)
{
profit=Bid-EntryPrice;

if(profit>target1*point && profit<target2*point)
{
stop_loss=EntryPrice+protect1*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target2*point && profit<target3*point)
{
stop_loss=EntryPrice+protect2*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target3*point && profit<target4*point)
{
stop_loss=EntryPrice+protect3*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target4*point && profit<target5*point)
{
stop_loss=EntryPrice+protect3*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target5*point)
{
stop_loss=EntryPrice+protect4*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
}
//---- sell orders are considered
if(cmd==OP_SELL)
{
profit=EntryPrice-Ask;

if(profit>target1*point && profit<target2*point)
{
stop_loss=EntryPrice-protect1*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target2*point && profit<target3*point)
{
stop_loss=EntryPrice-protect2*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target3*point && profit<target4*point)
{
stop_loss=EntryPrice-protect3*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target4*point && profit<target5*point)
{
stop_loss=EntryPrice-protect3*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
if(profit>target5*point)
{
stop_loss=EntryPrice-protect4*point;
result=OrderModify(OrderTicket(),0,stop_loss,0,0,C LR_NONE);
}
}
}
else { Print( "Error when order select ", GetLastError()); break; }
}
//----
return(0);
}
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

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 09:39 AM.



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