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
  #1531 (permalink)  
Old 01-13-2009, 08:34 AM
Senior Member
 
Join Date: Apr 2006
Posts: 158
InTrance is on a distinguished road
Quote:
Originally Posted by Moxy View Post
Hi Lux,

Thanks for the reply. I can workout out the individual iMA statements etc... the problem i have is how to reference the different time bars once a signal is triggered. For example... If I have a GET READY signal I need to look at the 2 bars before and 2 bars after (5 bars in total) for the other indicators to confirm I have a BUY SIGNAL on the open of the next bar. Not sure if I am making sense !!

I guess it is... how would i structure the necessary FOR loops etc.. when I need to reference bars both before and after the bar being processed.

Regards,
Moxy
You do this by using the shift variable in iMA(). You can also do this with Open, High, Low, Close values i.e. Close[3] which is 3 bars away from current bar.
__________________
Need a Professional Programmer? PM me
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
  #1532 (permalink)  
Old 01-13-2009, 12:51 PM
Junior Member
 
Join Date: Nov 2006
Posts: 1
ccscowboy is on a distinguished road
Moving average of Moves

Ok need a bit of help with code, I am looking to determine a set of average moves around a MA, so from the oldest BAR, I look for the moves above and below, put them into an array then average that array.

here is the code I am starting with, looking for a bit of assistance to get it done.

double AverageMove()
{
int cbars = iBars(Symbol(),EntryTimeFrame);
int counted_bars = 0,RangeCounter=0,ndx=0,iLimit=0;
double retval,averagemove,pHValue,pLValue,MAvalue,RangeVa lue[],EntryPoint,cHigh,cLow;
bool reset,TradeShort,TradeLong;

iLimit=Bars-1;
if(Symbol() != "AUDNZD") return(0);
for(ndx=0; ndx<iLimit; ndx++)
{

MAvalue = iMA(Symbol(),EntryTimeFrame,EntryMAInterval,0,Movi ngAverageType,PRICE_MEDIAN,ndx);
pHValue = High[ndx];
pLValue = Low[ndx];
if(MAvalue < pHValue && MAvalue > pLValue)
{
if(Symbol() =="AUDNZD") Print("MAValue="+MAvalue+" pHValue="+pHValue+" plValue="+pLValue);
reset = true;
if(EntryPoint > 0 && cHigh > 0)
{
RangeCounter++;
RangeValue[RangeCounter]=cHigh - EntryPoint;
}
if(EntryPoint > 0 && cLow > 0)
{
RangeCounter++;
RangeValue[RangeCounter]=EntryPoint - cLow;
}
EntryPoint = MAvalue;
}
if(pHValue < MAvalue && reset) TradeShort = true;
if(pLValue > MAvalue && reset) TradeLong = true;
if(TradeLong)
{
reset = false;
cHigh = pHValue;
}
if(TradeShort)
{
reset = False;
cLow = pLValue;
}


}
ArraySetAsSeries(RangeValue,true);
retval=iMAOnArray(RangeValue,RangeCounter,13,1,PRI CE_MEDIAN,0);
Print("Average Move"+retval);
}
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
  #1533 (permalink)  
Old 01-13-2009, 05:55 PM
Kikousi's Avatar
Junior Member
 
Join Date: Nov 2008
Posts: 6
Kikousi is on a distinguished road
I would like to know the client area at the chart.

Hellow,

I would like to know the client area at the chart.
Please advise me.
Assuming that the point of the left top corner is (0,0), please let me know the coordinats of the the right bottom.

In this case, ObjectSet("",OBJPROP_CORNER,3)shoud not be used.

Many thans and best regards,
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
  #1534 (permalink)  
Old 01-14-2009, 12:36 AM
Member
 
Join Date: Sep 2008
Posts: 65
codobro is on a distinguished road
Kikousi,

You may want to test for yourself the best coordinates. FerruFX and CJA have used the best solutions of having default corner positions with user-inputs to object placement. You may also want to look at OBJPROP_CORNER

Also, please try not to post the same request as you have done. Users see your post, and if someone can help you they will.

Thank you

Edit: Using the corner property 0 is upper left, 1 is upper right, 2 lower left, 3 lower right. It is 0 count.

Last edited by codobro; 01-14-2009 at 12:43 AM. Reason: Corner properties
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
  #1535 (permalink)  
Old 01-14-2009, 12:41 AM
Member
 
Join Date: Sep 2008
Posts: 65
codobro is on a distinguished road
Moxy,

If I understand you correctly then you will have to code this line for line in an EA.

example

MA1, index-1 before
MA1, index now
MA1, index+1 after

you have the basic there
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
  #1536 (permalink)  
Old 01-14-2009, 05:26 AM
Junior Member
 
Join Date: Apr 2008
Posts: 8
ssg10 is on a distinguished road
Help with debugging my EA

Hi. Sorry if this is the wrong forum to post and please fix if it is.

I programmed my own EA and have some problems with order filling and stop loss orders. Could somebody help? I can share the EA.

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
  #1537 (permalink)  
Old 01-14-2009, 06:31 AM
Kikousi's Avatar
Junior Member
 
Join Date: Nov 2008
Posts: 6
Kikousi is on a distinguished road
codobro,

Thank you very much for your kind reply.
I will not post the same question again from now on.
I apprciate your suggestion.
In this connection, I understand that upper left position is (0,0) , then What is the indication of lower right at that time?
For example, can I use (250,350) for lower right indication when upper left position is (0,0) ?

I thank you in advance for your kindest understanding of the above.
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
  #1538 (permalink)  
Old 01-16-2009, 10:42 AM
Junior Member
 
Join Date: Jan 2009
Posts: 1
Niller is on a distinguished road
Indicator graph not showing all data

Hi
I am fairly good at C-programming, but starting with MQL4.
I just made my first indicator and it shows an array partly in the separate window.
By partly I mean if you scroll left, then for some time-periods nothing is displayed, and if I scroll further left, then data i displayed for some periods and so on.
If you scroll right, then the same time-periods does not show.
Otherwise I see no pattern.
Also, if I shift from 1-min, where I do see some data, to say 5-min, then nothing are shown at all.
Why isnt all of the data shown? What might I have missed?
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
  #1539 (permalink)  
Old 01-17-2009, 11:02 AM
Junior Member
 
Join Date: May 2008
Posts: 2
hkstar98 is on a distinguished road
Exclamation Good EA - NEED HELP

Hai,

Is there anyone in this great forum, could modified this EA without any stop loss.

Thanks


//---- input parameters ---------------------------------------------+

extern int INCREMENT=35;
extern double LOTS=0.1;
extern int LEVELS=3;
extern double MAX_LOTS=99;
extern int MAGIC=1803;
extern bool CONTINUE=true;
extern bool MONEY_MANAGEMENT=false;
extern int RISK_RATIO=2;
//+------------------------------------------------------------------+

bool UseProfitTarget=false;
bool UsePartialProfitTarget=false;
int Target_Increment = 50;
int First_Target = 20;
bool UseEntryTime=false;
int EntryTime=0;

//+------------------------------------------------------------------+

bool Enter=true;
int nextTP;

int init()
{
//+------------------------------------------------------------------+
nextTP = First_Target;
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ticket, cpt, profit, total=0, BuyGoalProfit, SellGoalProfit, PipsLot;
double ProfitTarget=INCREMENT*2, BuyGoal=0, SellGoal=0, spread=(Ask-Bid)/Point, InitialPrice=0;
//----

if(INCREMENT<MarketInfo(Symbol(),MODE_STOPLEVEL)+s pread) INCREMENT=1+MarketInfo(Symbol(),MODE_STOPLEVEL)+sp read;
if(MONEY_MANAGEMENT) LOTS=NormalizeDouble(AccountBalance()*AccountLever age()/1000000*RISK_RATIO,0)*MarketInfo(Symbol(),MODE_MIN LOT);
if(LOTS<MarketInfo(Symbol(),MODE_MINLOT))
{
Comment("Not Enough Free Margin to begin");
return(0);
}
for(cpt=1;cpt<LEVELS;cpt++) PipsLot+=cpt*INCREMENT;
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MAGIC && OrderSymbol()==Symbol())
{
total++;
if(!InitialPrice) InitialPrice=StrToDouble(OrderComment());
if(UsePartialProfitTarget && UseProfitTarget && OrderType()<2)
{
double val=getPipValue(OrderOpenPrice(),OrderType());
takeProfit(val,OrderTicket());
}
}
}
if(total<1 && Enter && (!UseEntryTime || (UseEntryTime && Hour()==EntryTime)))
{
if(AccountFreeMargin()<(100*LOTS))
{
Print("Not enough free margin to begin");
return(0);
}
// - Open Check - Start Cycle
InitialPrice=Ask;
SellGoal=InitialPrice-(LEVELS+1)*INCREMENT*Point;
BuyGoal=InitialPrice+(LEVELS+1)*INCREMENT*Point;
for(cpt=1;cpt<=LEVELS;cpt++)
{
OrderSend(Symbol(),OP_BUYSTOP,LOTS,InitialPrice+cp t*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(I nitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGI C,0);
OrderSend(Symbol(),OP_SELLSTOP,LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoa l+spread*Point,DoubleToStr(InitialPrice,MarketInfo (Symbol(),MODE_DIGITS)),MAGIC,0);
}
} // initial setup done - all channels are set up
else // We have open Orders
{
BuyGoal=InitialPrice+INCREMENT*(LEVELS+1)*Point;
SellGoal=InitialPrice-INCREMENT*(LEVELS+1)*Point;
total=OrdersHistoryTotal();
for(cpt=0;cpt<total;cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && StrToDouble(OrderComment())==InitialPrice){EndSess ion();return(0);}
}
if(UseProfitTarget && CheckProfits(LOTS,OP_SELL,true,InitialPrice)>Profi tTarget) {EndSession();return(0);}
BuyGoalProfit=CheckProfits(LOTS,OP_BUY,false,Initi alPrice);
SellGoalProfit=CheckProfits(LOTS,OP_SELL,false,Ini tialPrice);
if(BuyGoalProfit<ProfitTarget)
// - Incriment Lots Buy
{
for(cpt=LEVELS;cpt>=1 && BuyGoalProfit<ProfitTarget;cpt--)
{
if(Ask<=(InitialPrice+(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,cpt*LOTS,Init ialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,Do ubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DI GITS)),MAGIC,0);
}
if(ticket>0) BuyGoalProfit+=LOTS*(BuyGoal-InitialPrice-cpt*INCREMENT*Point)/Point;
}
}
if(SellGoalProfit<ProfitTarget)
// - Increment Lots Sell
{
for(cpt=LEVELS;cpt>=1 && SellGoalProfit<ProfitTarget;cpt--)
{
if(Bid>=(InitialPrice-(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,cpt*LOTS,Ini tialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoa l+spread*Point,DoubleToStr(InitialPrice,MarketInfo (Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) SellGoalProfit+=LOTS*(InitialPrice-cpt*INCREMENT*Point-SellGoal-spread*Point)/Point;
}
}
}
//+------------------------------------------------------------------+

Comment("mGRID EXPERT ADVISOR ver 2.0\n",
"FX Acc Server:",AccountServer(),"\n",
"Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n",
"Minimum Lot Sizing: ",MarketInfo(Symbol(),MODE_MINLOT),"\n",
"Account Balance: $",AccountBalance(),"\n",
"Symbol: ", Symbol(),"\n",
"Price: ",NormalizeDouble(Bid,4),"\n",
"Pip Spread: ",MarketInfo("EURUSD",MODE_SPREAD),"\n",
"Increment=" + INCREMENT,"\n",
"Lots: ",LOTS,"\n",
"Levels: " + LEVELS,"\n");
return(0);
}

//+------------------------------------------------------------------+

int CheckProfits(double LOTS, int Goal, bool Current, double InitialPrice)
{
int profit=0, cpt;
if(Current)//return current profit
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(Bid-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-Ask)/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
if(Goal==OP_BUY)
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit-=(OrderStopLoss()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_BUYSTOP) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit-=(OrderOpenPrice()-OrderStopLoss())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELLSTOP) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
}
}

bool EndSession()
{
int cpt, total=OrdersTotal();
for(cpt=0;cpt<total;cpt++)
{
Sleep(3000);
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderType()>1) OrderDelete(OrderTicket());
else if(OrderSymbol()==Symbol() && OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3);
else if(OrderSymbol()==Symbol() && OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3);

}
if(!CONTINUE) Enter=false;
return(true);
}


double getPipValue(double ord,int dir)
{
double val;
RefreshRates();
if(dir == 1) val=(NormalizeDouble(ord,Digits) - NormalizeDouble(Ask,Digits));
else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(ord,Digits));
val = val/Point;
return(val);
}

//========== FUNCTION takeProfit

void takeProfit(int current_pips, int ticket)
{
if(OrderSelect(ticket, SELECT_BY_TICKET))
{

if(current_pips >= nextTP && current_pips < (nextTP + Target_Increment))
{
if(OrderType()==1)
{
if(OrderClose(ticket, MAX_LOTS, Ask, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
else
{
if(OrderClose(ticket, MAX_LOTS, Bid, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
}
}
}
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
  #1540 (permalink)  
Old 01-17-2009, 11:53 AM
Banned
 
Join Date: Oct 2006
Posts: 32
pghiaci is on a distinguished road
Quote:
Originally Posted by hkstar98 View Post
Hai,

Is there anyone in this great forum, could modified this EA without any stop loss.

Thanks


//---- input parameters ---------------------------------------------+

extern int INCREMENT=35;
extern double LOTS=0.1;
extern int LEVELS=3;
extern double MAX_LOTS=99;
extern int MAGIC=1803;
extern bool CONTINUE=true;
extern bool MONEY_MANAGEMENT=false;
extern int RISK_RATIO=2;
//+------------------------------------------------------------------+

bool UseProfitTarget=false;
bool UsePartialProfitTarget=false;
int Target_Increment = 50;
int First_Target = 20;
bool UseEntryTime=false;
int EntryTime=0;

//+------------------------------------------------------------------+

bool Enter=true;
int nextTP;

int init()
{
//+------------------------------------------------------------------+
nextTP = First_Target;
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ticket, cpt, profit, total=0, BuyGoalProfit, SellGoalProfit, PipsLot;
double ProfitTarget=INCREMENT*2, BuyGoal=0, SellGoal=0, spread=(Ask-Bid)/Point, InitialPrice=0;
//----

if(INCREMENT<MarketInfo(Symbol(),MODE_STOPLEVEL)+s pread) INCREMENT=1+MarketInfo(Symbol(),MODE_STOPLEVEL)+sp read;
if(MONEY_MANAGEMENT) LOTS=NormalizeDouble(AccountBalance()*AccountLever age()/1000000*RISK_RATIO,0)*MarketInfo(Symbol(),MODE_MIN LOT);
if(LOTS<MarketInfo(Symbol(),MODE_MINLOT))
{
Comment("Not Enough Free Margin to begin");
return(0);
}
for(cpt=1;cpt<LEVELS;cpt++) PipsLot+=cpt*INCREMENT;
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MAGIC && OrderSymbol()==Symbol())
{
total++;
if(!InitialPrice) InitialPrice=StrToDouble(OrderComment());
if(UsePartialProfitTarget && UseProfitTarget && OrderType()<2)
{
double val=getPipValue(OrderOpenPrice(),OrderType());
takeProfit(val,OrderTicket());
}
}
}
if(total<1 && Enter && (!UseEntryTime || (UseEntryTime && Hour()==EntryTime)))
{
if(AccountFreeMargin()<(100*LOTS))
{
Print("Not enough free margin to begin");
return(0);
}
// - Open Check - Start Cycle
InitialPrice=Ask;
SellGoal=InitialPrice-(LEVELS+1)*INCREMENT*Point;
BuyGoal=InitialPrice+(LEVELS+1)*INCREMENT*Point;
for(cpt=1;cpt<=LEVELS;cpt++)
{
OrderSend(Symbol(),OP_BUYSTOP,LOTS,InitialPrice+cp t*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(I nitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGI C,0);
OrderSend(Symbol(),OP_SELLSTOP,LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoa l+spread*Point,DoubleToStr(InitialPrice,MarketInfo (Symbol(),MODE_DIGITS)),MAGIC,0);
}
} // initial setup done - all channels are set up
else // We have open Orders
{
BuyGoal=InitialPrice+INCREMENT*(LEVELS+1)*Point;
SellGoal=InitialPrice-INCREMENT*(LEVELS+1)*Point;
total=OrdersHistoryTotal();
for(cpt=0;cpt<total;cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && StrToDouble(OrderComment())==InitialPrice){EndSess ion();return(0);}
}
if(UseProfitTarget && CheckProfits(LOTS,OP_SELL,true,InitialPrice)>Profi tTarget) {EndSession();return(0);}
BuyGoalProfit=CheckProfits(LOTS,OP_BUY,false,Initi alPrice);
SellGoalProfit=CheckProfits(LOTS,OP_SELL,false,Ini tialPrice);
if(BuyGoalProfit<ProfitTarget)
// - Incriment Lots Buy
{
for(cpt=LEVELS;cpt>=1 && BuyGoalProfit<ProfitTarget;cpt--)
{
if(Ask<=(InitialPrice+(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,cpt*LOTS,Init ialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,Do ubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DI GITS)),MAGIC,0);
}
if(ticket>0) BuyGoalProfit+=LOTS*(BuyGoal-InitialPrice-cpt*INCREMENT*Point)/Point;
}
}
if(SellGoalProfit<ProfitTarget)
// - Increment Lots Sell
{
for(cpt=LEVELS;cpt>=1 && SellGoalProfit<ProfitTarget;cpt--)
{
if(Bid>=(InitialPrice-(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,cpt*LOTS,Ini tialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoa l+spread*Point,DoubleToStr(InitialPrice,MarketInfo (Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) SellGoalProfit+=LOTS*(InitialPrice-cpt*INCREMENT*Point-SellGoal-spread*Point)/Point;
}
}
}
//+------------------------------------------------------------------+

Comment("mGRID EXPERT ADVISOR ver 2.0\n",
"FX Acc Server:",AccountServer(),"\n",
"Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n",
"Minimum Lot Sizing: ",MarketInfo(Symbol(),MODE_MINLOT),"\n",
"Account Balance: $",AccountBalance(),"\n",
"Symbol: ", Symbol(),"\n",
"Price: ",NormalizeDouble(Bid,4),"\n",
"Pip Spread: ",MarketInfo("EURUSD",MODE_SPREAD),"\n",
"Increment=" + INCREMENT,"\n",
"Lots: ",LOTS,"\n",
"Levels: " + LEVELS,"\n");
return(0);
}

//+------------------------------------------------------------------+

int CheckProfits(double LOTS, int Goal, bool Current, double InitialPrice)
{
int profit=0, cpt;
if(Current)//return current profit
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(Bid-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-Ask)/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
if(Goal==OP_BUY)
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit-=(OrderStopLoss()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_BUYSTOP) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit-=(OrderOpenPrice()-OrderStopLoss())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELLSTOP) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
}
}

bool EndSession()
{
int cpt, total=OrdersTotal();
for(cpt=0;cpt<total;cpt++)
{
Sleep(3000);
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderType()>1) OrderDelete(OrderTicket());
else if(OrderSymbol()==Symbol() && OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3);
else if(OrderSymbol()==Symbol() && OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3);

}
if(!CONTINUE) Enter=false;
return(true);
}


double getPipValue(double ord,int dir)
{
double val;
RefreshRates();
if(dir == 1) val=(NormalizeDouble(ord,Digits) - NormalizeDouble(Ask,Digits));
else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(ord,Digits));
val = val/Point;
return(val);
}

//========== FUNCTION takeProfit

void takeProfit(int current_pips, int ticket)
{
if(OrderSelect(ticket, SELECT_BY_TICKET))
{

if(current_pips >= nextTP && current_pips < (nextTP + Target_Increment))
{
if(OrderType()==1)
{
if(OrderClose(ticket, MAX_LOTS, Ask, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
else
{
if(OrderClose(ticket, MAX_LOTS, Bid, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
}
}
}


Hi
here you go
Attached Files
File Type: mq4 new.mq4 (7.8 KB, 27 views)
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 05:26 AM.



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