Ask! - page 134

 
bakhul:
Could u someone here help me to add alert to this filter,when it cross 0 level or change color. Thank`s for u who want to help me...

Maybe you would have better luck to posting here: https://www.mql5.com/en/forum

 

How Many Currently open Buy, and Sell Orders from EA

I just went through 134 pages hoping someone had already answer this question. But I was out of luck..

After creating and tweaking every type of cross over, and pivot point, and ATR range, and break out strategy that I can conceive with the hundreds of different indicators that I have. I realized that a full blown automated EA needs tons of variables that you need to code for. So I instead, I am starting to create user assisted expert advisors. Well to the questions at hand...

What code can be used to count how many open Buy and how many open sell orders the EA currently has open in the Market.

I do not want it to count how many open orders there are in total because I will be placing orders as well on the same account to offset the current orders that the EA has placed.

Eventually I would like to set up filters that will alter the ratio of buy and sell orders for hedging purposes.

 

A little help please...

Hi All,

I originally posted this as a new thread, but it was moved into another programming thread (I have no objections to its move BTW) and now seems to have got lost due to the amount of posters in that thread.

Perhaps someone here can help me?

I have nearly finished my first EA after nearly 7 days of trial and error and cutting and pasting and hours of research....

Can someone please tell me how to issue an exit or stop function to an EA?

I want the EA to delete all current and pending trades and exit after reaching 10,000 in equity. Below is that portion of the code so far:

bool StopTrade;

int total = OrdersTotal(), cnt = 0, ExitAtEquity=10000;

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

{

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

if (AccountEquity ()== ExitAtEquity)//(TimeCurrent()- OrderOpenTime() >= ActiveMinutes*60 )

{if(OrderType()==OP_BUY)

OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);

if(OrderType()==OP_SELL)

OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);

if(OrderType()>OP_SELL)

OrderDelete(OrderTicket());

StopTrade=true;}

}

if (dclose==dopen && OrdersTotal() < ConcurrentTrades && StopTrade != true)

As you can see, the EA looks at the Equity and then sets the bool value of the StopTrade variable to true. The EA then acknowledges the command and does not process anything under the StopTrade != true for one cycle, but then the bool value of the StopTrade gets reset I guess and trades continue.

Firstly, is there anyway for me to get this to do what I need it to do in the manner in which I am doing it?

Secondly, is there a function that I can use to simply tell the EA to quit?

All assistance is greatly appreciated.

NB.

cutzpr - How Many Currently open Buy, and Sell Orders from EA

I think part of my code can help you with what you need.

 

Well I had figured that a loop that would cycle threw all the open orders would be a start, but I wouldn't know what to tell the EA so that it will only look at the Orders placed by the EA and disregard the orders that I put in manually. Thanks.

 

Magic number

cutzpr - you need to use a magic number and then use something like the following:

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

{

OrderSelect(0,SELECT_BY_POS,MODES_TRADES);

if (OrderMagicNumber()==yourmagicnumber)

{if(OrderType()==OP_BUY)

 

Well taking a look at that code, I conjured up this piece of code below. I am not sure if it coded properly. I set up

int MaxLong=5,MaxShort=5;

extern double Magic=10000;

extern int MaxOpenOrders=10;

so..

if (b<=MaxLong)

{trade

}

if (s<=MaxShort)

{trade

}

But the EA is still sending out the max buy, and the max sell. Instead of counting how many orders there are of each and limiting itself to the MaxLong and Short. I know there must be something wrong with the code but I cant see it.

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

{

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber()==Magic)

{if(OrderType()==OP_BUY)

{

b++; // add order to Long Quantity

if(TP != 0)

{

if(b!= 0)

{

if(Bid >= ((OrderOpenPrice()+TP*Poin)+Spread))

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // Long position closed.

CMT=OrderCloseTime();

b--; // Long Order closed. Remove one order from total Longs

return(0);

}

}

}

}

if (OrderMagicNumber()==Magic)

{if(OrderType()==OP_SELL)

s++; // Add one to Short order Quantity

if (TP != 0)

{

if(s!= 0)

{

if(Ask <= ((OrderOpenPrice()-TP*Poin)+Spread))

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // Short position closed.

CMT=OrderCloseTime();

s--; // Short Order Closed. Remove one order from total shorts

return(0);

}

}

}

}

}
 
cutzpr:
Well taking a look at that code, I conjured up this piece of code below. I am not sure if it coded properly. I set up

int MaxLong=5,MaxShort=5;

extern double Magic=10000;

extern int MaxOpenOrders=10;

so..

if (b<=MaxLong)

{trade

}

if (s<=MaxShort)

{trade

}

But the EA is still sending out the max buy, and the max sell. Instead of counting how many orders there are of each and limiting itself to the MaxLong and Short. I know there must be something wrong with the code but I cant see it.

Well i think you are complicating things too much. Try using few shorter parts of code instead of one big function. This should give you some hint:

int totalOrders(int type)

{

int totalNumber = 0;

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

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == Magic && OrderType() == type) totalNumber++;

}

return(totalNumber);

}

[/CODE]

AND HERE IS EXAMPLE HOW YOU CAN USE IT

[CODE]

int totalBuy = totalOrders(OP_BUY);

int totalSell = totalOrders(OP_SELL);

if( (totalBuy + totalSell) < MaxOpenOrders)/*TOTAL NUMBER OF ORDERS WASN'T REACHED*/

{

if(totalBuy <= MaxLongOrders)

{

//OPENING LONG IS PERMITED

}

if(totalSell <= MaxShortOrders)

{

//OPENING SHORT IS PERMITED

}

}

 

[ASK] Indicator "SilverTrend_Signal"

I'm a beginner in forex and mql4 programming. I have a indicator SilverTrend_Signal (i attach here) and

i want to make an EA from this indicator but i have a problem with this indicator, the signal can change

in the same bar, such as the uptrend signal arrow appear in the chart then can disappear and maybe

change to the downtrend signal arrow in the same bar. Can someone help me to solve this problem?

I use this indicator in M1 time period and EU.

Thankyou very much.

(I'm sorry, my english is not good enough)

Files:
 

My personal opinion is that you should stay away from using indicators that repaint for signals. Especially on the M1 chart. Signals will change too often. You are just asking for non-stable signals and trouble. Past history looks good cause its the past.

 
willya:
I'm a beginner in forex and mql4 programming. I have a indicator SilverTrend_Signal (i attach here) and

i want to make an EA from this indicator but i have a problem with this indicator, the signal can change

in the same bar, such as the uptrend signal arrow appear in the chart then can disappear and maybe

change to the downtrend signal arrow in the same bar. Can someone help me to solve this problem?

I use this indicator in M1 time period and EU.

Thankyou very much.

(I'm sorry, my english is not good enough)

Not sure about how this one repaints but if it does ONLY on the current bar, then use the signal at bar (confirmed) close will be fine.

If it repaints more than the current bar, so you can forget to use its signal for an EA.

FerruFx

Reason: