How to code? - page 343

 
techmac:
Hidden stop loss and take profit are risky. If the EA does not work, nothing can close your EA - and EAs can be stopped from the broker side

Dear techmac,

can you explain more,why EA does not work,if EAs will not be checked and tested dozens times before to apply on live in general or at VPS...........(nothing can close your EA) did not understand what did you means ??? ....(and EAs can be stopped from the broker side)....for what other reasons broker can stop it when EA is applied with the brokers permission/agreeing. if you means due to some of hidden parameters reasons ?

regards

 
mladen:
Yes. When the stop loss field of the order is set to some value (then that line is displayed) and when it is brokers responsibility to execute the stop loss at desired price (unlike the "soft" "hidden" stop loss, when it is your EA that has to close the order)

Dearest MLADEN,

thank you,so kind of you,understand exact,how that work in real.

is there any way and possibility that our EA trying to execute TP/SL in case of hidden sl/tp at some point/level and some hidden activities (coded in brokers software that handles clients trading activities, allow or denoy processing further) from broker side stopping it doing so?

lol,so in this case,who is more reliable,effective and responsible EA or broker... ....as for the reputations of brokers now a days...soft wares and non human feelings equipment's are more sincere and loyal. .

regards

 
mntiwana:
Dearest MLADEN,

thank you,so kind of,understand exact,how that work in real.

lol,so in this case,who is more reliable,effective and responsible EA or broker... ....as for the reputations of brokers now a days...soft wares and non human feelings equipment's are more sincere and loyal. .

regards

The thing is the following :

In the case of SNB, if people were using "hidden" "soft" stop loss, they had no ground whatsoever to get refunded for anything (since they did not fill the stop loss field, the broker had no obligation at all to do something with those orders). While those that did have that field filled, also did have some grounds for a complaint - not that they got everything back, but at least they could do something

 
mladen:
The thing is the following : In the case of SNB, if people were using "hidden" "soft" stop loss, they had no ground whatsoever to get refunded for anything (since they did not fill the stop loss field, the broker had no obligation at all to do something with those orders). While those that did have that field filled, also did have some grounds for a complaint - not that they got everything back, but at least they could do something

Dearest MLADEN,

again thanks for your expert eye on things....so all in all ....traders loss is confirm,due to any and only a lil bit reason when gain is doubtful in any and every case....things go like this way, now a days.it is usual.

one question boss,when market price fall or rise so speedy same as light speed....is there any chance and possibility that all our loss breakers ( BE,SL and trailing stop) might be ignored/rejected/pass through ....or....they work effectively by all means in any circumstances.

regards

 
mntiwana:
Dearest MLADEN,

again thanks for your expert eye on things....so all in all ....traders loss is confirm,due to any and only a lil bit reason when gain is doubtful in any and every case....things go like this way, now a days.it is usual.

one question boss,when market price fall or rise so speedy same as light speed....is there any chance and possibility that all our loss breakers ( BE,SL and trailing stop) might be ignored/rejected/pass through ....or....they work effectively by all means in any circumstances.

regards

mntiwana

It should not happen, but by all means, read the contract that you have with broker. Specifics about things like that must be stated in the contract

 

What is the simplest way yo check crossing of two values?

 
apprentice coder:
What is the simplest way yo check crossing of two values?

It depends on the values you are comparing. Can you give a specific example?

 
mladen:
It depends on the values you are comparing. Can you give a specific example?

For example : cross of two averages

 

Hi, I am having some problems with my EA and have seem to hit a dead end. Would appreciate if someone could help me with this matter. I am trying to get my EA to trigger only 1 trade a day. Basically this is a breakout EA that will open a trade once the candle break out by a certatin amount of pips. However, I can't seem to get the EA to trigger only 1 trade a day.

​Currently my EA will trigger another trade on the same candle again if the conditions are met again after my trade has already TP or SL.

Appreciate if anyone could help me with this matter. Thanks.

Below is my programming.

Regards

//---- input parameters

extern double TakeProfit = 1000.0;

extern double Lots = 0.1;

extern double StopLoss = 980.0;

extern int Entry_Hour_1st = 21;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//+------------------------------------------------------------------+

//-- Trigger Trade

//+------------------------------------------------------------------+

int ticket, total;

double TP_Value, SL_Value;

total = OrdersTotal(); // check for total number of trades currently open

if(total < 1)

{

if (Hour()==Entry_Hour_1st && ((High[0] - High[1]) > 0.00100) && ((High[1] - Low[1]) > 0.00100))

{

if ((Close[1] - Open[1]) > 0.00100)

{

TP_Value = (Close[1] - Open[1]); // value of long body

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

if ((Open[1] - Close[1]) > 0.00100)

{

TP_Value = (Open[1] - Close[1]); // value of short body

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

if ((Open[1] - Close[1]) <= 0.00100)

{

TP_Value = (High[1] - Low[1]); // value of whole candle including head and tail

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

}

if (Hour()==Entry_Hour_1st && ((Low[1] - Low[0]) > 0.00100) && ((High[1] - Low[1]) > 0.00100))

{

//-------------------------------------------------------//

//-------- if H7 long candle body more than 10pips --------//

//-------------------------------------------------------//

if ((Close[1] - Open[1]) > 0.00100)

{

TP_Value = (Close[1] - Open[1]); // value of long body

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

if ((Open[1] - Close[1]) > 0.00100)

{

TP_Value = (Open[1] - Close[1]); // value of short body

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

if ((Open[1] - Close[1]) <= 0.00100)

{

TP_Value = (High[1] - Low[1]); // value of whole candle including head and tail

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

}

}

return(0);

}

}

//+------------------------------------------------------------------+

 
tkuan77:
Hi, I am having some problems with my EA and have seem to hit a dead end. Would appreciate if someone could help me with this matter. I am trying to get my EA to trigger only 1 trade a day. Basically this is a breakout EA that will open a trade once the candle break out by a certatin amount of pips. However, I can't seem to get the EA to trigger only 1 trade a day.

​Currently my EA will trigger another trade on the same candle again if the conditions are met again after my trade has already TP or SL.

Appreciate if anyone could help me with this matter. Thanks.

Below is my programming.

Regards

//---- input parameters

extern double TakeProfit = 1000.0;

extern double Lots = 0.1;

extern double StopLoss = 980.0;

extern int Entry_Hour_1st = 21;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//+------------------------------------------------------------------+

//-- Trigger Trade

//+------------------------------------------------------------------+

int ticket, total;

double TP_Value, SL_Value;

total = OrdersTotal(); // check for total number of trades currently open

if(total < 1)

{

if (Hour()==Entry_Hour_1st && ((High[0] - High[1]) > 0.00100) && ((High[1] - Low[1]) > 0.00100))

{

if ((Close[1] - Open[1]) > 0.00100)

{

TP_Value = (Close[1] - Open[1]); // value of long body

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

if ((Open[1] - Close[1]) > 0.00100)

{

TP_Value = (Open[1] - Close[1]); // value of short body

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

if ((Open[1] - Close[1]) <= 0.00100)

{

TP_Value = (High[1] - Low[1]); // value of whole candle including head and tail

SL_Value = (Low[1] - 0.0010); // always the same for long

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,SL_Value,Ask+TP_Value,"My EA",200,0,Green);

return(0);

}

}

if (Hour()==Entry_Hour_1st && ((Low[1] - Low[0]) > 0.00100) && ((High[1] - Low[1]) > 0.00100))

{

//-------------------------------------------------------//

//-------- if H7 long candle body more than 10pips --------//

//-------------------------------------------------------//

if ((Close[1] - Open[1]) > 0.00100)

{

TP_Value = (Close[1] - Open[1]); // value of long body

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

if ((Open[1] - Close[1]) > 0.00100)

{

TP_Value = (Open[1] - Close[1]); // value of short body

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

if ((Open[1] - Close[1]) <= 0.00100)

{

TP_Value = (High[1] - Low[1]); // value of whole candle including head and tail

SL_Value = (High[1] + 0.0010); // always the same for short

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,SL_Value,Bid-TP_Value,"My EA",200,0,Red);

return(0);

}

}

}

return(0);

}

}

//+------------------------------------------------------------------+

tkuan77

You have to find the last closed bar and to see if the day of the last closed bar is the same as the current day.

You can use something like this function to get the last closed order time :

datetime GetLastClosedOrderTime()

{

datetime CloseTime = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderCloseTime()>CloseTime)

CloseTime = OrderCloseTime();

}

return(CloseTime);

}

And then you can check if the date is the same

Reason: