akuh: So whenever "changeofTrend ==1" occurs ...
if ( 1 == 0 ) { |
|
|
Hi whroeder1,
i just checked the return values from and got it right right now, without using changeofTrend.
"
- If you want if(changeofTrend) why did you write if(1 == 0) ?"
if(1 ==0) is just a there to let the EA execute without sending an error. Its just a spaceholder for a closing condition which can be set by the programmer. Thats why its said above"replace 1==0 to your conditions". Below you see my condition which works well.
Ticket = OrderClose ( Ticket, OrderLots(), OrderClosePrice(), Slippage, Red );
I would like to ask another question. Whats the correct function to call up the current market price ? i havent found an example till now. My idea is, that i want to code a buystop and sellstop condition. THe buystop condition is fulfilled when the market price moves below the supertrend value (in Uptrend) and a sellstop when the market price moves above the supertrend value (in downtrend). I tried it with MarketInfo() with the bid and ask values but they dont return the right values.
double vbid = MarketInfo("EURUSD",MODE_BID);
double vask = MarketInfo("EURUSD",MODE_ASK);
// Here you can place indicators and all stuff // For ex. if you want to play 0.5 Lot with 1000$ account you can write MathRound ( AccountBalance() / 20 ) / 100;
// Which will calculate when script should buy or sell.
double up = iCustom(NULL,0,"HalfTrend_1",4,1);
//Print("vask:", vask);
double down = iCustom(NULL,0,"HalfTrend_1",5,1);
//Print("vbid:", vbid);
double tu = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,0,0);
// Print("supertrendup:", tu);
double td = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,1,0);
//Print("supertrenddown:", td);
double tuu = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,0,1);
double tdd = iCustom(NULL,0,"super-trend",Nbr_Periods,Multiplier,1,1);
RefreshRates(); // RefreshRate() update Bid and Ask value.
if ( ( Ask - Bid ) / Point < MaxSpread ) { // Checking, if spread is less than MaxSpread from inputs. If its Bigger, orders wont open
// Replace 1 == 0 to your conditions to buy order.&& LastOT==1
if ( 0.01<up && up<5 && tuu>0.01 && tuu<5 && OrderType()==OP_SELL && LastOrder != 1 ) { // LastOrder!= 1 prevent script from making a lot of same buy orders
Ticket = OrderSend ( Symbol(), OP_BUY, Lots, Ask, Slippage, Ask - ( StopLoss * Point ), Ask + ( TakeProfit * Point ), NULL, Magic, 0, Green);
LastOrder = 1; // It prevent script from making a lot of same buy orders
}
// Replace 1 == 0 to your conditions to buy order.&& LastOT==1
if ( tuu> vask && LastOrder != 1 ) { // LastOrder!= 1 prevent script from making a lot of same buystop orders
Ticket = OrderSend ( Symbol(), OP_BUYSTOP, Lots, Ask + ( Pips * Point ), Slippage, Ask + ( Pips * Point ) - ( StopLoss * Point ), Ask - ( Pips * Point ) + ( TakeProfit * Point ), NULL, Magic, TimeCurrent() + ( 60 * Mins ), Green);
LastOrder = 1; // It prevent script from making a lot of same buy orders
}
// Replace 1 == 0 to your conditions to sell order.&& LastOT==0
if ( 0.01<down && down<5 && tdd>0.01 && tdd<5 && OrderType()==OP_BUY && LastOrder != 0 ) { // LastOrder!= 0 prevent script from making a lot of same sell orders
Ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, Bid + ( StopLoss * Point ), Bid - ( TakeProfit * Point ), NULL, Magic, 0, Red);
LastOrder = 0; // It prevent script from making a lot of same sell orders
}
// Replace 1 == 0 to your conditions to sell order.&& LastOT==0
if ( tdd<vbid && LastOrder != 0 ) { // LastOrder!= 0 prevent script from making a lot of same sellstop orders
Ticket = OrderSend ( Symbol(), OP_SELLSTOP, Lots, Bid - ( Pips * Point ) , Slippage, Bid - ( Pips * Point ) + ( StopLoss * Point ), Bid + ( Pips * Point ) - ( TakeProfit * Point ), NULL, Magic, TimeCurrent() + ( 60 * Mins ), Red);
LastOrder = 0; // It prevent script from making a lot of same sell orders
}
}
I would be very thankful for an idea.
cheers
akuh
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
For my EA i want to read out a specific value from an indicator. For my case, i want to read out the int "changeofTrend" from the super-trend indicator. So whenever "changeofTrend ==1" occurs or is true, i want to the close the last order! The super-trend indicator i use is in the attachement.
Here you find my code for closing buy and sell positions:
I would be very thankful for a hint or advice !
RefreshRates(); // RefreshRate() update Bid and Ask value.
// Calculate Trailing Stop.
if ( Bid >= OrderOpenPrice() + TrailingStart * Point && OrderStopLoss() < Bid - ( TrailingStop * Point ) ) {
Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), Bid - ( TrailingStop * Point ), OrderTakeProfit() , 0 );
}
// Calculate BA.
if ( Bid >= OrderOpenPrice() + Ba * Point && Bid < OrderOpenPrice() + ( Ba ) * Point ) {
Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + ( failsafe * Point ), OrderTakeProfit() , 0 );
}
// Replace 1 == 0 to conditions to close Buy order.
if ( 1==0 ) {
Ticket = OrderClose ( Ticket, OrderLots(), OrderClosePrice(), Slippage, Green );
}
}
if ( OrderType() == OP_SELL ) {
RefreshRates(); // RefreshRate() update Bid and Ask value.
// Calculate Trailing Stop.
if ( Ask <= OrderOpenPrice() - TrailingStart * Point && OrderStopLoss() > Ask + ( TrailingStop * Point ) ) {
Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), Ask + ( TrailingStop * Point ), OrderTakeProfit(), 0 );
}
// Calculate BA.
if ( Ask <= OrderOpenPrice() - Ba * Point && Ask > OrderOpenPrice() - ( Ba ) * Point ) {
Ticket = OrderModify ( OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - ( failsafe * Point ) , OrderTakeProfit(), 0 );
}
// Replace 1 == 0 to conditions to close Sell order.
if ( 1 == 0 ) {
Ticket = OrderClose ( Ticket, OrderLots(), OrderClosePrice(), Slippage, Red );
}
}