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
  #2011 (permalink)  
Old 08-29-2009, 11:19 AM
Snowski's Avatar
Member
 
Join Date: May 2009
Posts: 67
Snowski is on a distinguished road
Dear all,

I have a simple question, I think.

I have an indicator that notifies me with a pop-up (alert) and I wanted to add a custom sound (other than the standard alert.wav).

I have noticed that once the event happens and the alert appears, no matter what "custom" sound I programmed in the indicator, Metatrader 4 will ALWAYS play the sound I have assigned for alert (default this is alert.wav, see the MT4 menu Tools>Options>Events).

Is it possible to program the indicator in such a manner that I both get a visual alert AND a custom assigned audible alert...?

Many thanks in advance..!
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
  #2012 (permalink)  
Old 08-30-2009, 12:28 AM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
Actually, you can take any sound and call it alert.wav and replace the original file.
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
  #2013 (permalink)  
Old 08-30-2009, 04:40 PM
Junior Member
 
Join Date: Jul 2009
Location: Indonesia
Posts: 5
V-Force is on a distinguished road
Changing custom Alert

Quote:
Originally Posted by Snowski View Post
Dear all,

I have a simple question, I think.

I have an indicator that notifies me with a pop-up (alert) and I wanted to add a custom sound (other than the standard alert.wav).

I have noticed that once the event happens and the alert appears, no matter what "custom" sound I programmed in the indicator, Metatrader 4 will ALWAYS play the sound I have assigned for alert (default this is alert.wav, see the MT4 menu Tools>Options>Events).

Is it possible to program the indicator in such a manner that I both get a visual alert AND a custom assigned audible alert...?

Many thanks in advance..!


Hello Snowski,

Try............

if (alert_ON == true) // to turn on or turn off sound alert
{
Alert ("Key in you custom PopUp Here",Symbol(),"-",TimeFrame);
PlaySound("custom.wav");
}

I am not so good at coding but you can try this as it should work. the custom .wav, you can enter your own file name into the ("??????.wav")

if you want to be able to set alert on and off, you need to also add

extern bool alert_ON = True; // or false at the beginning of your indicator code
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
  #2014 (permalink)  
Old 08-31-2009, 06:28 AM
Junior Member
 
Join Date: Jun 2009
Posts: 12
asgard2 is on a distinguished road
History function

Hi,

I have this code below. I am trying to implement a delay between my buystop orders in the event they were deleted. I have never used the history function before.

I am unable to compile it because of an unbalanced parentheses error, can anyone tell me why these are unbalanced?

Also, can anyone tell me if I am on the right track or if I should be looking at another way to do this?


Code:
         if ((type == _OP_BUYSTOP) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))//Time Delay for the next Buy Stop Order
         
          int hstTotal=OrdersHistoryTotal();
            for(i=0;i<hstTotal;i++)
               {                             
                if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
                                             Print("Access to history failed (",GetLastError(),")"); break;
                  {
                    if (OrderDelete() && (((TimeCurrent() - OrderCloseTime())/60) =< NextBuyStop_Order_Minutes) MayOpenDeferOrder = false; 
                   
                  }
               }
Thanks
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
  #2015 (permalink)  
Old 08-31-2009, 07:02 AM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 722
Kalenzo is on a distinguished road
Quote:
Originally Posted by asgard2 View Post
Hi,

I am unable to compile it because of an unbalanced parentheses error, can anyone tell me why these are unbalanced?


Thanks
If you are getting this error then you are missing one of [ or { or (
probably somewhere in your code there is a function where you put too much of the {[(

I checked part of your code and found some errors. Try this :
Code:
  if ((type == _OP_BUYSTOP) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))//Time Delay for the next Buy Stop Order
{        
   int hstTotal=OrdersHistoryTotal();
   for(i=0;i<hstTotal;i++)
   {                             
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false)
      {
         Print("Access to history failed ("+GetLastError()+")"); 
         break;
      }                                             
      else                  
      {
         if (OrderDelete() && (((TimeCurrent() - OrderCloseTime())/60) =< NextBuyStop_Order_Minutes) MayOpenDeferOrder = false; 
      }
}
Also i think last part of your code (OrderDelete) will not work, because OrderDelete functons does not check anything - it is deleting selected order. So you need to pass parameter with order ticket to it. Instead of this you can recognize deleted orders by checking theirs comments. Each deleted order will have "canceled" in it comment - you can compare result of OrderComment() function to find this.
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
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
  #2016 (permalink)  
Old 08-31-2009, 10:18 AM
Junior Member
 
Join Date: Aug 2009
Posts: 2
ForExTryo is on a distinguished road
Question Can Someone Help Me?

Hello,

I am trying to write an EA, and I need some help writing a formula.
I want the formula to calculate the different between the previous candle close (PCC1) and the close of the candle two candles back (PCC2) (I will be running this on multiple pairs). HoL=(PCC1-PCC2)

My goal is to signal a buy or sell;
bool BuySignal=false;
bool SellSignal=false;

if(HoL>0) BuySignal=true;
if(HoL<0) SellSignal=true;


Thank you for your help with this.
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
  #2017 (permalink)  
Old 08-31-2009, 11:00 AM
mladen's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,270
mladen is on a distinguished road
...

If you want to use multiple symbols from one instance of EA that you can use something like this :
PHP Code:
double HoL=iClose(symbolName,0,1)-iClose(symbolName,0,2); 
Or to prevent some back testing surprises, a slightly more complicated code
PHP Code:
int    symbolShift1 iBarShift(symbolName,0,Time[1]);
int    symbolShift2 iBarShift(symbolName,0,Time[2]);
double HoL iClose(symbolName,0,symbolShift1)-iClose(symbolName,0,symbolShift2); 
If you are going to use it only on symbol that your EA is attached to than this
PHP Code:
double HoL=Close[1]-Close[2]; 
is enough

PS: "symbolName" should be set to Symbol of your choice.

regards
mladen

Quote:
Originally Posted by ForExTryo View Post
Hello,

I am trying to write an EA, and I need some help writing a formula.
I want the formula to calculate the different between the previous candle close (PCC1) and the close of the candle two candles back (PCC2) (I will be running this on multiple pairs). HoL=(PCC1-PCC2)

My goal is to signal a buy or sell;
bool BuySignal=false;
bool SellSignal=false;

if(HoL>0) BuySignal=true;
if(HoL<0) SellSignal=true;


Thank you for your help with this.

Last edited by mladen; 08-31-2009 at 11:06 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
  #2018 (permalink)  
Old 08-31-2009, 03:32 PM
Junior Member
 
Join Date: Jun 2008
Posts: 10
sparow21 is on a distinguished road
Smile Help needed to hide the TP.

Quote:
Originally Posted by Slakerz View Post
Hi guys, i've been trying to figure out how to put a StopLoss.. my EA is as below,

//+------------------------------------------------------------------+
//| CHinGs73MAroon73CLK200_v2.6 |
//| Copyright © Dec_2007, CHinGsMAroonCLK |
//| chingsmaroonclk@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, CHinGsMAroonCLK."
#property link "http://chings73forex.blogspot.com/"

extern int MinGS=17;
extern int TP=19;
extern int StopLoss=15;
extern double lot=0.10;
extern int MaxTrades=9;
extern int RegularSpread=3;
extern double Multiplier=2;
extern double LotInc=0;
extern double MarginLevelAlert=1000;

int magic;
double lot2;
datetime tob,tos,toe; //Time Out Buy & Sell & email


//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----



//----
return(0);
}

int init()
{
if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") { magic = 211001; }
if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") { magic = 211002; }
if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") { magic = 211003; }
if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") { magic = 211004; }
if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") { magic = 211005; }
if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") { magic = 211006; }
if (Symbol() == "EURCADm" || Symbol() == "EURCAD") { magic = 211007; }
if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") { magic = 211008; }
if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") { magic = 211009; }
if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") { magic = 211010; }
if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") { magic = 211011; }
if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") { magic = 211012; }
if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") { magic = 211013; }
if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") { magic = 211014; }
if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") { magic = 211015; }
if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") { magic = 211016; }
if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") { magic = 211017; }
if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") { magic = 211018; }
if (Symbol() == "USDCADm" || Symbol() == "USDCAD") { magic = 211019; }
if (magic == 0) { magic = 211999; }
return (0);
return(0);
}

void OpenBuy()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,1,0,Ask+TP*Poin t,"Ask-StopLoss*Point,EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}

void OpenSell()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,1,0,Bid-TP*Point,Bid+StopLoss*Point,"EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}


void ManageBuy()
{
int lasttradetime = 0;
double lastopenprice=0;
double maxlots = 0;
double lasttp=0;
int lastordertype=-1;
int lastorderticket=0;
int y=0;

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY)) { continue; }
if (OrderOpenTime() > lasttradetime) {
lasttradetime = OrderOpenTime();
lastopenprice = OrderOpenPrice();
lastordertype=OrderType();
lastorderticket=OrderTicket();
lasttp=OrderTakeProfit();
}
if (OrderLots() > maxlots) { maxlots = OrderLots(); }
}

int lvl=MathRound(MathLog((maxlots-LotInc)/lot)/MathLog(Multiplier)+1);

Print(lvl);

if (lvl<0) lvl=0;

lot2=lot*MathPow(Multiplier,lvl)+LotInc;

if ((lvl==0) && (((Ask-Bid)/Point)<=RegularSpread)) OpenBuy();

if ((lastopenprice-Ask>MinGS*Point) && (lvl<MaxTrades) && (((Ask-Bid)/Point)<=RegularSpread)) {
OpenBuy();
return(0);
}

/////////// TP
/*
double sumlots=0;
double sump=0;
double avgp=0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY)) { continue; }
sumlots=sumlots+OrderLots();
sump=OrderOpenPrice()*OrderLots()+sump;
}

if (sumlots>0) {
avgp=NormalizeDouble(sump/sumlots,Digits);
double tpp=NormalizeDouble(TP/10/sumlots*Point+avgp,Digits);

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY) || (OrderTakeProfit()==tpp)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderSt opLoss(),tpp,0,Red);
}


}
*/

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY) || (OrderTakeProfit()==lasttp) || (lasttp==0)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderSt opLoss(),lasttp,0,Red);
}


}

void ManageSell()
{
int lasttradetime = 0;
double lastopenprice=0;
double maxlots = 0;
double lasttp=0;
int lastordertype=-1;
int lastorderticket=0;
int y=0;

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL)) { continue; }
if (OrderOpenTime() > lasttradetime) {
lasttradetime = OrderOpenTime();
lastopenprice = OrderOpenPrice();
lastordertype=OrderType();
lastorderticket=OrderTicket();
lasttp=OrderTakeProfit();
}
if (OrderLots() > maxlots) { maxlots = OrderLots(); }
}

int lvl=MathRound(MathLog((maxlots-LotInc)/lot)/MathLog(Multiplier)+1);

if (lvl<0) lvl=0;

lot2=lot*MathPow(Multiplier,lvl)+LotInc;

if ((lvl==0) && (((Ask-Bid)/Point)<=RegularSpread)) OpenSell();

if ((Bid-lastopenprice>MinGS*Point) && (lastopenprice>0) && (lvl<MaxTrades) && (((Ask-Bid)/Point)<=RegularSpread)) {
OpenSell();
return(0);
}

/////////// TP
/* double sumlots=0;
double sump=0;
double avgp=0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL)) { continue; }
sumlots=sumlots+OrderLots();
sump=OrderOpenPrice()*OrderLots()+sump;
}

if (sumlots>0) {
avgp=NormalizeDouble(sump/sumlots,Digits);
double tpp=NormalizeDouble(-TP/10/sumlots*Point+avgp,Digits);

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL) || (OrderTakeProfit()==tpp)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderSt opLoss(),tpp,0,Red);
}


}
*/

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL) || (OrderTakeProfit()==lasttp) || (lasttp==0)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderSt opLoss(),lasttp,0,Red);
}


}

void CheckMargin()
{
if (AccountMargin()!=0) {
if (((AccountEquity()/AccountMargin()*100)<MarginLevelAlert) && (TimeCurrent()>toe+3600)) {
SendMail("Account Margin Warning","Account Free Margin is "+AccountFreeMargin());
toe=TimeCurrent();
}
}
}




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

ManageBuy();

ManageSell();

CheckMargin();

//----
return(0);
}
//+------------------------------------------------------------------+

Thanx so much...
Hallo everyone,
I would be very gratefull if anybody can help me to hide the TP for this EA.
Thank you.
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
  #2019 (permalink)  
Old 08-31-2009, 04:43 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
Hide TP

Replace
Code:
void OpenBuy()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,1,0,Ask+TP*Poin t,"Ask-StopLoss*Point,EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}

void OpenSell()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,1,0,Bid-TP*Point,Bid+StopLoss*Point,"EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}
to

Code:
void OpenBuy()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,1,0,0,"Ask-StopLoss*Point,EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}

void OpenSell()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,1,0,0,"EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}
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
  #2020 (permalink)  
Old 09-01-2009, 01:06 AM
Junior Member
 
Join Date: Jun 2009
Posts: 12
asgard2 is on a distinguished road
Distance between Buy Stop orders

Hi Everyone, I am trying to implement a distance between a deleted buy stop order and the next buystop order.

I have written this code which works unless the last order is something else. I am not sure how to select a deleted buystop order from the history. If someone could point me in the right direction I would really appreciated it.

thanks



// Time Delay for the next "Buy Stop" Order is deleted.


Code:
//Time Delay for the next Buy Stop Order
   if ((type == _OP_BUY) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))
         
          {
         total = OrdersHistoryTotal();

            for(e = total - 1; e >= 0; e--)
               {
               OrderSelect(e, SELECT_BY_POS,MODE_HISTORY);
         
            if(OrderSymbol() != Symbol())  continue;   
               {
               if(((TimeCurrent() - OrderOpenTime())/60) < NextBuyStop_Order_Minutes) MayOpenDeferOrder = false; 
               
         }
      }
   }
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: 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
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 03:28 PM.



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