Question Regarding Array

 

Hello,

This may sound abit stupid to professional coder but is it not possible to use variable as array, as there will be invalid index value (i tried understanding it but i seem to not be able to)

Example Code would be 

input int FASTEMA = 50;

int start()
        { 
        blah blah blah
        double MAXIMUM[FASTEMA];
        blah blah blah
        {

However, if it use

int start()
        { 
        blah blah blah
        double MAXIMUM[50];
        blah blah blah
        {

It works, can somebody explain why I cannot substitute FASTEMA for 50?

And whether there is a way to make it substitutable? 

Thank you.

 

You must use a constant when declaring and sizing an array at the same time.

Otherwise declare the array and size it.

input int FASTEMA = 50;

int start()
        {
        double MAXIMUM[];
        ArrayResize(MAXIMUM,FASTEMA);
        {
 
Keith Watford:

You must use a constant when declaring and sizing an array at the same time.

Otherwise declare the array and size it.

Hey, can i ask 1 more question?


Is it possible to close position if the indicator's color change? i.e. closing position on indicator's color not the indicator's value

 
hyunjeshin:

Hey, can i ask 1 more question?


Is it possible to close position if the indicator's color change? i.e. closing position on indicator's color not the indicator's value

Indicators don't have a colour.

Indicators may use objects or lines etc and these may have a colour.

If a line/histogram has 2 colours, then it may use 2 buffers. You will need to check the values of both buffers to see which colour is showing for the particular bar. 

 
Keith Watford:

Indicators don't have a colour.

Indicators may use objects or lines etc and these may have a colour.

If a line/histogram has 2 colours, then it may use 2 buffers. You will need to check the values of both buffers to see which colour is showing for the particular bar. 

Oh yeap, so in my code, when indicator is rising, the buffer color is green, when fall = red, when sideway = white.

Is it possible to code in a way that will close my current position if the buffer color turns red?


Also, is there a way to limit opening position that would allow only 1 long and 1 short position?

Sorry for having so many questions. 

 
hyunjeshin:

Oh yeap, so in my code, when indicator is rising, the buffer color is green, when fall = red, when sideway = white.

Is it possible to code in a way that will close my current position if the buffer color turns red?

A buffer colour does not change, a buffer is either displayed or not displayed.

Find out which buffer is the red buffer and check its value. Usually if it is not displayed, its value will be EMPTY_VALUE, so if it has a different value, the line etc is being displayed as red.

 
Keith Watford:

A buffer colour does not change, a buffer is either displayed or not displayed.

Find out which buffer is the red buffer and check its value. Usually if it is not displayed, its value will be EMPTY_VALUE, so if it has a different value, the line etc is being displayed as red.

I see, I will try different ways to see if it works or not.


Also, is there a way to limit opening position that would allow only 1 long and 1 short position?

 
hyunjeshin:

Also, is there a way to limit opening position that would allow only 1 long and 1 short position?

Yes.

Show your code and you will receive some help.

 
Keith Watford:

Yes.

Show your code and you will receive some help.

Currently its 

//Long
      if((Bars > BarsCount) && (OrdersTotal() == 0))
      {
         if(SecondCustom > ThirdCustom)
         if(Custom> SecondCustom)
         if(Custom< MaxLongCustom)
         {
            LongOrder();
         }
//Short//

         if(ThirdCustom> SecondCustom )
         if(SecondCustom > Custom)
         if(MaxShortCustom < Custom)
         {
            ShortOrder();
         }      
      }

Currently, the only way i know to limit order is with OrdersTotal(), however is there other way to limit opening position to allowing maximum of 1 long and short positions (1 of each)?

 
hyunjeshin:

Currently its 

Currently, the only way i know to limit order is with OrdersTotal(), however is there other way to limit opening position to allowing maximum of 1 long and short positions (1 of each)?

Count the buys and sells first and use the results

   int buys=0,sells=0;
   for(int x=OrdersTotal()-1; x>=0; x--)
     {
      if(OrderSelect(x,SELECT_BY_POS))
         if(OrderType()==OP_BUY)
            buys++;
         else if(OrderType()==OP_SELL)
            sells++;
     }
 

Work like a Charm! Thank you!

Back to the "Find out which buffer is the red buffer and check its value. Usually if it is not displayed, its value will be EMPTY_VALUE, so if it has a different value, the line etc is being displayed as red."

How do I check my iCustom's buffer value? Currently I have three colors, Green, Red, White. (Buffer 1 = Green, Buffer 2 = Red, Buffer 3 = White).

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
The CLR_NONE constant is used to outline the absence of color, it means that the graphical object or graphical series of an indicator will not be plotted. This constant was not included into the Web-color constants list, but it can be applied everywhere where the color arguments are required. The EMPTY_VALUE constant usually corresponds to the...
Reason: