How to code? - page 247

 

need help for hide_breakeven

Hi all, i have found this code for a hide trailing stop and want to make a hide breakeaven, it works, but it not close the order. I want close the order if the BID comes down from high and cross the BE HLINE, and not close if the BID is crossing the BE HLINE from down. I have done many examples but it not work like i want...please help me, here is the code for "buy":

void HideBreakEvenBuy(){

int totalorders = OrdersTotal();

for(int i=totalorders-1;i>=0;i--){

if (OrderSymbol()==OrderSymbol()){

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){

if (OrderType()==OP_BUY){

if (MarketInfo(OrderSymbol(),MODE_ASK)-OrderOpenPrice() >= breakeven*Point && ObjectGet("sl"+OrderTicket()+"b", OBJPROP_PRICE1) < OrderOpenPrice()){

ObjectCreate("BE"+OrderTicket()+"b", OBJ_HLINE, 0, 0, 0);

ObjectSet("BE"+OrderTicket()+"b", OBJPROP_PRICE1, OrderOpenPrice()+BE*Point);

ObjectSet("BE"+OrderTicket()+"b", OBJPROP_COLOR, Red);

ObjectSet("BE"+OrderTicket()+"b", OBJPROP_STYLE, 3);

}

if (MarketInfo(OrderSymbol(),MODE_ASK) -ObjectGet("BE"+OrderTicket()+"b", OBJPROP_PRICE1)

>= breakeven*Point && ObjectGet("BE"+OrderTicket()+"b", OBJPROP_PRICE1)

>= OrderOpenPrice() && ObjectGet("BE"+OrderTicket()+"b", OBJPROP_PRICE1) <MarketInfo(OrderSymbol(),MODE_ASK)){

//ObjectSet("BE"+OrderTicket()+"b", OBJPROP_PRICE1, MarketInfo(OrderSymbol(),MODE_ASK) -TrailingStop*Point);

if (OrderType() == OP_BUY && MarketInfo(OrderSymbol(),MODE_ASK) >= ObjectGet("BE"+OrderTicket()+"b", OBJPROP_PRICE1)) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), SlippageClose, Silver);

}

}

}

}

}

}

best regards go_rich

 

How to add a trailing Stop to existing Expert Advisor

How can I add a trailing Stop to an expert that already is done? This expert can be editing. Thanks for any help

 

2 indicators in One

Hi all, from few months I use strategy which is based on 2 indicators and brings me good profit( i use and fundamental with it), I am looking for someone which can connect these indicators in One for more convenience! If someone is interested please write on private, thanks

 
vladokvr:
Hi all, from few months I use strategy which is based on 2 indicators and brings me good profit( i use and fundamental with it), I am looking for someone which can connect these indicators in One for more convenience! If someone is interested please write on private, thanks

will somebody help me, or take an example how to make One indicator of Two, I think it will be interesting for many traders!

 

Previous Bars Calculation/Tester Freezing

Hello, I was wondering if someone could help me out with a quick EA code correction.

I need my EA to take the lowest price within the last 60 days and subtract it from the highest price within that same period. Once the difference is made, I would like the result to be multiplied by 1000 in order to get the desired range for my calculations.

For example, if the Highest price for EURUSD in the last 60 days was 1.30000, and the lowest price was 1.20000, the difference would be 0.1 (or 1000 pips). I would then multiply that 0.1 by 1000 to get my desired range of 100. (Basically for every 1000 pip trading range, I need a value of 100 for my calculations).

If the difference was 1250 pips, the value that I need would be 125.

Anyway, this is the code that I used:

double highval = High;

double lowval = Low;

int DesiredRange = NormalizeDouble(highval - lowval,3)*1000;

For some reason, in the strategy tester, it works fine for a short period. However, on certain dates, the tester just pauses and doesn't continue trading. It just freezes without stopping; and you have to manually stop the program and change the start date to the next day in order to continue.

Is there something wrong with my code? If I take the code above out, it works fine with a constant DesiredRange. At first I thought it could be because of rounding, but it seems to round correctly.

PLEASE HELP! Thanks in advance!

 

Why don't you use the Monthly timeframe and get the Highest and Lowest of the previous 2 months. 2 months equals the 60 days.

Getting the Highest value in this case is comparing only the High of the current candle and the High of the previous candle. The same for the Lowest.

jamesmean:
Hello, I was wondering if someone could help me out with a quick EA code correction.

I need my EA to take the lowest price within the last 60 days and subtract it from the highest price within that same period. Once the difference is made, I would like the result to be multiplied by 1000 in order to get the desired range for my calculations.

For example, if the Highest price for EURUSD in the last 60 days was 1.30000, and the lowest price was 1.20000, the difference would be 0.1 (or 1000 pips). I would then multiply that 0.1 by 1000 to get my desired range of 100. (Basically for every 1000 pip trading range, I need a value of 100 for my calculations).

If the difference was 1250 pips, the value that I need would be 125.

Anyway, this is the code that I used:

double highval = High;

double lowval = Low;

int DesiredRange = NormalizeDouble(highval - lowval,3)*1000;

For some reason, in the strategy tester, it works fine for a short period. However, on certain dates, the tester just pauses and doesn't continue trading. It just freezes without stopping; and you have to manually stop the program and change the start date to the next day in order to continue.

Is there something wrong with my code? If I take the code above out, it works fine with a constant DesiredRange. At first I thought it could be because of rounding, but it seems to round correctly.

PLEASE HELP! Thanks in advance!
 

This is not an easy task.

vladokvr:
will somebody help me, or take an example how to make One indicator of Two, I think it will be interesting for many traders!
 

Check Your Bars

jamesmean:
Hello, I was wondering if someone could help me out with a quick EA code correction.

I need my EA to take the lowest price within the last 60 days and subtract it from the highest price within that same period.

......

Anyway, this is the code that I used:

double highval = High;

double lowval = Low;

int DesiredRange = NormalizeDouble(highval - lowval,3)*1000;

Is there something wrong with my code? If I take the code above out, it works fine with a constant DesiredRange. At first I thought it could be because of rounding, but it seems to round correctly.

PLEASE HELP! Thanks in advance!

Hi James,

Edit - I deleted my suggestion. Not the right code (it was for iCustom's, not iHighest, iLowest). Still learning.

---

You may consider Codersguru's suggestion as well using the month period as it may give you a more accurate average.

Hope this helps,

Robert

 

Indicator, price breaks latest fractal

How to determine (by code) if price broke the last up or down fractal.

I have tried something with ifractals in mql but without success. I would like to identify the last of down fractal in my code.

I want to select the bar with the arrow on top in the attached chart by code, but I have no idea how to accomplish this. Any help is appreciated.

TIA !

Files:
chrt1.gif  23 kb
 

Forget the question about the fractal, I found a solution. THe problem is to determine the fractal you have to go back in time with a "for loop" which IMO results in a lot of overhead. But I am not a programmer so there are probably better solutions.

THNX

Reason: