How to code? - page 175

 

Your system sounds a bit crazy......

extern double Lots=0.1;

extern int TP=50;

extern int SL=50;

extern int timeframe=1;

extern bool close=false;

extern int Slippage=2;

extern int Magic=46151;

int init()

{

return(0);

}

int deinit()

{

return(0);

}

datetime LastTradeTime = 0;

int start()

{

int time=60*timeframe;

if(LocalTime()-LastTradeTime > time) {

if(close==true) {

if(OrdersTotal()!=0) {

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

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderType()==OP_SELL && OrderMagicNumber()==Magic) { OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage, Green ); }

if(OrderType()==OP_BUY && OrderMagicNumber()==Magic) { OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage, Red ); }

} } }

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Ask - SL * Point, Ask + TP * Point, NULL, Magic, 0, Green);

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid + SL * Point, Bid - TP * Point, NULL, Magic, 0, Red);

LastTradeTime = LocalTime(); }

return(0);

}

If "close" is true, it will close the open orders at the end of the timeframe (in this case 1 minute). SL/TP=100 means 10pips at a 5digit broker.

By the way, I'm not sure if it will open both orders immediately.

Is it possible to close and open (or to open 2 positions) at the same time?

This works fine in backtests of course, but I don't know if it works on a demo/live account.

 

i've NEVER been able to get that to work with any broker...

i've added delays and confirmation code to check if orders were closed and opened, if not try again.

even then, still not working correctly consistently

 

This appears to be a problem for many strategies. Is there anyone that found a solution for this problem?

 

trailing stop issue

I have yen pairs that when I try to use my trailing stop; move my price to "zero" after going in profit. Can anyone tell me why that occurs and how to fix? The trail order works fine on 5 digit currencies.

void TrailOrder(int type)

{

if(TrailingStop>0)

{

if(OrderMagicNumber() == MagicNumber)

{

if(type==OP_BUY)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop),OrderTakeProfit(),0,Green);

}

}

}

if(type==OP_SELL)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*TrailingStop),OrderTakeProfit(),0,Red);

}

}

}

}

}

}

 
ajk:
I have yen pairs that when I try to use my trailing stop; move my price to "zero" after going in profit. Can anyone tell me why that occurs and how to fix? The trail order works fine on 5 digit currencies.

I think (it's my opinion only) it's because you have a function and this function doesn't know anything about OrderOpenPrice(), OrderStopLoss() etc. You better put this code inside the loop.

 
ajk:
I have yen pairs that when I try to use my trailing stop; move my price to "zero" after going in profit. Can anyone tell me why that occurs and how to fix? The trail order works fine on 5 digit currencies.

Possibly a diligent use of NormalizeDouble(...) would make a difference?

 

how to code two indicators cross with different scales

how to code two indicators cross with different scales?

i want help

 

I will give anything a shot. Its strange because coder guru coded the ea and I modified. I looked through tons' of ea's and can't find anything.

 

any suggestion on how to write the code after the

void TrailOrder(int type)

calling function?

Maybe take out function completely and use external e trailing ea...argh>!

 
ajk:
any suggestion on how to write the code after the

void TrailOrder(int type)

calling function?

Maybe take out function completely and use external e trailing ea...argh>!

If you want I can fix your EA. Send me it on PM.

Reason: