How to code? - page 48

 
MrPip:
I have used this in other EAs and it works correctly.

I check for trade closed today instead of open today.

Usage in start is

if (LastTradeClosedToday()) return(0);

// code here to open new trades

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

//| LastTradeClosedToday |

//| Check History to see if last trade closed today |

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

bool LastTradeClosedToday()

{

int cnt, total;

bool Closed;

total = HistoryTotal();

for (cnt = total - 1; cnt >= 0; cnt--)

{

OrderSelect (cnt, SELECT_BY_POS, MODE_HISTORY);

if(OrderSymbol()!=Symbol()) continue;

if (OrderMagicNumber() != MagicNumber) continue;

Closed = false;

if (OrderType() == OP_BUY)

{

if (TimeDay(OrderCloseTime()) == TimeDay(TimeCurrent()))

{

Closed = true;

}

cnt = 0;

}

if (OrderType() == OP_SELL)

{

if (TimeDay(OrderCloseTime()) == TimeDay(TimeCurrent()))

{

Closed = true;

}

cnt = 0;

}

}

return (Closed);

}

ok i will try.. thanks mr pips.. your of great help..

 

Problem Solved

Hi,

I have solved my bug myself, a silly mistake made. Thanks all for reading this thread.

 

Converted it yet?

Beno:
Thanks Mr Pips Sorted it

Is it possible to turn this indicator into an EA. I thought Beno is trying to do this. I will appreciate anyone who has done it or can do it to please post the EA version of this indicator. Many thanks

The indicator is attached:

 
makemo8:
Is it possible to turn this indicator into an EA. I thought Beno is trying to do this. I will appreciate anyone who has done it or can do it to please post the EA version of this indicator. Many thanks The indicator is attached:

Oops! the indicator to be converted to an EA is MT4-LevelStop-Reverse-vB0-4.mq4

 

Hi,

I have a EA to trade breakout - each night, I have to load preset files with the breakouts levels for the next day.

My question is : How can I make the EA looks for the preset files himself instead of doing it myself ?

Example : I upload the presets files on a ftp, the ea know the adress and each day at 22:00, the presets files are loaded from this adress.

Is this possible ?

Thanks

 

Programming questions

I have a couple quick questions:

1. Suppose I am trading GBPUSD on the 15 minute charts. Does the start() function in my EA get called only when a new bar becomes available (every 15 minutes) or is it every time there is a new quote (cane be every few seconds)?

2. Suppose at a specific time I place two orders - one is a buy stop say 20 pips above the current price and the other is a sell stop 20 pips below the current price. If the price goes up to my buy stop, I want to cancel the sell stop as soon as I confirm that the buy stop order was triggered. Similarly, if the price goes down to my sell stop, I want to cancel the buy stop as soon as I confirm that the sell stop was triggered.

So is there an easy way to do this? How do I confirm that the buy stop was triggered before canceling the sell stop? Does the system provide some sort of order callback function that lets me know an order was triggered? Or do I just have to let the start() function keep checking for open orders every quote and detect it that way?

Thanks

 
westofpluto:
I have a couple quick questions:

1. Suppose I am trading GBPUSD on the 15 minute charts. Does the start() function in my EA get called only when a new bar becomes available (every 15 minutes) or is it every time there is a new quote (cane be every few seconds)?

2. Suppose at a specific time I place two orders - one is a buy stop say 20 pips above the current price and the other is a sell stop 20 pips below the current price. If the price goes up to my buy stop, I want to cancel the sell stop as soon as I confirm that the buy stop order was triggered. Similarly, if the price goes down to my sell stop, I want to cancel the buy stop as soon as I confirm that the sell stop was triggered.

So is there an easy way to do this? How do I confirm that the buy stop was triggered before canceling the sell stop? Does the system provide some sort of order callback function that lets me know an order was triggered? Or do I just have to let the start() function keep checking for open orders every quote and detect it that way?

Thanks

1. Start() function is called at every tick

2. Yes it's possible. More than one way to do it. You could set your buy stop and sell stop, then call the OrderType( ) function, if it returns an OP_BUY or an OP_SELL , you could then use OrderDelete( ) to delete the existing pending order.

 

is this correct mr pips? will it work with strategy tester cause it is not working in the tester.. or should i only forward test it?

if (LastTradeOpenToday()) return ();

bool LastTradeOpenToday()

{

int cnt, total;

bool Opened;

total = HistoryTotal();

for (cnt = total - 1; cnt >= 0; cnt--)

{

OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()!=Symbol()) continue;

if (OrderMagicNumber() != Magic_Number) continue;

Opened = false;

if (OrderType() == OP_BUY)

{

if (TimeDay(OrderOpenTime()) >= TimeDay(TimeCurrent()))

{

Opened = true;

}

cnt = 0;

}

if (OrderType() == OP_SELL)

{

if (TimeDay(OrderOpenTime()) >= TimeDay(TimeCurrent()))

{

Opened = true;

}

cnt = 0;

}

}

return (Opened);

}
 

Mathematical differential

Can a coder tell me how can I introduce a new indicator based on mathematical differential or integral ?

I am seeking for the formula which transfer an indicator to mathematical differential or integral

 

csv files

dear friends

i need an indicator to save me the CSV files instead of using "ctrl+s"

thanks