Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 930

 
silachara:

DiPach , thanks again for your help. I have analysed your examples. Made some changes to my startup code. The result is this:

What was changed:

1. moved the line containing int awd1[]; array declaration inside OnStart() function

2. Added the ArrayResize(awd1,6,7) function;

3. The script works.

I will try to draw conclusions. In scripts, it is correct to declare arrays inside the OnStart() function. After the array is declared, it must be necessarily defined in size using the ArrayResize() function; otherwise the compiler will generate an error. Are my conclusions correct? If not, please give me a correct interpretation.

Generally speaking, yes. And it will work, at least silently, but very well. :)

I will only specify the following points:

1. When declaring normal variables and arrays, I think you should consider what the script (or EA/indicator) is going to do and what these variables/arrays are intended for.

Your attached script workflow allows for declaration of variables not on a global program level, but locally. That is, the array is declared once. We don't need looped declarations in the Start() body, for example, before starting the for() loop and when we need further declaration of some variables after for() {}:


Accordingly, the array is declared not at the level of global variables of the program but in the body of OnStart() before the for() loop's statement - it is quite acceptable in this scheme of program execution.

From my point of view, if there's no need to declare something at the level of global variables in a program, we'd better use this opportunity and declare everything we can locally.

2. As for the code, let me make it clear:

void OnStart()
  {
   int awd1[];
   ArrayResize(awd1,6,7);
   for(int i=0;i<6;i++)
     {
      awd1[i]=i+10;
      Print("awd1[",i,"]=",awd1[i]);
     }
   string text=StringConcatenate("awd1[0]=",awd1[0],", awd1[1]=",awd1[1],", awd1[2]=",awd1[2],
                                 ", awd1[3]=",awd1[3],", awd1[4]=",awd1[4],", awd1[5]=",awd1[5]);
   Alert(text);
  }

That is:

  • You should not use the <= sign (less than equal) in for. I mean where it was (i=0;i<=5;i++). Just put a <(less than) sign and replace 5 with 6:
for(int i=0;i<6;i++)

That's the way 5 would be appropriate for for:

for(int i=5;i>=0;i--)
  • I remember encountering information before that Stringconcatenate function contributes to faster processing of long text. That's why I usually use it in my code. I have added it here too, just in case.


P./S.: One more clarification, just in case, using ArrayResize() - for dynamic arrays. In the documentation to this function , there is information when this function cannot resize dynamic arrays.

 
Best_ATS:
Why can't I add friends?
And how do you imagine a friend without knowing him or her personally in life, from work?
 

Hello! How can I make the new price be shown first and the previous price drop to the bottom and so on? I made an example to make it clear.

double NN=0;
double NN1=0;
double NN2=0;
double NN3=0;
void OnTick()
  {
//---
if(Ask>NN)NN=Ask;
if(NN>NN1)NN1=NN;
if(NN1>NN2)NN2=NN1;
if(NN2>NN3)NN3=NN2;
        Comment(""       
             + "1.   "+"Buy: "" Max: " + DoubleToStr(NN,5)
             + "\n"  
             + "2.   "+"Buy: "" Max: " + DoubleToStr(NN1,5)
             + "\n"  
             + "3.   "+"Buy: "" Max: " + DoubleToStr(NN2,5)
             + "\n"  
             + "4.   "+"Buy: "" Max: " + DoubleToStr(NN3,5)
             + "\n"
             + "------------------------------------------------" );
           
  }
 
abeiks:

Hello! How can I make the new price be shown first and the previous price drop to the bottom and so on? That would be clear made an example.

I made an example, and with the conditions more or less you can figure it out yourself:

double bda_Price[4];
void OnTick()
{
      int li_int;
//---
    if (Ask > bda_Price[0])
    {
        ArrayInitialize (bda_Price, 0.);
        bda_Price[0] = Ask;
        double lda_Price[3];
        ArrayCopy (lda_Price, bda_Price, 0, 1);
        for (int li_int = 1; li_int < 4; li_int++)
        {bda_Price[li_int] = lda_Price[li_int-1];}
    }
    string ls_txt;
    StringInit (ls_txt, 100);
    for (li_int = 0; li_int < 4; li_int++)
    {ls_txt = StringConcatenate (ls_txt, (string) li_int, ".   Buy:  Max: ", DoubleToStr (bda_Price[li_int], Digits), "\n");
    ls_txt = StringConcatenate (ls_txt, "------------------------------------------------" );
    Comment (ls_txt);
//---
}
 
TarasBY:

I've made an example, and you can work out the terms more or less on your own:


Thank you!
 
abeiks:

Hello! How can I make the new price be shown first and the previous price drop to the bottom and so on? To make it clear, I made an example.

Here is a completely primitive code.

double Price1, Price2, Price3, Price4;

void OnTick()
  {
Price4=Price3;
Price3=Price2;
Price2=Price1;
Price1=Ask;
Comment(Price1, "\n", Price2, "\n", Price3, "\n", Price4);
  }
 
silachara:

Here's a perfectly primitive code made.




Thank you!
 

Hi all. Tried to open a trade order in the strategy tester using a rudimentary script, failed.

int start()

{

//----

int res;

double ask=Close[0]+MarketInfo(_Symbol,MODE_SPREAD)*Point;

res=OrderSend(Symbol(),OP_BUY,0.1,ask,3,0,0,",0,0,Blue);

if(res>-1)Alert("Open BUY order with ticket ",res);

//----

return(0);

}

I put the script on the tester chart in visualization mode, but the trade order opens in MT4 terminal.

I also cannot get information about open orders in the strategy tester using SimpleFXTester_v2.ex4.

Please help me to understand this.

 
kosmos0975:

Hi all. Tried to open a trade order in the strategy tester using a rudimentary script, failed.

int start()

{

//----

int res;

double ask=Close[0]+MarketInfo(_Symbol,MODE_SPREAD)*Point;

res=OrderSend(Symbol(),OP_BUY,0.1,ask,3,0,0,",0,0,Blue);

if(res>-1)Alert("Open BUY order with ticket ",res);

//----

return(0);

}

I put the script on the tester chart in visualization mode, but the trade order opens in MT4 terminal.

I also cannot get information about open orders in the strategy tester using SimpleFXTester_v2.ex4.

Please help me to understand this.

The scripts in the Strategy Tester do not work.
 

Hi.

Can't delete the terminal!

C:\$Recycle.Bin\S-1-5-21-436374069-1993962763-854245398-500\$RSU1FJ4\$R33JNRS

"Sitting" here, delete the folder and it's restored again.... and don't know what to do.

Turned off UAC, doesn't help.

Reason: