How to code? - page 157

 

thanks wolfe!

thanks for your answer and the book! its new to me so i will dig in to it and learn some more. i will then post the next version of my ea or anouther question if i hit a road block.

Eric

 

Time fixing of an object

I wondered if anyone could tell me how to time fix an object (such as an arrow) so when I change the chart TF the arrow would remain at the original time. Similar to drawing a vertical line and then changing chart TF. Thanks.

 

how to change or remove .00

double HiPrice2 = iHigh(NULL,NULL,1);

double LoPrice2 = iLow (NULL,NULL,1);

double Rangehilo= (HiPrice2-LoPrice2);

if (Digits < 4) Rangehilo = Rangehilo * 100; else Rangehilo = Rangehilo * 10000;

Comment("\n","Range: ",DoubleToStr(Rangehilo,2)+" pip","\n");

I try to create range PIP between high and low,but it show like this

->> Range: 37.00 pip

My question is,how to remove .00?so it will just show 37pip only?

thanks

 

NormalizeDouble(var1,0);

Lux

PS: Just noticed your code: DoubleToStr(Rangehilo,0) - change the 2 to 0

 
luxinterior:
NormalizeDouble(var1,0);

Lux

PS: Just noticed your code: DoubleToStr(Rangehilo,0) - change the 2 to 0

Ohohhh,just a small mistake..thanks luxinterior!

 

adding stdev bands

Hi, sorry for the stupid question, but pls help me out here:

If you have any indicator that consists of 1 line in the chart window, and you want to add standard deviation bands to that line, like Bollinger bands. How do you do this:

let's say your buffer that plots your original indicator is named abc

so first you declare these:

extern int BandsPeriod=20;

extern int BandsShift=0;

extern double BandsDeviations=2.0;

1) you change

#property indicator_buffers 1 (1 becomes 3)

2)

SetIndexBuffer(0,abc);

SetIndexStyle(0,DRAW_LINE);

and add

SetIndexBuffer(1,UpperBuffer);

SetIndexStyle(1,DRAW_LINE);

SetIndexBuffer(2,LowerBuffer);

SetIndexStyle(2,DRAW_LINE);

SetIndexDrawBegin(0,BandsPeriod+BandsShift);

SetIndexDrawBegin(1,BandsPeriod+BandsShift);

3) you add the rest of the bollinger bands code into the initialization loop

int start()

{

int i,k,counted_bars=IndicatorCounted();

double deviation,sum,oldval,newres;

//----

if(Bars<=BandsPeriod) return(0);

//---- initial zero

if(counted_bars<1)

and so on....

4) but how the heck do you replace the buffer called MovingBuffer in the original bands.mq4 code by your new buffer from your indicator, called "abc"?

What's the best way to go about this?

Should I try to get my indicator code into the bands.mq4 code or the other way around?

I attached a well-known piece of code called bands.mq4 so you can see what I'm working with.

again, sorry for my coding-ignorance

Maybe someone knows of a 'adding stdev bands tutorial' ? That would be what I need right now. Thx

Files:
bands.mq4  3 kb
 
 

Coding for an EA

Hello all,

I would like to create some coding that will keep an EA from trading if it has already had a profitable trade for the current trading session.

I have a number of EA's that I built that allow me to choose the opening time and closing time for trading each day. The EA also only does anything on the opening of each new bar. So, if I have a trade going and it is closed because it either hit my stop loss or my take profit, the EA will wait until the opening of the next bar before opening a new trade.

For example, I have the EA set to trade between 6:00 AM and 2:00 PM on a one hour chart. At 6:00 AM a trade is opened. At 9:23, my take profit is hit and the trade is closed. At 10:00 AM a new trade will be opened and will remain open until either the new stop loss or take profit is hit, or the time reaches 2:00 PM, at which time the trade is closed and trading is done for the rest of the day.

What I would like the EA to do is not only recognize the time of day but also recognize whether I have already had a winning trade during the trading session. So, in the example above, even though it is still during the trading time period for the day, the EA would not open a new trade at 10:00 AM because a profit has already been made. On the other hand, if it was my stop loss that was hit in the above example, the EA would open a new trade at 10:00 AM because no profit was made yet.

I'm thinking that I would need to use the "OrderSelect" function along with the "Mode_History" parameter to look at previously closed trades and then compare the opening price to the closing price for the order to determine whether a profit or loss was realized. Does that sound about right? Being a novice at programming, I am not sure if that is the best way to approach the problem and if it is, it will take me a long, long time to get it in the correct format to work properly.

If anyone could help me out or at the least, just give me some insights or ideas on how to tackle this problem, I would be grateful. If my example doesn't make any sense, let me know and I will try to explain it better.

Thanks in advance for any help that is offered.

Ron

 

Checking for order losses...

On this site, at this link https://www.mql5.com/en/forum/176053/page25 is a copy of the DIN_Kukus_EA_V2.6. If you view the EA's contents, you will find a function that checks for order losses in your order history, just as you have discribed doing for yourself. You can use this working example of how to extract the number of successful trades from your order history. You can modify it to extract history for a particular period of time as well, but I hope this will help you see how to accomplish what you propose to do for yourself...

 

wanting to use indicator results in EA

Hello All,

The Gliding_Channels indicator puts current channel data in comment area of the Data Window. It tells the vertical depth of channel on the current bar, the angle of the channel (both positive and negative), the high limit and the low limit. I want to see that data, however it conflicts with the data my EA shows in the comment area causing my comments to flicker.

I tried to add a SetIndexBuffer for each of the four datum in the indicator so I could reference them in my EA using iCustom. I was only able to bring one of the four values into my EA comments that way. (I also continued to have the flickering problem).

Would anybody please show me the correct way to access those four indicator results in my EA?

In my EA, I will be calling these four values "depth, angle, limitHI, and limitLO."

Reason: