How to code? - page 170

 
Roger09:
Look at

double NormalizeDouble( double value, int digits)

If you put digits=2, you can see what you want.

Hi,

I think i wasn't very clear. For example:

- If current price is 1.3756, the code should return 56

- If current price is 99.22, the code should return 22

- If current price is 1.4499, the code should return 99

Basically, I'm trying to return the value of the last two digits, regardless if quote is 4 decimal or 2 decimal place.

NomalizeDouble only rounds up the price to specified Digits placing.

Anyone has any ideas?

 
musical:
Hi,

I think i wasn't very clear. For example:

- If current price is 1.3756, the code should return 56

- If current price is 99.22, the code should return 22

- If current price is 1.4499, the code should return 99

Basically, I'm trying to return the value of the last two digits, regardless if quote is 4 decimal or 2 decimal place.

NomalizeDouble only rounds up the price to specified Digits placing.

Anyone has any ideas?

ОК

double lasttwonumbers=(Bid-MathFloor(Bid/(Point*100))*Point*100)/Point;

 
1Dave7:
How do I create an EA that will close out any open ticket order from multiple EA's if SL is 10 Pips or greater??

Dave

<<<

Myfxidea is candlestick pattern charting service and provide expert advisor for mt4

 
Roger09:
ОК double lasttwonumbers=(Bid-MathFloor(Bid/(Point*100))*Point*100)/Point;

Works like a charm. Thank you for all your help

 

Help with Trailling Stop / 1 Risk or Position M

Hi all,

i have tried do search in the forum a solution for my Problem:

At the begin of my EA:

//---- buy conditions

if(Ask > mybuyconditions)

{

ticket=OrderSend(Symbol(),OP_BUY,LotsLong(),Ask,Spread,Bid-(Ask-lowestof10bars),((BBupper-BBlower)/(Ask-lowestof10bars))*1000,"Einstieg 1",magic+1,0,Green);

}

//---- sell conditions

if(Bid < mysellconditions)

{

ticket=OrderSend(Symbol(),OP_SELL,LotsShort(),Bid,Spread,Ask+(highestof10bars-Bid),((BBupper-BBlower)/(highestof10bars-Bid))/100,"Einstieg -1",magic-1,0,Red);

}

//----[/CODE]

Stopploss: its easy 10 bars hi/lo

Takeprofit: here i write my formula for my Trailingstop, and that is:

Take the differenz of BBupper - BBlower at the order open time. Then divide by StopLoss in Pips and you have an Factor. Then take the actual BB differenz and divide it by this Faktor. NOW WE HAVE OUR VOLA BB TRAILINGSTOPP!!!!!

SO, my big problem is now to save this FAKTOR!!!! I saved it in th Takeprofit of Ordersend, it works but it is not right!!!!!

And know the 2te Question:

Position Management:

so my order is open and i have my trailing stopp that trails : So and now if the trailingstop is > orderopenprice send next ORDER!!! It's logical because so i can always sicure to risk just my 1 R Risk.

.... if Trailingstopp is > orderopenprice of secondOrder send 3te order.

HERE MY EXAMPLES:

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

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+1)

if(OrderStopLoss()< Bid-(oben-unten)/(OrderTakeProfit()/1000))

{

OrderModify(OrderTicket(),OrderOpenPrice(),High-(oben-unten)/(OrderTakeProfit()/1000),OrderTakeProfit(),0,Indigo);

return;

}

if(OrderStopLoss() > OrderOpenPrice() && CalculateCurrentOrders(Symbol()) == 1)

{

ticket1=OrderSend(Symbol(),OP_BUY,LotsLong(),Ask,Spread,Bid-(Ask-Low),((oben-unten)/(Ask-Low))*1000,"Einstieg 2",magic+2,0,Green);

return;

}

}

{

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+2 && CalculateCurrentAfterOrders(Symbol()) <= 1)

{

if(OrderStopLoss()<Bid-(oben-unten)/(OrderTakeProfit()/1000))

{

OrderModify(OrderTicket(),OrderOpenPrice(),High-(oben-unten)/(OrderTakeProfit()/1000),OrderTakeProfit(),0,Indigo);

return;

}

if(OrderStopLoss() > OrderOpenPrice() && CalculateCurrentOrders(Symbol()) == 2)

{

ticket2=OrderSend(Symbol(),OP_BUY,LotsLong(),Ask,Spread,Bid-(Ask-Low),((oben-unten)/(Ask-Low))*1000,"Einstieg 3",magic+3,0,Green);

return;

}

}

{

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+3 && CalculateCurrentAfterOrders(Symbol()) <= 2)

{

if(OrderStopLoss()< Bid-(oben-unten)/(OrderTakeProfit()/1000))

{

OrderModify(OrderTicket(),OrderOpenPrice(),High-(oben-unten)/(OrderTakeProfit()/1000),OrderTakeProfit(),0,Indigo);

return;

}

}

}

}

[CODE] if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+1)

{

{

OrderModify(OrderTicket(),OrderOpenPrice(),High-(oben-unten)/(OrderTakeProfit()/1000),OrderTakeProfit(),0,Indigo);

return;

}

if(OrderStopLoss() >= OrderOpenPrice() && CalculateCurrentOrders(Symbol()) == 1)

{

ticket1=OrderSend(Symbol(),OP_BUY,LotsLong(),Ask,Spread,0,0,"Einstieg 2",magic+2,0,Green);

return;

}

}

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+2)

{

if(OrderStopLoss() >= OrderOpenPrice() && CalculateCurrentOrders(Symbol()) == 2)

{

ticket2=OrderSend(Symbol(),OP_BUY,LotsLong(),Ask,Spread,0,0,"Einstieg 3",magic+3,0,Green);

return;

}

}

}

{

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+2)

{

if(CalculateCurrentOrders(Symbol()) == 0)

{

OrderClose(ticket1,OrderLots(),Ask,Spread,Red); return;

}

}

}

if(OrderType()==OP_BUY && OrderMagicNumber() == magic+3)

{

OrderClose(i,OrderLots(),Ask,Spread,Red); return;

}

I hope someone can help me with this problem!!!!! Thanks to all.

 

Adding Code When position goes against you "x" pips add additional lot with fixedtpsl

hi

i did a lot of studies and i found out it may be good to add this function to my EA

When position goes against you "20" pips add additional lot "0.1" with own TP and SL input

is it possible to realize ??

Also this Ea is very good but it only opens BUYS

maybe ad "sell" logic

please help me

Files:
_v1.2.mq4  6 kb
 

Need Help With a Programming Problem

How can you program Metatrader 4 to exit the previous position and open the new position on the SAME bar if you set EachTickMode to false? When you set EachTickMode to True it automatically does this but when you set it to false it will close the previous position on one bar and then will wait for the next bar to open the new position. I use the

H4 timeframe and waiting 4 more hours to open a new position after the signal is given is unacceptable. My system is too sensitive to use EachTickMode=True. Any help anyone can give me with this would greatly be appreciated.

 

Help needed to get past Ordersend error 130

Below is my buy function. If I set variable order_type to 1 (for market order), it works, so I know my stoploss and takeprofit functions are working. The problem must be in the determination of price for the op_buylimit order. I am trying to calculate my order price by decreasing Ask by a percentage of the length (pct_of_length) of the candle body (at bar 1). I have tried a slew of coding variations (some including NormalizeDouble), but I cannot get beyond the error 130. Can anyone help? I am using IBFX, by the way.

Thanks in advance!

bool place_buy_order() {

int ticket, length_in_pips, offset_in_pips;

double buy_limit_price;

// pct_of_length is an external integer, currently set to 10

if ( order_type == 2 && pct_of_length > 0 )

{

length_in_pips = MathAbs(High[1]-Low[1]) * MathPow(10,Digits);

offset_in_pips = MathRound(length_in_pips * (pct_of_length/100));

buy_limit_price = Ask - offset_in_pips * Point;

ticket = OrderSend(Symbol(),OP_BUYLIMIT,LotSize(),buy_limit_price,0,stoploss("b",buy_limit_price),takeprofit("b",buy_limit_price),"",MAGICMA,0,Blue);

}

else

// market order

ticket = OrderSend(Symbol(),OP_BUY,LotSize(),Ask,Slippage,stoploss("b",Ask),takeprofit("b",Ask),"",MAGICMA,0,Blue);

if ( ticket == -1 ) return(false); else return(true);

}

 

Have you tried printing out the various variables, TP, SL etc, and seeing if they are being set correctly? That might give you a clue where the problem lies.

Lux

 
stocktrader24202:
How can you program Metatrader 4 to exit the previous position and open the new position on the SAME bar if you set EachTickMode to false? When you set EachTickMode to True it automatically does this but when you set it to false it will close the previous position on one bar and then will wait for the next bar to open the new position. I use the H4 timeframe and waiting 4 more hours to open a new position after the signal is given is unacceptable. My system is too sensitive to use EachTickMode=True. Any help anyone can give me with this would greatly be appreciated.

EachTickMode is a variable that the EA's original coder included SPECIFICALLY so you could choose either to open on the same candle OR open on the next.

It sounds like the EA is doing EXACTLY what it was designed for so I'm not sure what your problem is.

You say it works the way you want when you set the variable to true so whats the problem? Just set the variable to true.

Lux

Reason: