Coding help - page 20

 

exit base MACD

Mr guru, can you help me to make this EA close base on MACD cross 0.

i have edit but too difficult 4 me... thank you very much

Files:
1428maplus.mq4  30 kb
 

Looking for help with writing a no hedge piece of code

Hi,

I'm hoping to get some help with a slice of coding. I have a support and resistance system and I'm trying to edit the ea to include the option of hedging. (Since I live in the US and am with a no-hedge broker).

I know that when my EA is activated and I have an open order, the opposite pending order will automatically be deleted. The problem is, I can't properly backtest and tweak the system because the Strategy Tester doesn't have hedge/no hedge options.

So, I'm trying to edit the code to include that option. Obviously I need to put in a bool and set it to false (which Ive done), but I'm not sure where to go from there.

The EA is a typical support/resistance EA. It places pending orders x distance from either the support or resistance. Using an example, if the market is in a down trend and hits my pending sell and turns it into a market order, and then the trend reverses, I need to delete pending buy orders (or disallow pending buy orders) until the sell order is closed.

The EA also deletes pending orders on an expiration timer and at the end of the inputted trading hours. I wasn't sure if I could modify some of that code to do what I'm thinking of.

Here's the code from the EA that deletes the pending orders. Is there some way I could modify this to do what I'm trying to do, or if not can someone point me in the right direction?

void deletebuypending(int magic)

{

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber()==magic &&

OrderType()==OP_BUYSTOP)

{

OrderDelete(OrderTicket());

}

}

}

void deletesellpending(int magic)

{

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber()==magic &&

OrderType()==OP_SELLSTOP)

{

OrderDelete(OrderTicket());

}

}

}

Any help or pointing me in the right direction is appreciated.

 

Thank you for trying to assist me (by again moving my thread without comment). I read through this thread, but didn't see anything pertaining to what I was asking. I started trying to write the code myself.

I think I'm sort of on the right track. I've written this piece of code, but what happens is pending sell orders (sell stop orders) are deleted as soon as they are placed, whether there is an active buy order or not.

Still hoping someone can assist me.

if (hedge==false)

{

int total = OrdersTotal();

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

{

OrderSelect(m, SELECT_BY_POS);

int type=OrderType();

int type1=OP_BUY;

int type2=OP_BUYSTOP;

int type3=OP_SELL;

int type4=OP_SELLSTOP;

if(type==type2 && type1>0)

{

OrderDelete(OrderTicket());

}

if(type==type4 && type3>0)

{

OrderDelete(OrderTicket());

}

}

}

 

Hi Gregwendland,

Guess you can say then this is my belated comment, we try to keep things somewhat organized in the forum, and seemed you needed coding help so thats where i moved you, the coding help section, reason i didn't comment was thinking where i moved you would speak for itself and i couldn't offer any help to your coding question,anyway hope you find someone to help you.

 

Thank you, MrTools.

I appreciate it. I understood what you were doing by moving my thread. I just didn't find any answers in the previous posts. I'm still working at it. I think I've got it. It seems to be allowing an active order and deleting the opposite pending order. As well as switching between the two.

if (hedge==false)

{

int total = OrdersTotal();

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

{

OrderSelect(m, SELECT_BY_POS);

if(OrderType()==OP_BUY)

{

deletesellpending(magic);

}

if(OrderType()==OP_SELL)

{

deletebuypending(magic);

}

}

}

[/PHP]

Now, it sort of brings up another question. The EA places objects and connecting lines to show where an order was opened and closed. With setting up the deletepending this way, My chart actually gets filled with continuous Sell/Buy Stop indicators immediately followed by closing/deleted indicators. This continues until there is no longer an open position.

So, what I'd like to try now is to figure out if I can put in a check at the ordering function to stop a pending order from even being placed. This will create a cleaner chart screen for me.

I know I figured that one out on my own, but I'm still looking for help since I am not very good with programming languages.

This is the Order Function:

[PHP]

if((count(OP_BUYSTOP,magic)+count(OP_BUY,magic))<maxtrades && buy && tpb<tradesperbar && IsTradeAllowed())

{

// -- Taken out coding to shorten post

ticket=OrderSend(Symbol(),OP_BUYSTOP,ilots,resistance+distance*pt,slippage*mt,sl,tp,comment+"Bid: "+DoubleToStr(Bid,5),magic,expire,Blue);

if(ticket<=0)

{

Print("Error Occured : "+errordescription(GetLastError()));

}

else

{

tps++;

Print("Order opened : "+Symbol()+" Buy @ "+Ask+" SL @ "+sl+" TP @"+tp+" ticket ="+ticket);

}

}

if((count(OP_SELLSTOP,magic)+count(OP_SELL,magic))<maxtrades && sell && tpb<tradesperbar && IsTradeAllowed())

{

// -- Taken out coding to shorten post

ticket=OrderSend(Symbol(),OP_SELLSTOP,ilots,support-distance*pt,slippage*mt,sl,tp,comment+"Ask: "+DoubleToStr(Ask,5),magic,expire,Red);

if(ticket<=0)

{

Print("Error Occured : "+errordescription(GetLastError()));

}

else

{

tpb++;

Print("Order opened : "+Symbol()+" Sell @ "+Bid+" SL @ "+sl+" TP @"+tp+" ticket ="+ticket);

}

}

I was thinking if I put in something like && OP_SELL==false (or OP_BUY==false in the sell order section). Is that the right idea?

 

Bar Counter for MT4 - IndicatorCounter

Hello there to all.

This is my first post.

I need help from anyone who can.

I have developed my first MT4 EA using a code generator plus modifying it after compiling and I'm trying to:

1. After Entry, exit the trade after eg. 15 bars.

2. The number of bars to exit is changeable in the "extern int" section.

The EA trades on the specified RSI parameters and currently exits on TP, SL and TS (trailing stop).

I would like to also exit for eg. when 10 or 15 bars have elapsed.

I have tried like crazy but cannot get it to work.

I really appreciate if someone could help me please.

I have attached the EA for anyone to take a look.

cheers and Best regards

cj

 
freefreecj:
Hello there to all.

This is my first post.

I need help from anyone who can.

I have developed my first MT4 EA using a code generator plus modifying it after compiling and I'm trying to:

1. After Entry, exit the trade after eg. 15 bars.

2. The number of bars to exit is changeable in the "extern int" section.

The EA trades on the specified RSI parameters and currently exits on TP, SL and TS (trailing stop).

I would like to also exit for eg. when 10 or 15 bars have elapsed.

I have tried like crazy but cannot get it to work.

I really appreciate if someone could help me please.

I have attached the EA for anyone to take a look.

cheers and Best regards

cj

Hi Cj,

Moved you over here, hopefully you will find a solution here in this thread or someone will drop by and help.

 

Thanks MrTools

Thanks MrTools

 

Hi all,

I need an Indicator which can give a sound and box alert for

a) Buy when Low crosses above 34 EMA of Highs upwards

b) Sell When High crosses 34 EMA of Lows downwards

Can someone help me out please?

Any kind of help will be appreciated.

Thanks in advance

regards

Sahilsri

 

...

Mladen...why Squize MA doesn't show bands where arrow is...to my understanding it has to show bands when MA's come within a certain distance to each other?

Files:
a.tpl  2 kb
a_2.jpg  161 kb