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
  #1091 (permalink)  
Old 07-23-2008, 10:05 PM
CodeMuncher's Avatar
Junior Member
 
Join Date: Jul 2008
Posts: 2
CodeMuncher is on a distinguished road
Hi.

I am looking forward to learning your tricks and showing you mine.
__________________
If you code it, they will come
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1092 (permalink)  
Old 07-24-2008, 03:29 AM
Senior Member
 
Join Date: Feb 2007
Posts: 947
FerruFx is on a distinguished road
Quote:
Originally Posted by CodeMuncher View Post
Hi.

I am looking forward to learning your tricks and showing you mine.
You'll find a lot of great stuff on this forum.

Read and use the search feature without any restriction!!!

Feel free to ask anything ... A lot of great contributors/helpers here.

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
  #1093 (permalink)  
Old 07-24-2008, 12:01 PM
Member
 
Join Date: Sep 2007
Posts: 68
Ronald Raygun is on a distinguished road
Quote:
Originally Posted by fireslayer26 View Post
In this code, it has the trailing stop set for 45 pips. But the trailing stop doesnt seem to Activate until it moves 45 pips. How would I need to change it to have the trailing stop activated when the trade is placed?

Code:
extern string Remark1 = "== Main Settings ==";
extern int MagicNumber = 0;
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 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 - OrderStopLoss() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

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


            //+------------------------------------------------------------------+
            //| 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(((OrderStopLoss - Ask) > (Point * TrailingStop)) || OrderStopLoss() == 0) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }


Changed in Red
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1094 (permalink)  
Old 07-24-2008, 04:12 PM
Member
 
Join Date: May 2008
Posts: 54
fireslayer26 is on a distinguished road
I made the changes in red, but now the EA doesnt seem to want to work. I'll post the whole EA for you to take a look at. Thanks!
Attached Files
File Type: mq4 Williams_EA.mq4 (11.6 KB, 12 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1095 (permalink)  
Old 07-24-2008, 04:15 PM
Member
 
Join Date: Sep 2007
Posts: 68
Ronald Raygun is on a distinguished road
Make sure you put () after orderstoploss
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1096 (permalink)  
Old 07-24-2008, 04:24 PM
Member
 
Join Date: May 2008
Posts: 54
fireslayer26 is on a distinguished road
Cool, that did it!

How about this indicator....

Could it be modified to have the prices show different colors depending on how they open? Like if it opens higher than the previous bar the price would be green, if lower, then red, and if even then yellow? With these colors being selectable? Also, could you extend it to show 10 openings instead of just 6?


Also on the EA we just fixed, How would I put an input setting like, "Pips to Activate Trailing Stop". I have this in another EA but unsure how to code it.
Attached Files
File Type: mq4 PERIOD_OPEN.mq4 (22.2 KB, 7 views)

Last edited by fireslayer26; 07-24-2008 at 04:28 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1097 (permalink)  
Old 07-25-2008, 01:22 AM
MiniMe's Avatar
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,297
MiniMe is on a distinguished road
Close trades at beakeven

..............
__________________
x.x.x.x.x. $$$ x.x.x.x.x.

Last edited by MiniMe; 07-26-2008 at 01:31 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1098 (permalink)  
Old 07-25-2008, 03:47 PM
Member
 
Join Date: Sep 2007
Posts: 68
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!
Reply With Quote
  #1099 (permalink)  
Old 07-25-2008, 09:51 PM
Member
 
Join Date: Jan 2006
Posts: 56
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!
Reply With Quote
  #1100 (permalink)  
Old 07-25-2008, 10:43 PM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 556
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!
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 12:14 PM.



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