help for simple code

 

hi i have a simple ea and i would to add a thing for close order, this is fibonacci so i added the indicators and i would to close order if MAP (moving average with period 1) is near at least 8 pips to lower or high lines of fibonacci, so this is the initial part of intrested code



//...other code

int digits;
double point;


int init()
{
digits=Digits;
point=GetPoints();

}



double GetPoints()
{
if(Digits==3 || Digits==5)point=Point*10;
else point=Point;
return(point);
}

//.....



void CheckForClose()
{


double MAP;

double LOWFIB, HIGHFIB;


LOWFIB=iCustom(Symbol(),0,"Fibos",true,false,0,200,0,0);
HIGHFIB=iCustom(Symbol(),0,"Fibos",true,false,0,200,6,0);

MAP = iCustom(NULL,0,"Moving Averages Red",
1, // Period
0, // Offset
MODE_SMA, // Calculation method
PRICE_CLOSE // Calculating on Close prices
);





And this is the part i'm not sure, i dont know how to do the gap of 8 pips so i wrote LOWFIB+8*point

Like this




if(OrderType()==OP_BUY)
{
if(MAP<LOWFIB+8*point && ...other conditions... ) OrderClose(OrderTicket(),OrderLots(),Bid,slippageclose,White);
break;
}

if(OrderType()==OP_SELL)
{
if(MAP>HIGHFIB-8*point && ...other conditions... ) OrderClose(OrderTicket(),OrderLots(),Ask,slippageclose,White);
break;
}

You think this will work?

thnks

 
If you use the SRC button in the tool bar your code will look like code and not plain text. It is much easier to read.
 
MAP = iCustom(NULL,0,"Moving Averages Red",
1, // Period
0, // Offset
MODE_SMA, // Calculation method
PRICE_CLOSE // Calculating on Close prices
);

Is this any different to using iMA?

https://docs.mql4.com/indicators/ima

 
int digits;
double point;


int init()
{
digits=Digits;
point=GetPoints();

}



double GetPoints()
{
if(Digits==3 || Digits==5)point=Point*10;
else point=Point;
return(point);
}

The above sort of works but is a bit nasty computationally. What you are doing is performing a function call which sets a global variable then returns a copy of that global variable to update itself.

You could, for example, not return anything from GetPoints since you already assigned point with its value.

Or

double GetPoints(){
    if( Digits==3 || Digits==5 )
        return(Point*10);

    return(Point);
}

Although the variable and function should probably be called pips and GetPips respectively.

 

This look curious

if(OrderType()==OP_BUY){
      if(MAP<LOWFIB+8*point && ...other conditions... )
           OrderClose(OrderTicket(),OrderLots(),Bid,slippageclose,White);
      break;
}

It is not clear what you are breaking from.

break has nothing to do with if statements.

https://docs.mql4.com/basis/operators/break

 

this is only part of code dabbler thank you anyway

i've another question

if i want to apply a close condition

like this

if( ...conditions... ) OrderClose(OrderTicket(),...

only when i am in profit,

how could i do?

thank you :D

 
Having successfully selected the order, you can just read the profit using OrderProfit(), but you should add on OrderSwap() and OrderCommision() just to be accurate.