Coding help - page 109

 

pending order modify

Hey everyone, I tried to programm a price modify for pending orders. Its one of my first EAs. I want to write as many EAs so that I can write complex ones later on. With my order modify I have the problem that it is not working when I put it into a chart on my demo-account. Can anyone find mistakes and help me by correcting it? Thanks. I really have no more clues. Cheers

{ RefreshRates(); double ppoint=MarketInfo(OrderSymbol(), MODE_POINT); int total=OrdersTotal(); double pBid=MarketInfo(OrderSymbol(), MODE_BID); double pAsk=MarketInfo(OrderSymbol(), MODE_ASK); double priceNew; //---- for(int i=0; i50*ppoint) { priceNew=(pBid-50*ppoint); OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit()); Print("Modified Order"); } } } if (OrderType()==OP_SELLSTOP) { if (OrderOpenPrice()-pAsk>50*ppoint) { priceNew=(pAsk+50*ppoint); OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit()); Print("Modified Order"); } } } } }
 

Hey Robert, thanks for ur help so far. How do I properly post code here? Thanks and cheers.

 
fabian103:
Hey Robert, thanks for ur help so far. How do I properly post code here? Thanks and cheers.

fabian103

You should do a simple copy and paste at that php code box

For some reason your code is "all over the place". Try it. If it does not work try attaching the part of the code you want to be revised as a separate file (using the attachment tool - the one pointed out at the picture)

Files:
attach.gif  36 kb
 

Hi,

I've been trying to calculate the value of the bollinger bands inside the stochastic indicator but I haven't been able to do that.

I get the value referred to the pair, but I need the value that should be between 0 and 100.

Any pointer?

Thanks

 
metcalfe:
Hi,

I've been trying to calculate the value of the bollinger bands inside the stochastic indicator but I haven't been able to do that.

I get the value referred to the pair, but I need the value that should be between 0 and 100.

Any pointer?

Thanks

I assume that you mean calculating Bollinger bands of a stochastic (using stochastic values instead of symbols prices). You can not do that with a built in iBands() because it always uses main chart prices.

You could use iBandsOnArray() but with it you have an eternal metatrader problem : deviations can be only integer multipliplicators. You can not set deviations to fractional values. So, the best is to use iStdDevOnArray() and iMaOnArry() functions to calculate your own Bollinger bands of any value and with any width of the bands. In case of stochastic the code that does that would look like this :

for(int i=limit; i>=0; i--) stoch = iStochastic(NULL,0,StochPeriod,1,StochSlowing,MODE_SMA,StochPrice,MODE_MAIN,i);

for( i=limit; i>=0; i--)

{

double dev = iStdDevOnArray(stoch,0,BollingerPeriod,0,MODE_SMA,i);

bollmi = iMAOnArray(stoch,0,BollingerPeriod,0,MODE_SMA,i);

bollup = bollmi+BollingerDeviations*dev;

bolldn = bollmi-BollingerDeviations*dev;

}

Attaching the indicator itself too, so you can continue experimenting with it. It looks like this on the the chart :

____________________

PS: values of bands can exceed the 0 and 100 bounds (in cases when Stochastic is hovering around 0 or 100) depending on what bands multiplier you use for deviations and what is the length of the Bollinger bands calculation itself

 
mladen:
I assume that you mean calculating Bollinger bands of a stochastic (using stochastic values instead of symbols prices). You can not do that with a built in iBands() because it always uses main chart prices.

You could use iBandsOnArray() but with it you have an eternal metatrader problem : deviations can be only integer multipliplicators. You can not set deviations to fractional values. So, the best is to use iStdDevOnArray() and iMaOnArry() functions to calculate your own Bollinger bands of any value and with any width of the bands. In case of stochastic the code that does that would look like this :

That is SUPER AWESOME!!!!!

Thanks very much, I have been trying for so long.

And thanks for the super fast reply.

One more stupi question.

The indi works very fine but I can't get the right number on the ea about the bands value.

For instance like in the pic you've attached the numbers 81...67..54....

 
metcalfe:
That is SUPER AWESOME!!!!!

Thanks very much, I have been trying for so long.

And thanks for the super fast reply.

One more stupi question.

The indi works very fine but I can't get the right number on the ea about the bands value.

For instance like in the pic you've attached the numbers 81...67..54....

:):)

Stochastic length on that example is set to 32. That is the only difference compared to default parameters

 
mladen:
:):):) Stochastic length on that example is set to 32. That is the only difference compared to default parameters

Sorry..I didn't explain very well what I wanted to ask.

In my ea I am trying to get the number for example of upper or lower band in the stoch window like in the picture. For instance I want in the ea retrieve the upper band that is 81.8116 and I coded as

Comment(iCustom(NULL,0,"name",24,0,MODE_UPPER,0)); \\renamed the indi

but I don't have the right number.

Where am I wrong?

Thanks

 
metcalfe:
Sorry..I didn't explain very well what I wanted to ask.

In my ea I am trying to get the number for example of upper or lower band in the stoch window like in the picture. For instance I want in the ea retrieve the upper band that is 81.8116 and I coded as

Comment(iCustom(NULL,0,"name",24,0,MODE_UPPER,0)); \\renamed the indi

but I don't have the right number.

Where am I wrong?

Thanks

Do it like this :

double upperBand = iCustom(NULL,0,"name",24,1,0,0);[/PHP]

The problem was that you can not put 0 in place of the slowing parameter since in that case metatrader will cause an error when calculating stochastic, and you will always get 0 as a return value, so use 1 instead (it is equivalent to no smoothing of the stochastic value). Also, better to use buffer numbers (MODE_MAIN is a reserved word in MQL - it 0 but in some cases they are not what you expect them to be). To get the rest of the values you would then have to write something similar to this :

[PHP]double middleBand = iCustom(NULL,0,"name",24,1,1,0);

double lowerBand = iCustom(NULL,0,"name",24,1,2,0);
 

Ok...

Super thanks.

You saved me....

Reason: