Coding help - page 778

 

Could someone show me how to make this code shorter? How to use for cycle for this?

extern double S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15;
if (S1==1234) S1=DoubleToString(S1);
if (S2==1234) S2=DoubleToString(S2);
if (S3==1234) S3=DoubleToString(S3);
if (S4==1234) S4=DoubleToString(S4);
if (S5==1234) S5=DoubleToString(S5);
if (S6==1234) S6=DoubleToString(S6);
if (S7==1234) S7=DoubleToString(S7);
if (S8==1234) S8=DoubleToString(S8);
if (S9==1234) S9=DoubleToString(S9);

Would like something like this, but don't know how to change variable names. 

for(i=1; i<=9; i++){
if (S+i==1234) S+i=DoubleToString(S+i);
}
 
Karel Nagel:

Could someone show me how to make this code shorter? How to use for cycle for this?

Would like something like this, but don't know how to change variable names. 

You cannot initialize an array with a list of inputs, due to limitations of MQL. (Only constant expressions like { 2, 5, 3.1 } will do.)

But since you need to convert doubles to strings anyway you can use StringFormat. The interesting thing about this function is it accepts an arbitrary number of arguments.

With the help of StringSplit it can be used to create an array on the fly:

string line=StringFormat("%g %g %g %g %g %g %g %g %g",S1,S2,S3,S4,S5,S6,S7,S8,S9);
string numbers[];
int count=StringSplit(line,' ',numbers);
for(int i=0; i<count; i++)
  {
   if(numbers[i]=="1234") Print(" S",i+1," == 1234");
  }
 
rsiArray[0] = iRSI(NULL,0,10,PRICE_CLOSE,1);
rsiArray[1] = iRSI(NULL,0,10,PRICE_CLOSE,2);
rsiArray[2] = iRSI(NULL,0,10,PRICE_CLOSE,3);
rsiArray[3] = iRSI(NULL,0,10,PRICE_CLOSE,4);
rsiArray[4] = iRSI(NULL,0,10,PRICE_CLOSE,5);
ArraySetAsSeries(rsiArray, true); 

upperEnv = iEnvelopesOnArray(rsiArray, 0, 5,MODE_SMA, 0, 5, MODE_UPPER, 0);
lowerEnv = iEnvelopesOnArray(rsiArray, 0, 5,MODE_SMA, 0, 5, MODE_LOWER, 0); 

Been trying to figure this out for too long now, i need help.

The envelope values aren't corresponding with rsiArray[0] or to any value i see on the charts and i just cant figure out why.


Any ideas?


Thanks

EDIT: (fixed) ok, all i needed to do was restart mt4 and the code worked fine.

 

I've spent hours trying to get an EA/utility to work correctly and made several changes until my brain is numb.  Attached is a preliminary version and I'll improve it once I get past the hurdle of basics working correctly which is to sound an alarm when an open buy/sell order is added and a different alarm when an open order buy/sell is closed.  This version sometimes works and sometimes doesn't so unreliable at this point.


//+------------------------------------------------------------------+
//|               myNotify.mq4                                       |
//|               Notify me by sound file of change in orders        |
//+------------------------------------------------------------------+

//---- input parameters
extern string OrderClosedWav = "OrderClosed.wav";
extern string OrderOpenedWav = "OrderOpened.wav";
string sVersion = "1.39";
int iOld, iNew = 0;
int i = 0;
uchar ii = 0;
long NewOrdersHash = 0;
long OldOrdersHash = 0;

int nOrders = 0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
// +------------------------------------------------------------------+
// |  expert deinitialization function                                |
// +------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
{ 
    nOrders = 0;
    NewOrdersHash = 0;

//First Pass
    for(i=OrdersTotal()-1;i>=0;i--)
       {
         OrderSelect(i, SELECT_BY_POS);
         if (OrderType() < 2)           // NOT "OP_BUYLIMIT" || "OP_BUYSTOP" //|| "OP_SELLLIMIT" || "OP_SELLSTOP")
         {
           NewOrdersHash = NewOrdersHash + OrderTicket();
           nOrders++;
         } 
       } 

OldOrdersHash = NewOrdersHash;
iOld =nOrders;

    Comment ("Ver ",sVersion," \n",
         iOld,"\n", iNew,"\n\n", ii,"\n\n",
         OrderOpenedWav,"\n",
         OrderClosedWav,"\n\n",
         "Old:  ",OldOrdersHash,"\n",
         "New: ",NewOrdersHash,"\n\n",
         nOrders,"\n");
// Wait
         Sleep(2000);

//Second Pass to compare after short pause
    nOrders = 0;
    NewOrdersHash = 0;
    for(i=OrdersTotal()-1;i>=0;i--)
       {
         OrderSelect(i, SELECT_BY_POS);
         if (OrderType() < 2)           // NOT "OP_BUYLIMIT" || "OP_BUYSTOP" //|| "OP_SELLLIMIT" || "OP_SELLSTOP")
         {
           NewOrdersHash = NewOrdersHash + OrderTicket();
           nOrders++;
         } 
       } 
iNew = nOrders;

    if (ii > 24) {ii = 1;} else {ii++;}
       
    Comment ("Ver ",sVersion," \n",
         iOld,"\n", iNew,"\n\n", ii,"\n\n",
         OrderOpenedWav,"\n",
         OrderClosedWav,"\n\n",
         "Old:  ",OldOrdersHash,"\n",
         "New: ",NewOrdersHash,"\n\n",
         nOrders,"\n");
    if (OldOrdersHash != NewOrdersHash)
    {
     if (iNew > iOld)
       PlaySound(OrderOpenedWav);
     else
       PlaySound(OrderClosedWav);
    }

return(0);

}  

/*
void OrdersF()
   {

    nOrders = 0;
    NewOrdersHash = 0;
    for(int i=OrdersTotal()-1;i>=0;i--)
       {
         OrderSelect(i, SELECT_BY_POS);
         if (OrderType() < 2)          
         {
           NewOrdersHash = NewOrdersHash + OrderTicket();
           nOrders++;
         } 
       } 
    iNew = nOrders;
    return;
   }
*/
//+------------------------------------------------------------------+

 

Hi guys, I'm new. I want to do a very simple edit on this indicator

How and where do I just simply put in the Description box of the Horizontal Line, the word,     Alert_     ?

for it to automatically appear?

Looking forward your response



//+------------------------------------------------------------------+

//|                                              horizontal line.mq4 |
//|                                                          Wdholic |
//|                            https://www.mql5.com/en/users/wdholic |
//+------------------------------------------------------------------+
#property copyright "Wdholic"
#property link      "https://www.mql5.com/en/users/wdholic"
#property version   "1.00"
#property strict

#import "cfunctions.dll" 
int      MT4_ScreenToClient(int hWnd, int& iX[]);  
#import
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  { 
    double pmax=ChartGetDouble(0,CHART_PRICE_MAX);
    double pmin=ChartGetDouble(0,CHART_PRICE_MIN);
    double Ymax=ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS)*1.0;
   //  Alert(pmin);Alert(pmax);Alert(Ymax);
   int iCoords[2] ;
    int hWin = WindowHandle( Symbol(), Period());  
   
    MT4_ScreenToClient(hWin, iCoords);    
               
    double cory=iCoords[1]*1.0;
    double range=(pmax-pmin);
    
    double XY= (cory*1.0)/Ymax;
      double P=pmax-XY*range;
     
        
   Line("test_",P,clrAqua);
   WindowRedraw();
   return;
  }
//+------------------------------------------------------------------+

void Line(string t,double P,color C )
{ int a=1;string nm;
    nm="line_"+t+string(a);
  while(ObjectFind(0,nm)==0){ a++; nm="line_"+t+string(a);}
  
if(ObjectFind(0,nm)<0){
  ObjectCreate(0,nm,OBJ_HLINE,0,0,0); 
  ObjectSet( nm,OBJPROP_COLOR,C);}
  ObjectSet( nm,OBJPROP_PRICE1,P);  
  ObjectSet( nm,OBJPROP_SELECTED,1);  
}

 

Can anyone Help me to code this. Putting Rectangle as a high and low of the last 3 months as shown thank you

Files:
INDIxxx.jpg  243 kb
 

someone help with stoploss on previous ma cross



 

Hi,

I have idea. But i don't know mq4 code much. 

Previous high is lower than 2nd previous high, then buy pending order at previous high * 2% or 1% and when price at current candle touch that order buy. 

Previous low is higher than 2nd previous low, then sell pending order at previous low * -2% or -1% and when price at current candle touch that order sell.

Any period. No target No stop loss. Trailing stop loss like opposite.

Grateful to anyone, who can make mq4 code. I need help. Only MT4.

 

Hi ...

Can you make an Expert for  this strategy please

Reinforcement Expert

Settings :

1.    Option: Sell only / Buy only

2.    TP: 50

3.    Sl: 00

4.    Step: 150

5.    Start Lot: 0,1

6.    Multiplication: 1.2.4.8.16… ..

7.    Total orders: 100

8.    Magic Number: 111111

The method of work :

1-   Opening a position at the start automatically by the specified lot size.

2-   Change Tp for all trades on each reinforcement.

According to the following equation: Tp for the last double position covers us all floating loss + profit of the last position.

3-   Return to the beginning lot.

 

 

 
BANSINO Money Maker:

Hi ...

Can you make an Expert for  this strategy please

Reinforcement Expert

Settings :

1.    Option: Sell only / Buy only

2.    TP: 50

3.    Sl: 00

4.    Step: 150

5.    Start Lot: 0,1

6.    Multiplication: 1.2.4.8.16… ..

7.    Total orders: 100

8.    Magic Number: 111111

The method of work :

1-   Opening a position at the start automatically by the specified lot size.

2-   Change Tp for all trades on each reinforcement.

According to the following equation: Tp for the last double position covers us all floating loss + profit of the last position.

3-   Return to the beginning lot.

 

 

Post it as a job in Freelance section.

Reason: