Ask! - page 32

 

Dave,

Don't give up that easily. If I tell you what to do, it maybe wrong and you will never learn the right thing.

Here is another try.

Good luck.

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

{

OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

}

 

how do i know if my order hit a stop-loss?

Hi guys

I am programming an EA that uses a trailing-stop. The thing is that when it hits a stop-loss then it opens a new order. So, the question is that how to tell the EA that when an order hits a stop-loss then wait for the next bar to decide if you want to open a new order?? anyhelp please?

 
 
iscuba11:
Where does the modification take place in this?? The original stop loss was 40, and the take profit was 100. As a part of the sleep mode, the stop loss is to change to 15 on any existing open orders and the take profit is to change to 25 on any existing open orders.

Open Order Tickets:Prior to sleep mode.

Before Sleep Mode Stop Loss - 40 Before Sleep Mode Take Profit-100 After Sleep Mode Stop Loss Modification -15 After Sleep Mode Take Profit Modification - 25

I am not initializing order settings, I am modify existing orders already placed and still active.

Thanks for you help anyhow! Why does something so simple seem so difficult?

Dave <<

how do you define your sleep mode?

just add it before the ordermodify() loop

like..

if(sleepcome)

{

for(.....)

{

//delete my code gave you before or make it as comment

orderselect(.....);

.

.

.

}

}

may this help

 
AnasFX:
Hi guys I am programming an EA that uses a trailing-stop. The thing is that when it hits a stop-loss then it opens a new order. So, the question is that how to tell the EA that when an order hits a stop-loss then wait for the next bar to decide if you want to open a new order?? anyhelp please?

check the trade history if the ordercloseprice() = orderstoploss() then it close by hit the sl

for(int hcnt=0;hcnt<HistoryTotal();hcnt++)

{

OrderSelect(hcnt, SELECT_BY_POS, MODE_HISTORY);

if(OrderSymbol()==Symbol())

{

if(OrderClosePrice()==OrderStopLoss())

.

.

.

}

}

 

Time of stop-loss

phoenix:
check the trade history if the ordercloseprice() = orderstoploss() then it close by hit the sl

for(int hcnt=0;hcnt<HistoryTotal();hcnt++)

{

OrderSelect(hcnt, SELECT_BY_POS, MODE_HISTORY);

if(OrderSymbol()==Symbol())

{

if(OrderClosePrice()==OrderStopLoss())

.

.

.

}

}

Thanks for the idea man. I also wants to know the time of its stop-loss and if that time is in the current bar. I may have lots of stop-losses, but I want to know if it hits the stop-loss in the current time bar. Should I check the order close time and compare it with the time of the current bar?

 

showing Buys and Sells on an EA

I'd like to put arrows or text objects or something on the chart while my EA is running to show it's actions, but the objects don't seem to appear. Anybody got a working EA example that draws on the chart?

Also, the Strategy Tester has a button to display a chart after a test is run, but I'm not seeing the arrows. Is this a problem with build 195, because I know I've seen them there in the past. How can we modify these arrow objects? I'd like to make them bigger, but don't know how to get at the chart in the tester either.

I guess both problems are the same: getting user feedback from EAs.

 

I have an expert that I'm tweaking and wanted to avoid an entry signal if the previously closed bar was extremely long. (>30 pips) I added the phrase below as a condition but it didn't seem to be recognized. I'm not a good coder but have luck with adjusting experts and am learning as I go. Could someone tell me what logic or phrase I should use here?

Under the section;

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

void CheckForSignals() {

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

I included the condition;

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

if ((Close[1])-(Open[1])<30 ) {

buysig=true;

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

Thanks for any suggestions,

MJ

 
marketjouster:
I have an expert that I'm tweaking and wanted to avoid an entry signal if the previously closed bar was extremely long. (>30 pips) I added the phrase below as a condition but it didn't seem to be recognized. I'm not a good coder but have luck with adjusting experts and am learning as I go. Could someone tell me what logic or phrase I should use here?

if ((Close[1])-(Open[1])<30 ) ...

MJ

MJ,

Assuming that Close[1] is for instance 1.2835 and Open[1] is at 1.2805 (bullish bar), the difference is 0.0030 so checking against 30 won't work. Furthermore what if Close[1] is at 1.2805 and Open[1] at 1.2835 (bearish bar)? You'll get -0.0030.

So first of all you need to use Close[1]-Open[1] < (30*Point) to remediate to the first problem, and then you have to use the MathAbs() function to get the absolute value of the subtraction.

In short use: if MathAbs(Close[1]-Open[1])<(30*Point) ....

HTH

Yannis

 

Code to avoid Long Bar trade entry

Yannis:
MJ,

Assuming that Close[1] is for instance 1.2835 and Open[1] is at 1.2805 (bullish bar), the difference is 0.0030 so checking against 30 won't work. Furthermore what if Close[1] is at 1.2805 and Open[1] at 1.2835 (bearish bar)? You'll get -0.0030.

So first of all you need to use Close[1]-Open[1] < (30*Point) to remediate to the first problem, and then you have to use the MathAbs() function to get the absolute value of the subtraction.

In short use: if MathAbs(Close[1]-Open[1])<(30*Point) ....

HTH

Yannis

Thanks very much Yannis. Your explanation is very clear and I appreciate the inclusion of the actual code. Could I pose a follow-up question? If I wanted to be able to adjust the number of pips for the long bar in the expert advisors properties window, could I use;

extern int LBE=30; // LBE is 'Long Bar Entry'. Default could be 30

in the header section of the expert and then use LBE instead of 30 in your line of code?

if MathAbs(Close[1]-Open[1])<(LBE*Point)

This would allow me to test variant pip settings manually, and to optimize it in back testing.

MJ

Reason: