Need help to code manual TakeProfit into this EA.

 

Hi, I tried putting this:

if (TakeProfit!=0)
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnumber)
{
TrailingStairs(OrderTicket(),TakeProfit);

in the end... But I couldn't make it work.. I'm a newbie when it comes to coding, probably will never be able to code. Please help add the manual profit target, there only seem to be a trailingstop/profit target. Much appreciated, thanks.


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

//| OpenTiks.mq4 |
//| Copyright © 2008, ZerkMax |
//| zma@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, ZerkMax"
#property link "zma@mail.ru"

extern int TakeProfit = 30;
extern int TrailingStop = 30;
extern int StopLoss = 0;
extern double Lots = 0.1;
extern int magicnumber = 777;
extern bool PolLots = true;
extern int MaxOrders = 1;

int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----





int i=0;
int total = OrdersTotal();
for(i = 0; i <= total; i++)
{
if(TrailingStop>0)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnumber)
{
TrailingStairs(OrderTicket(),TrailingStop);
}
}
}

bool BuyOp=false;
bool SellOp=false;


if (High[0]>High[1]&&High[1]>High[2]&&High[2]>High[3]&&Open[0]>Open[1]&&Open[1]>Open[2]&&Open[2]>Open[3]) BuyOp=true;
if (High[0]<High[1]&&High[1]<High[2]&&High[2]<High[3]&&Open[0]<Open[1]&&Open[1]<Open[2]&&Open[2]<Open[3]) SellOp=true;

if(Time[0] == prevtime)
return(0);
prevtime = Time[0];
if(!IsTradeAllowed())
{
prevtime = Time[1];
return(0);
}


if (total < MaxOrders || MaxOrders == 0)
{
if(BuyOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-(StopLoss*Point),0,"OpenTiks_Buy",magicnumber,0,Green);
}
else
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"OpenTiks_Buy",magicnumber,0,Green);
}
}
if(SellOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(StopLoss*Point),0,"OpenTiks_Sell",magicnumber,0,Red);
}
else
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"OpenTiks_Sell",magicnumber,0,Red);
}
}
{
if (TakeProfit!=0)
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnumber)
{
TrailingStairs(OrderTicket(),TakeProfit);
}
}
}

//----
return(0);
}
//+------------------------------------------------------------------+
void TrailingStairs(int ticket,int trldistance)
{
int Spred=Ask - Bid;
if (OrderType()==OP_BUY)
{
if((Bid-OrderOpenPrice())>(Point*trldistance))
{
if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
{
OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Ask,3,Green);
}
}
}
}
else
{
if((OrderOpenPrice()-Ask)>(Point*trldistance))
{
if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Bid,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Bid,3,Green);
}
}
}
}
}
 
No one? It must be so simple.. I just suck at coding.. Just a manual take profit to this EA thanks.. Much appreciated.
 

M

'manual' take profit - presume you mean hard-coded - like this?

Good Luck

-BB-


//+------------------------------------------------------------------+
//| OpenTiks.mq4 |
//| Copyright © 2008, ZerkMax |
//| zma@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, ZerkMax"
#property link "zma@mail.ru"

extern int TakeProfit = 30;
extern int TrailingStop = 30;
extern int StopLoss = 0;
extern double Lots = 0.1;
extern int magicnumber = 777;
extern bool PolLots = true;
extern int MaxOrders = 1;

int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----


int i=0;
int total = OrdersTotal();
for(i = 0; i <= total; i++)
{
if(TrailingStop>0)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnumber)
{
TrailingStairs(OrderTicket(),TrailingStop);
}
}
}

bool BuyOp=false;
bool SellOp=false;


if (High[0]>High[1]&&High[1]>High[2]&&High[2]>High[3]&&Open[0]>Open[1]&&Open[1]>Open[2]&&Open[2]>Open[3]) BuyOp=true;
if (High[0]<High[1]&&High[1]<High[2]&&High[2]<High[3]&&Open[0]<Open[1]&&Open[1]<Open[2]&&Open[2]<Open[3]) SellOp=true;

if(Time[0] == prevtime)
return(0);
prevtime = Time[0];
if(!IsTradeAllowed())
{
prevtime = Time[1];
return(0);
}


if (total < MaxOrders || MaxOrders == 0)
{
if(BuyOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-(StopLoss*Point),Ask+(TakeProfit*Point),"OpenTiks_Buy",magicnumber,0,Green);
}
else
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+(TakeProfit*Point),"OpenTiks_Buy",magicnumber,0,Green);
}
}
if(SellOp)
{
if (StopLoss!=0)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(StopLoss*Point),Bid-(TakeProfit*Point),"OpenTiks_Sell",magicnumber,0,Red);
}
else
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-(TakeProfit*Point),"OpenTiks_Sell",magicnumber,0,Red);
}
}
{

}
}

//----
return(0);
}
//+------------------------------------------------------------------+
void TrailingStairs(int ticket,int trldistance)
{
int Spred=Ask - Bid;
if (OrderType()==OP_BUY)
{
if((Bid-OrderOpenPrice())>(Point*trldistance))
{
if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
{
OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Ask,3,Green);
}
}
}
}
else
{
if((OrderOpenPrice()-Ask)>(Point*trldistance))
{
if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red);
if (PolLots)
if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
{
OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Bid,3,Green);
}
else
{
OrderClose(ticket,OrderLots(),Bid,3,Green);
}
}
}
}
}


 
BarrowBoy:

M

'manual' take profit - presume you mean hard-coded - like this?

Good Luck

-BB-

Hey mate. Thank you very much!

There's another thing I need done, would be lovely... You know how there's "Max Orders", I want it balanced..... Say I put 6 Max Orders, that will make 3 buy's and 3 sells y'know.. Would be great if you can have an on and off button or True and False y'know. Really appreciate it. Cheers, jays

 

I also have a question..... say I code:


if (High[1]>High[2]) Can I turn that into: if (High[1]>High[2,3,4,5])?


Cheers

 

BB - what are your current fees?

;)

 
fbj:

BB - what are your current fees?

;)

He usually charge eh?

 
Read the MQL4 programming book - at no cost...
 
fbj:
Read the MQL4 programming book - at no cost...

The problem is I don't understand anything, especially if I were to put it all together and whatnot...... The simplest thing in coding gets me aggitated, I just dont possess it eh..

 

yes, I see and also sympathize your position - this is an issue which is reasonably within grasp of all willing to study. All materials on web. Design, programming tutorials everywhere. Software to help you learn too. Assemblers, interpreters and compilers are also freely available. Excuse my what you may see as harshness, but I have always found that it is up to each individual to 'bite the bullet' and roll up their shirt sleeves, pick up the shovel and just get on with learning. MQL4 language is veeeeeery simple and it is not imho programming that always gives worst headache - it is the unsound deskwork/design sweat that let's many down. and hey - if you cannot trade manually your system you for sure not suceed with EA. While you doing manual system + refining it + making some income - you can be doing the learn-programming bit, yes? Is gonna be win-win situation that way! How cool is that then? making income and learning at same time!!!

of course, can always PM BarrowBoy (look at his profile) - he is genuine bloke with professional programming background who makes living from his skillset.

Best

 
fbj:

yes, I see and also sympathize your position - this is an issue which is reasonably within grasp of all willing to study. All materials on web. Design, programming tutorials everywhere. Software to help you learn too. Assemblers, interpreters and compilers are also freely available. Excuse my what you may see as harshness, but I have always found that it is up to each individual to 'bite the bullet' and roll up their shirt sleeves, pick up the shovel and just get on with learning. MQL4 language is veeeeeery simple and it is not imho programming that always gives worst headache - it is the unsound deskwork/design sweat that let's many down. and hey - if you cannot trade manually your system you for sure not suceed with EA. While you doing manual system + refining it + making some income - you can be doing the learn-programming bit, yes? Is gonna be win-win situation that way! How cool is that then? making income and learning at same time!!!

of course, can always PM BarrowBoy (look at his profile) - he is genuine bloke with professional programming background who makes living from his skillset.

Best

I don't disagree on the learning part and eventually have a sense of how it all works...... It's the countless hours of the learning process, while many are already expert at it..... But of course nothing is free true that...... Well I have a system I manually day trade with successfully, I guess that's a head start... Got a mate that's quite good at programming but he doesn't have the time or the right equitment right now, and I'm just getting ahead with him as usual.... Oh wells, just a matter of time I guess, I'll eventually have something coded somehow.. Cheers for the inspiration, I'll probably have to start from scratch if things keeps going this way =)

Reason: