Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
Harami57
50
Harami57 2015.03.10 19:37 

Hello All,

I have an EA running on M5 TF.

Start function is:

int start()
  {
  if(IsNewCandle())
      {
      CheckForSMTrade();
      if(OpenOrdersThisPair(Symbol())>=1)
         {
         MangageTrade();
         if(UseMoveToBreakEven)MoveToBreakEven();
         if(UseTrailingStop)AdjustTrail();
         if(Use_MA_Trail)MATrail();
         }
      }
   return(0);
  } 


In ManageTrade() function there is this code:

 if(OrderType()==OP_SELLLIMIT||OrderType()==OP_SELLSTOP)
                              
                 if(IsNewCandle())
                   {
                                
                   double Sell_Price = NormalizeDouble((iMA(NULL,60,20,0,0,1,0)),4);

etc.


I need the value of the iMA for the current (0) H1 but the value appears to be for the previous. e.g. at 19:34 GMT the H1 is 1.5078 but Sell_Price above is 1.5081 (the 19:00 level).

Hope someone can point out how to remedy this...

Thx

Carl Schreiber
6397
Carl Schreiber 2015.03.10 19:45  

Have you read the reference abut iMA?

double  iMA(
   string       symbol,           // symbol
   int          timeframe,        // timeframe
   int          ma_period,        // MA averaging period
   int          ma_shift,         // MA shift
   int          ma_method,        // averaging method
   int          applied_price,    // applied price
   int          shift             // shift
   );

so your:

iMA(NULL,60,20,0,0,1,0)

is the most recent iMA(..) of

1) chart symbol,

2) H1 period (not 5 min)

3) 20 bars

4) shift=0

5) SMA

6) PRICE_OPEN (not closed?)

7) most recent bar 0

Is this what you want to have?

Harami57
50
Harami57 2015.03.10 19:57  
gooly:

Have you read the reference abut iMA?

so your:

is the most recent iMA(..) of

1) chart symbol,

2) H1 period (not 5 min)

3) 20 bars

4) shift=0

5) SMA

6) PRICE_OPEN (not closed?)

7) most recent bar 0

Is this what you want to have?


Yes have read the reference...but

2) Yes Price is H1

3) Yes 20 bars

4) Yes shift=0

5) Yes Simple

6) I want the current (i.e. new candle every 5M) value for the H1. Not Open etc. Is this the Close? Whilst I've been writing this post the value for the 20 SMA on Cable has  been 1.50782, then 1.50783 etc. I need the value of this whatever it is, every 5M candle...

7) I use 0 thinking that is the current as per (6)

Not sure where this is going wrong....?!

Carl Schreiber
6397
Carl Schreiber 2015.03.10 20:59  
it's all explained in the editor's reference - follow the links!
Keith Watford
Moderator
9548
Keith Watford 2015.03.10 23:23  

 PRICE_OPEN refers to the open of the bar and will always be the same

 

 PRICE_CLOSE refers to the close of the bar, for the current bar, it is the current price 

Harami57
50
Harami57 2015.03.12 18:39  
GumRai:

 PRICE_OPEN refers to the open of the bar and will always be the same

 

 PRICE_CLOSE refers to the close of the bar, for the current bar, it is the current price 

Ok GumRai, thx for that.

I had a look over the code and there was a problem elsewhere - I'd used PRICE_OPEN (Value 1 not 0 as it should have been). From now on I'm going to use the ID not Value to make it clearer... ;-)
Carl Schreiber
6397
Carl Schreiber 2015.03.12 22:38  
Harami57:

Ok GumRai, thx for that.

I had a look over the code and there was a problem elsewhere - I'd used PRICE_OPEN (Value 1 not 0 as it should have been). From now on I'm going to use the ID not Value to make it clearer... ;-)
and have a look in the reference before asking! You'll find your answers a lot faster!
Harami57
50
Harami57 2015.03.12 23:05  
gooly:
and have a look in the reference before asking! You'll find your answers a lot faster!
Where here https://docs.mql4.com/indicators/ima (which I already looked at) is the answer given by GumRai to the original question, i.e. the one you didn't answer?! Thanks for trying anyway...;-)
Carl Schreiber
6397
Carl Schreiber 2015.03.13 07:53  

1) Well didn't you see the link there of:

applied_price

[in]  Applied price. It can be any of ENUM_APPLIED_PRICE enumeration values?

2) Too many people ask without reading the reference (or forum-searching, or googeling) where they would have find the solution of their problem!

3) The examples there (and elsewhere) are very good examples from where they could learn a lot more than just the answer of their question!

4) Therefore I want to help the people to solve their problem on their own but answering every simple question.

Harami57
50
Harami57 2015.03.13 08:50  
gooly:

1) Well didn't you see the link there of:

applied_price

[in]  Applied price. It can be any of ENUM_APPLIED_PRICE enumeration values?


Where does it say there:
GumRai:

 PRICE_OPEN refers to the open of the bar and will always be the same

 

 PRICE_CLOSE refers to the close of the bar, for the current bar, it is the current price 

It doesn't.....that's why I asked the question!

Maybe you should read the reference yourself before posting? Just a suggestion....;-)

Carl Schreiber
6397
Carl Schreiber 2015.03.13 08:55  

it doesn't??

PRICE_CLOSE        0          Close price
PRICE_OPEN         1          Open price

And if you don't understand Close price and Open price you'd better start reading the whole book you might lose a lot of money.

/ /12
To add comments, please log in or register