Coding help - page 16

 
nontan:
Hi,genius coder & kind people:D

Now I'm developing a simple EA but can't understand below conditions.

If previous position is closed by Take Profit,make new entry that set 20 pips by s/l and t/p at next open price.(on 5M chart)

I tried to write one.

if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)) //Last position was instant order OP_BUY or OP_SELL

{

if(OrderClosePrice() == OrderTakeProfit()) // IF close price is the same with take profit price

{

if(OrderType() == OP_BUY) //That order's order type is buy

{

OrderSend(OP_BUY,Lots,Ask,Slippage,SLpips,Ask+20*Point,"",MAGIC);// Lots and other variables is defined by my self

}

else if(OrderType() == OP_SELL)

{

OrderSend(OP_SELL,Lots,Bid,Slippage,SLpips,Bid-20*Point,"",MAGIC);

}

}

I tried many time run by Strategy tester,but can't action as I'm hoping.

Some body give me a help from this question!!

Regards.

[lang=pl]Hi,

Can you attache whole code of EA?

Cheers,

Grzesiek[/lang]

 

...

Try using this in comparison

if (NormalizeDouble(OrderClosePrice(),Digits) == NormalizeDouble(OrderTakeProfit(),Digits))

maybe that helps

nontan:
Hi,genius coder & kind people:D

Now I'm developing a simple EA but can't understand below conditions.

If previous position is closed by Take Profit,make new entry that set 20 pips by s/l and t/p at next open price.(on 5M chart)

I tried to write one.

if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)) //Last position was instant order OP_BUY or OP_SELL

{

if(OrderClosePrice() == OrderTakeProfit()) // IF close price is the same with take profit price

{

if(OrderType() == OP_BUY) //That order's order type is buy

{

OrderSend(OP_BUY,Lots,Ask,Slippage,SLpips,Ask+20*Point,"",MAGIC);// Lots and other variables is defined by my self

}

else if(OrderType() == OP_SELL)

{

OrderSend(OP_SELL,Lots,Bid,Slippage,SLpips,Bid-20*Point,"",MAGIC);

}

}

I tried many time run by Strategy tester,but can't action as I'm hoping.

Some body give me a help from this question!!

Regards.
 

Thank you guys.

I tried to insert NormarizeDouble but was not works..

Would you teach me why don't work it?

---------------------------------------------------

#include

#define MAGIC 20120101

#define COMMENT "Riding9"

extern double Lots = 0.1;

extern int Slippage = 3;

extern int SLpips = 20;

extern int TPpips = 50;

extern int StartTime = 1;

extern int FinishTime = 23;

extern int MAPeriod = 48;

int EntrySignal(int magic)

{

double pos = MyCurrentOrders(MY_OPENPOS, magic);

double Ma9 = iMA(NULL, 0, MAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

int ret = 0;

if((pos <= 0) && (Close[3] Open[2] && Open[2] >= Ma9) || (Open[2] Ma9)) && (Close[1] > Open[1] && Open[1] > Ma9)) ret = 1;

else if((pos <= 0) && (Open[3] Ma9) && (Close[2] Ma9) && (Close[1] > Open[1] && Close[1] > Ma9)) ret = 1;

if((pos >= 0) && (Close[3] >= Ma9) && ((Close[2] < Open[2] && Open[2] Ma9 && Close[2] < Ma9)) && (Close[1] < Open[1] && Open[1] < Ma9)) ret = -1;//

else if((pos >= 0) && (Open[3] > Ma9 && Close[3] Open[2] && Open[2] < Ma9) && (Close[1] < Open[1] && Close[1] < Ma9)) ret = -1;

return(ret);

}

bool MyOrderSendSL(int type, double lots, double price, int slippage, int slpips, int tppips, string comment, int magic)

{

int mult=1;

if(Digits == 3 || Digits == 5) mult=10;

slippage *= mult;

if(type==OP_SELL || type==OP_SELLLIMIT || type==OP_SELLSTOP) mult *= -1;

double sl=0, tp=0;

if(slpips > 0) sl = price-slpips*Point*mult;

if(tppips > 0) tp = price+tppips*Point*mult;

return(MyOrderSend(type, lots, price, slippage, sl, tp, comment, magic));

}

int start()

{

if(Hour() >= StartTime && Hour() < FinishTime)

{

int sig_entry = EntrySignal(MAGIC);

if(sig_entry > 0)

{

MyOrderClose(Slippage, MAGIC);

MyOrderSendSL(OP_BUY, Lots, Ask, Slippage, SLpips,TPpips, COMMENT, MAGIC);

}

if(sig_entry < 0)

{

MyOrderClose(Slippage, MAGIC);

MyOrderSendSL(OP_SELL, Lots, Bid, Slippage, SLpips,TPpips, COMMENT, MAGIC);

}

if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY))

{

if (NormalizeDouble(OrderClosePrice(),Digits) == NormalizeDouble(OrderTakeProfit(),Digits))

{

if(OrderType() == OP_BUY)

{

OrderSend(OP_BUY,Lots,Ask,Slippage,SLpips,Ask+20*Point,"",MAGIC);

}

else if(OrderType() == OP_SELL)

{

OrderSend(OP_SELL,Lots,Bid,Slippage,SLpips,Bid-20*Point,"",MAGIC);

}

}

}

return(0);

}

return(0);

}

------------------------------------------------------

Please teach me my wrong if you discover.

Regards.

 

...

nontan,

This line
if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY))

[/PHP]

Does not select the last closed order but the first (after the initial balance) order in the closed orders queue. So, it is always checking one fixed order instead of checking what was the last order and then accommodating to it. If you wish to test the last order closed (last in the closed orders queue, but be aware that metatrader [people do not guarantee that it is the last when sorted by close date-time) you should use this form of checking
[PHP]if (OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
 

Thank you,mladen

I haven't yet used OrderHistoryTotal function.It's a proper one for this code.

At last,I have got a desire code after modified.As result EA works to make new entry after got TakeProfit.

Thank you for your corporate & all.

 

I need your help master coders

hello, please i need someone to help me code my strategy

 
johnray:
hello, please i need someone to help me code my strategy

[lang=pl]Just give me a details

Cheers[/lang]

 

i sent a pm

g.pociejewski:
[lang=pl]Just give me a details Cheers[/lang]

thanks master i sent a you a pm.. its a little bit complicated

 

Code for auto refresh

I am using an indicator that needs constant refresh. I am using a 15 minute chart so it does not need to refresh every tick, although that would be nice if there is not a big power drain. It should at least have an option for time interval between each refresh. Right now I manually refresh every minute or so by using the drop down 'Charts' tab and selecting 'Refresh'.

Is there a code or way to refresh the indi and/or chart automatically, either through additional code in the indi or in an EA?

Thanks, el bee

 

[langtitle=fr]Original indicator Parabolic Sar by Wilder[/langtitle]

[lang=fr]
Hi!

I'm searching for the ORIGINAL parabolic SAR, quiproquo by Wilder. I have made the code of this indicator for PRT platform, but i don't know coding in MT4.

If someone has knowledge in MT4 coding, i can give the code by private message, to adapt this in MT4 coding.

Thanks
[/lang]
Reason: