Ask! - page 69

 

Hi,

Can somebody tell me what's wrong with this code?

It doesn't open any order at all?

I back test it at 2007.01.03

Cheers

extern string StrGetPosition = "19:55";

extern string StrStartOrderTime = "20:00";

extern string StrEndOrderTime = "23:59";

extern double MyBidPrice = 1.3271;

int CountOrder = 0, BuyMagicNumber, SellMagicNumber;

extern double Lots = 1;

extern int StopLoss = 35;

extern int TakeProfit = 8;

extern bool FlagBuy = false;

int x, b, FindMagicSell, TicketSell, FindMagicBuy, TicketBuy;

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

//| expert initialization function |

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

int init()

{

//----

MyBidPrice = 1.3271;

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

int GetPosition, StartOrderTime, EndOrderTime, o;

GetPosition = StrToTime(StrGetPosition);

StartOrderTime = StrToTime(StrStartOrderTime);

EndOrderTime = StrToTime(StrEndOrderTime);

if (TimeCurrent() >= StartOrderTime && TimeCurrent() <= EndOrderTime)

{

FlagBuy = true;

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

//| Posisi BUY

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

if (FlagBuy == true)

{

if ((MyBidPrice == Bid) && (CountOrder < 6))

{

CountOrder++;

BuyMagicNumber = StrToInteger("1" + CountOrder + Day() + Month() + Year());

o = OrderSend(Symbol(),OP_BUY,Lots,Bid,3,Bid-StopLoss*Point,Bid+TakeProfit*Point,"Test",BuyMagicNumber,0,Green);

if (o < 1) MessageBox("ERROR!!");

if (CountOrder > 1) ModifyBuy();

if (CountOrder == 5) FlagBuy = false;

MyBidPrice = Bid - (2*Point);

}

ShowComment();

}

}

//----

return(0);

}

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

void ModifyBuy()

{

for (x = 1; x < CountOrder; x++)

{

FindMagicBuy = StrToInteger("1" + x + Day() + Month() + Year());

for (b = 0; b < OrdersTotal(); b++)

{

OrderSelect(b,SELECT_BY_POS, MODE_TRADES);

if (OrderMagicNumber() == FindMagicBuy)

{

TicketBuy = OrderTicket();

OrderSelect(TicketBuy,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()-(2*Point),0);

break;

}

}

}

}

void ShowComment()

{

Comment("DayOfWeek = ",DayOfWeek(),"\nFLAG BUY : ",FlagBuy,"\nCount Order ",CountOrder,"\nNext order = ",MyBidPrice,"\nBID = ",Bid,"\nTime : ",TimeToStr(TimeCurrent(),TIME_MINUTES));

}
 

Can't Find MQ4 File For Indicator

I hope someone can help me with something I initially thought would be quite straightforward. I wanted to put an audible alert on an indicator that actually comes with Metatrader so that when it reaches a particular level it will tell me. The indicator is Force Index however I can not find an MQ4 file for it anywhere in the Experts/Indicators folder. Does anyone have an idea where I could locate the file?

If I can find the mq4 file would I be right in assuming I can use the code given by Codersguru at the beginning of this thread to add an alert to it?

thanks

 

ref Previous Post

I have managed to solve my problem from above post.

Thanks to all for interest.

 
Hartadi:
Hi,

Can somebody tell me what's wrong with this code?

It doesn't open any order at all?

I back test it at 2007.01.03

Cheers

o = OrderSend(Symbol(),OP_BUY,Lots,Bid,3,Bid-StopLoss*Point,Bid+TakeProfit*Point,"Test",BuyMagicNumber,0,Green);

You cannot buy at bid price.

 

@Michel :

Oh my god... how stupid i am..

thank you..

 

Help with hedging

Hi everyone!

I have used the Expert Advisor Builder at sufx.com to create an EA. It has two limitations that I am trying to get rid of:

1. only opens 1 trade at a time. I can get it to have two trades open at once, but I can't get it to open a buy order and a sell order simultaneously.

2. seems to take sell orders as a preference over buy orders. This wouldn't really be an issue if problem number 1 was solved.

Here is the peice of code that seems to be holding me up:

//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()) {

IsTrade = True;

if (OrderType() == OP_BUY) {

//Close

Any suggestions? I'd like to let it open as many trades as possible, and be able to open buy and sell orders simultaneously if the indicators say so.

Cheers for the help,

Benjimang

 

Profit/Loss of currency

Dave,

I think you need to be more specific in what you are asking for. And BTW why don't to reply to PMs? Where are you hiding these days??? lol

P in KC

 
FX4$$$:
Dave,

I think you need to be more specific in what you are asking for. And BTW why don't to reply to PMs? Where are you hiding these days??? lol

P in KC

I have not received any new PM's???? Unfortunately during this time I had a family emergency that happened - All is well with the emergency. I still could use the help on my coding, especially the envelope coding.

Dave

 

How do I post profit of currency at top right of graph??

I would like to post the profit/loss of currency at top right of the trade platform currency graph (EURUSD). If the profit of the current trade is positive, it would show in green; If it be 0.00, it would show in white; If it is a loss, it would show in red.

I know ObjectCreate is the way to go, but beyond that I do not know how to capture the profit from the tradeplatform? Can someone give me a hand on this utility?? I want to include this in my ea.

Thanks!

Dave

<<<
 

trading stats

use this code:

// ***************************************************************************

int stats()

{

int i, vOrders;

// current CP profit

vOrders = OrdersTotal();

Profit = 0;

PipsProfit = 0;

for(i=vOrders-1;i>=0;i--)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol())

{

Profit += OrderProfit();

if (OrderType() == OP_BUY) PipsProfit += ((Bid - OrderOpenPrice())/Point);

else if (OrderType() == OP_SELL) PipsProfit += ((OrderOpenPrice() - Ask)/Point);

}

}

}

// potential risk

// max positions

}

Profit & PipsProfit will need to be declared outside the program, then display then on the screen with your favorite method. Comments if nothing else.

Mark

Reason: