How to code? - page 336

 
tkuan77:
Hi mladen, sad to say I just retried it again and its still not working.

Is there another way which I can close my trade based on specific timing?

Regards

Ryan

I used this code :

extern bool UseCurrSymbol = false;

int init() { return(0); }

int deinit() { return(0); }

void start(void)

{

bool result;

if(OrdersTotal()>0)

{

if (TimeCurrent()>= StrToTime("07:00:00"))

for (int i=OrdersTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

if (!UseCurrSymbol || OrderSymbol()==Symbol())

{

if (OrderType()==OP_BUY)

{

double pBid=MarketInfo(OrderSymbol(),MODE_BID);

result = OrderClose(OrderTicket(),OrderLots(),pBid,3,Blue);

}

if (OrderType()==OP_SELL)

{

double pAsk=MarketInfo(OrderSymbol(),MODE_ASK);

result = OrderClose(OrderTicket(),OrderLots(),pAsk,3,Red);

}

}

}

}

return;

}

To test, and it closed the order (see the example)

Files:
test_closed.gif  63 kb
 
mladen:
I used this code :
extern bool UseCurrSymbol = false;

int init() { return(0); }

int deinit() { return(0); }

void start(void)

{

bool result;

if(OrdersTotal()>0)

{

if (TimeCurrent()>= StrToTime("07:00:00"))

for (int i=OrdersTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

if (!UseCurrSymbol || OrderSymbol()==Symbol())

{

if (OrderType()==OP_BUY)

{

double pBid=MarketInfo(OrderSymbol(),MODE_BID);

result = OrderClose(OrderTicket(),OrderLots(),pBid,3,Blue);

}

if (OrderType()==OP_SELL)

{

double pAsk=MarketInfo(OrderSymbol(),MODE_ASK);

result = OrderClose(OrderTicket(),OrderLots(),pAsk,3,Red);

}

}

}

}

return;

}

To test, and it closed the order (see the example)

Hi mladen, thanks. the problem has been resolved on my end. just a side note, can you explain abit to me what is the purpose of this few liners in your coding?

extern bool UseCurrSymbol = false; and

if (!UseCurrSymbol || OrderSymbol()==Symbol())

Regards

Ryan

 
tkuan77:
Hi mladen, thanks. the problem has been resolved on my end. just a side note, can you explain abit to me what is the purpose of this few liners in your coding?

extern bool UseCurrSymbol = false; and

if (!UseCurrSymbol || OrderSymbol()==Symbol())

Regards

Ryan

You used UseCurrSymbol variable and that exact line in your code

I had to make that variable so that the code uses same variables as your code

 
mladen:
You used UseCurrSymbol variable and that exact line in your code I had to make that variable so that the code uses same variables as your code

Hi mladen, sorry as i got that part of the code from the sources you provided me earlier.

what i meant was why do we need to set a bool UseCurrSymbol to false and what is the purpose of the 2nd liner for --> if (!UseCurrSymbol || OrderSymbol()==Symbol())

 
tkuan77:
Hi mladen, sorry as i got that part of the code from the sources you provided me earlier. what i meant was why do we need to set a bool UseCurrSymbol to false and what is the purpose of the 2nd liner for --> if (!UseCurrSymbol || OrderSymbol()==Symbol())

We do not need to set it to false

If you set it to true, then only current symbol will be checked for orders. So it allows you to chose which orders you want to process

 

Hi guys!

I have the following problem.

I want a value of an icustom indi e.g. iCustom(NULL,0,"MACD",12,26,9,0,i) to be use in a subfunction like:

double Mom(const double& series[], int period, int totcount, int index)

{

if (totcount<1 || period<1) return (EMPTY_VALUE);

if (indextotcount-1) return (EMPTY_VALUE);

return (series-series);

}

to get the momentum of the "iCustom(NULL,0,"MACD",12,26,9,0,i)"...

When I call it normaly with Mom(High,22,Bars,i)

this is working, but when I use the custom indi instead of the "High", it of course doesn't.

So my question is, how can I implement this to get the code working?

Thanks for any help!

Bye, AT

 
at120:
Hi guys!

I have the following problem.

I want a value of an icustom indi e.g. iCustom(NULL,0,"MACD",12,26,9,0,i) to be use in a subfunction like:

double Mom(const double& series[], int period, int totcount, int index)

{

if (totcount<1 || period<1) return (EMPTY_VALUE);

if (indextotcount-1) return (EMPTY_VALUE);

return (series-series);

}

to get the momentum of the "iCustom(NULL,0,"MACD",12,26,9,0,i)"...

When I call it normaly with Mom(High,22,Bars,i)

this is working, but when I use the custom indi instead of the "High", it of course doesn't.

So my question is, how can I implement this to get the code working?

Thanks for any help!

Bye, AT

at120

Do you have indicator named "macd" in the indicators folder at all (I don't mean the built in macd, but some custom macd)? If yes, check if the parameters are correct

 

Hi Mladen!

Thanks for fast replay!

Sorry MACD was a bad example, take any other indi a custom MACD or something like that.

I checked the output via extra window and test indi /output to set the right settings,

to be sure "iCustom(NULL,0,"myIndi",0,i)" has right parameters. Of corse it is compiled, right folder, etc...

I always get the error (when I use a variable) - e.g.

double mom1 = iCustom(NULL,0,"myIndi",0,i); -> mom(mom1,Bars,20,i)

-> "mom" - parameter conversation not allowed or when I use it directly ->

mom( iCustom(NULL,0,"myIndi",0,i),Bars,20,i)

Error: iCustom - parameter passed as reference, variable expected

Thanks for help and info!

Bye, AT

 
at120:
Hi Mladen!

Thanks for fast replay!

Sorry MACD was a bad example, take any other indi a custom MACD or something like that.

I checked the output via extra window and test indi /output to set the right settings,

to be sure "iCustom(NULL,0,"myIndi",0,i)" has right parameters. Of corse it is compiled, right folder, etc...

I always get the error (when I use a variable) - e.g.

double mom1 = iCustom(NULL,0,"myIndi",0,i);-> mom(mom1,Bars,20,i)

-> "mom" - parameter conversation not allowed or when I use it directly ->

mom( iCustom(NULL,0,"myIndi",0,i),Bars,20,i)

Error: iCustom - parameter passed as reference, variable expected

Thanks for help and info!

Bye, AT

I you use simple iCustom() call then error can happen only in parameters

You can not use iCustom() as a parameter for the mom() function (check the mom function header and you shall see what parameters and what type of parameters does mom() function accept). Result of iCustom() is defined as "double" - it can not take pace of an array passed by reference. Check this thread too : https://www.mql5.com/en/forum/173108 - maybe it helps

 

Hi Mladen!

I think the call of my iCustom ist right, because in test and normal (exporting data or use as indi)

it works fine so far. I think the problem is as you mentioned value double/array.

When I now use a

double mom1[];

mom1 = iCustom(NULL,0,"myIndi",0,i);

and than a -> mom(mom1,Bars,20,i);

-> "mom" - parameter conversation not allowed

How do I write this right?

Thanks a lot and bye, AT