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
  #561 (permalink)  
Old 12-13-2007, 12:15 AM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 100
nondisclosure007 is on a distinguished road
Quote:
Originally Posted by Michel View Post
You have to declare the two buffers : #property indicator_buffers 2

wow. can't believe i missed that.

now they're showing up on every candle. i've even put in a simple compare to an ima to see if i can dictate which one. that works too. now all i have to do is look at my original indicator that's giving me the problem and compare the 2.

thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #562 (permalink)  
Old 12-13-2007, 12:16 AM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 100
nondisclosure007 is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist View Post
Are you sure? Have you "compressed" the price scale to make sure it doesn't draw outside the current window?
you were right. they were there, just waaaaay off. i changed the formula of where to put the arrow. now they all show up.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #563 (permalink)  
Old 12-13-2007, 07:55 AM
Member
 
Join Date: Oct 2006
Posts: 56
Jovager is on a distinguished road
MACD stoploss

I want to stoploss on MACD.

I have this code :

double Mach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,Tr adeBar);
double vMach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,T radeBar+1);
double vvMach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN, TradeBar+2);

GlobalVariableSet("mt_Vager1"+Symbol()+Period(),mt r);
GlobalVariableSet("l_Vager1"+Symbol()+Period(),TP_ SL_Inc);



if (TotalOrders(Magic_Number)>0){
bool g=false;
while (!g){
g=true;
for (int kli=OrdersTotal()-1;kli>=0;kli--){
OrderSelect(kli,SELECT_BY_POS);
if

(OrderMagicNumber()==Magic_Number && OrderType()==OP_BUY && Mach<vMach && vMach<vvMach)
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Bid,Digits),Slippage,Pink);
g=false;
break;
}
if (OrderMag
icNumber()==Magic_Number && OrderType()==OP_SELL && m1>m2 && m11<=m21)
(OrderMagicNumber()==Magic_Number && OrderType()==OP_SELL && Mach>vMach && vMach>vvMach)
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Ask,Digits),Slippage,Pink);
g=false;
break;
}
}
}
}

Open works but not stoploss exit.

Thanks for help.

Jo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #564 (permalink)  
Old 12-13-2007, 08:00 AM
Member
 
Join Date: Oct 2006
Posts: 56
Jovager is on a distinguished road
MACD stoploss

Read TradeBar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #565 (permalink)  
Old 12-13-2007, 09:44 AM
Junior Member
 
Join Date: May 2007
Posts: 12
eastcity is on a distinguished road
I thought I could limit the number of alerts triggered by trigger using this:


if(trigger == 1)
{
int StartWaitingTime = GetTickCount();
if(GetTickCount() - StartWaitingTime > MaxWaiting_sec * 1000)
{

if(ShowAlert == true) {

Alert("Buy...........


But it does not seem to work, please help to modify it so it works, thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #566 (permalink)  
Old 12-13-2007, 10:11 AM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 556
MrPip is on a distinguished road
Quote:
Originally Posted by nondisclosure007 View Post
you were right. they were there, just waaaaay off. i changed the formula of where to put the arrow. now they all show up.
You also need to reset the avgRange to 0 before the loop.

avgRange = 0;
for (counter=i ;counter<=i+9;counter++)
{
avgRange=avgRange+MathAbs(High[counter]-Low[counter]);
}

Robert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #567 (permalink)  
Old 12-13-2007, 10:14 AM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 556
MrPip is on a distinguished road
You have an extra line in red that might cause a problem.

Robert


Quote:
Originally Posted by Jovager View Post
I want to stoploss on MACD.

I have this code :

double Mach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,Tr adeBar);
double vMach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,T radeBar+1);
double vvMach=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN, TradeBar+2);

GlobalVariableSet("mt_Vager1"+Symbol()+Period(),mt r);
GlobalVariableSet("l_Vager1"+Symbol()+Period(),TP_ SL_Inc);



if (TotalOrders(Magic_Number)>0){
bool g=false;
while (!g){
g=true;
for (int kli=OrdersTotal()-1;kli>=0;kli--){
OrderSelect(kli,SELECT_BY_POS);
if

(OrderMagicNumber()==Magic_Number && OrderType()==OP_BUY && Mach<vMach && vMach<vvMach)
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Bid,Digits),Slippage,Pink);
g=false;
break;
}
if (OrderMag
icNumber()==Magic_Number && OrderType()==OP_SELL && m1>m2 && m11<=m21)
(OrderMagicNumber()==Magic_Number && OrderType()==OP_SELL && Mach>vMach && vMach>vvMach)
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Ask,Digits),Slippage,Pink);
g=false;
break;
}
}
}
}

Open works but not stoploss exit.

Thanks for help.

Jo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #568 (permalink)  
Old 12-13-2007, 06:26 PM
Junior Member
 
Join Date: Dec 2007
Posts: 6
Slakerz is on a distinguished road
Need help on my EA

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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #569 (permalink)  
Old 12-13-2007, 06:50 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
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,
...
Who is this CHinGsMAroonCLK ?
As I remember, this EA is nothing else than 10p3 from elCactus, but maybe I am wrong...
Check it's thread, you will probably find what you are looking for: http://www.forex-tsd.com/expert-advi...nts-3-mq4.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #570 (permalink)  
Old 12-13-2007, 11:08 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
I thought I had fixed it but no.

What I am trying to do is have a comment on the chart and in the journal stating which entry condition was used to open the current position.

Has this been done before and how do you do it because I have been trying for a while now but no luck and it's not as easy as I thought.

Below is my latest attempt.

any help would be great

buysig = Long || Long2 || Long3 || Long4;
sellsig = Short || Short2 || Short3 || Short4;

closebuy=sellsig;
closesell=buysig;

if (curprof>=AccountEquity()*ProfitExit/100.0) {
exit=true;
}
if (last>0 && (Time[0]-last)/(Period()*60)>=CancelOrderBars) {
remorder=true;
}
}

void CheckForOpen() {
int res,tr;

//---- sell conditions
co=CalculateCurrentOrders(Symbol());
if(sellsig && lastsig!=-1) {
if ( Short == true)Print(" Short signal taken ");
if ( Short2 == true)Print(" Short2 signal taken ");
if ( Short3 == true)Print(" Short3 signal taken ");
if ( Short4 == true)Print(" Short4 signal taken ");
co=CalculateCurrentOrders(Symbol());
if (co==0) {
res = OpenStop(OP_SELLSTOP,LotsRisk(StopLoss), Low[shift]-OrderPipsDiff*Point, StopLoss, TakeProfit1);
}
lastsig=-1;
last=Time[0];
return;
}
//---- buy conditions
co=CalculateCurrentOrders(Symbol());
if(buysig && lastsig!=1) {
if ( Long == true) Print(" Long signal taken ");
if ( Long2 == true)Print(" Long2 signal taken ");
if ( Long3 == true) Print(" Long3 signal taken ");
if ( Long4 == true)Print(" Long4 signal taken ");
co=CalculateCurrentOrders(Symbol());
if (co==0) {
res = OpenStop(OP_BUYSTOP,LotsRisk(StopLoss), High[shift]+OrderPipsDiff*Point, StopLoss, TakeProfit1);
}
last=Time[0];
lastsig=1;
return;
}
}
bool CloseAtMarket(int ticket,double lot) {
//fault tolerant market order closing
bool bres=false; int tr;
tries=0;
while (!bres && tries<OrderTriesNumber) {
RefreshRates();
bres=OrderClose(ticket,lot,OrderClosePrice(),slipp age,White);
tries++;
tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
}
if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError()));
}

int OpenStop(int mode,double lot, double prc, int SL, int TP) {
int res,tr,col;
string mail;
double openprice,sl,tp,stlev;
tries=0;
stlev=(1+MarketInfo(Symbol(),MODE_STOPLEVEL))*Poin t;
while (res<=0 && tries<OrderTriesNumber) {
tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
RefreshRates();
if (mode==OP_SELLSTOP) {
if (prc<=Bid-stlev) openprice=prc;
else openprice=Bid-stlev;
if (SL>0) sl=openprice+SL*Point;
if (TP>0) tp=openprice-TP*Point;

col=Red;
} else
if (mode==OP_BUYSTOP) {
if (prc>=Ask+stlev) openprice=prc;
else openprice=Ask+stlev;
if (SL>0) sl=openprice-SL*Point;
if (TP>0) tp=openprice+TP*Point;

col=Blue;
} else return;
Print(Ask," ",Bid," ",Symbol()," ",mode," ",lot," ",openprice," ",sl," ",tp," ");
res=OrderSend(Symbol(),mode,lot,openprice,slippage ,sl,tp,EAName+"_"+ MagicNumber, MagicNumber,0,col);
tries++;
}
if (res<=0) Print("Error opening pending order : ",ErrorDescription(GetLastError()));
return(res);
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:12 PM.



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