Forex



Go Back   Forex Trading > Programming > MetaTrader
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
  #1101 (permalink)  
Old 07-25-2008, 03:47 PM
Member
 
Join Date: Sep 2007
Posts: 69
Ronald Raygun is on a distinguished road
OrderComment()
OrderTicket()
OrderLots()
OrderStopLoss()
OrderTakeProfit()
OrderOpenTime()

Those are all potential order-filtering tools.

What else about those specific trades makes them unique?
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
  #1102 (permalink)  
Old 07-25-2008, 09:51 PM
Member
 
Join Date: Jan 2006
Posts: 59
hiachiever is on a distinguished road
Quote:
Originally Posted by Ronald Raygun View Post
OrderComment()
OrderTicket()
OrderLots()
OrderStopLoss()
OrderTakeProfit()
OrderOpenTime()

Those are all potential order-filtering tools.

What else about those specific trades makes them unique?
Two of the most important for filtering orders are OrderSymbol() and OrderMagicNumber(). Another of note is OrderComment().

The best idea is to enter one of these into the Metaeditor, then click on the word asnd then press F1. Doing so will display the help and list all of the order functions.

Happy programming,
Hiachiever
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
  #1103 (permalink)  
Old 07-25-2008, 10:43 PM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 560
MrPip is on a distinguished road
Using OrderComment

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
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
  #1104 (permalink)  
Old 07-26-2008, 06:02 AM
Senior Member
 
Join Date: Feb 2007
Posts: 986
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
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
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
  #1105 (permalink)  
Old 07-27-2008, 09:20 AM
Junior Member
 
Join Date: Apr 2008
Posts: 4
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1106 (permalink)  
Old 07-27-2008, 09:36 PM
Member
 
Join Date: May 2008
Posts: 57
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1107 (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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1108 (permalink)  
Old 07-30-2008, 07:24 PM
Junior Member
 
Join Date: Jun 2008
Posts: 5
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1109 (permalink)  
Old 07-31-2008, 05:14 AM
Senior Member
 
Join Date: Feb 2007
Posts: 986
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
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
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
  #1110 (permalink)  
Old 07-31-2008, 04:17 PM
Junior Member
 
Join Date: Jun 2008
Posts: 5
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!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


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
buff_0
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 05:17 AM.



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