help help

 
extern double TakeProfit = 100;
extern double Lots = 0.2;
extern double TrailingStop = 50;
extern double MATrendPeriod=50;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent ;
double SignalPrevious, MaCurrent, MaPrevious, PRECIOACTUAL = Bid;
int cnt, ticket, total, C, Totalbarras;
double MinimoPrecio=Bid, Maximum=Bid;




if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
// to simplify the coding and speed up access
// data are put into internal variables


MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_LWMA,PRICE_HIGH,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_LWMA,PRICE_LOW,1);
int counted_bars=IndicatorCounted();
C=Bars-counted_bars;



total=OrdersTotal();

// if(total<1)
// {

// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibility

// numero de barras


while(i>=0)
{
if (Low[i]< MinimoPrecio)
MinimoPrecio=Low[i];
if (High[i]> Maximum)
Maximum=High[i];
i--;
}
Alert("For the last ",PRECIOACTUAL,"PRECIO ACTUAL= ",C,"1MEDIA= ",MaCurrent,"2MEDIA= ",MaPrevious," bars Min= ",MinimoPrecio," Max= ",Maximum);




if(MaCurrent == PRECIOACTUAL && Maximum > MinimoPrecio)

{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",0,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());

}
if(MaPrevious== PRECIOACTUAL && Maximum < MinimoPrecio)

{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",0,0,Red);

if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());

}
// }
return(0);

}

1 - Al backtesting make very few positions open, why is this happening?

2 - As you do so that double values take 5-digits and do not take 4 digits?
 

Put this in your init:

   if (Digits < 4) {
      PipPoints = 0.01;
   } else {
      PipPoints = 0.0001;
   }

This will allow you to use PipPoints to set values to correct digit settings.

For example, in a 5 digit broker, you want to use 10 pips for a stop loss, so:

StopLoss = 10;

StopLoss = StopLoss*PipPoints;

Now StopLoss value is 0.00010

on a 4 digit:

StopLoss = 10;

StopLoss = StopLoss*PipPoints;

Now StopLoss value is 0.0001

Works for 3 and 2 digits as well. I hope this helps.

 

By the way, if you click on the SRC button above the text entry location, you will be able to add your code to look like mine.

Also, I found in your code you are using *Point, you would replace that with *PipPoints.

 

  1. You must adjust pip values for 5 digit brokers, TP, SL, and slippage
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  2. MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_LWMA,PRICE_HIGH,0);
    MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_LWMA,PRICE_LOW,1);
    int counted_bars=IndicatorCounted();
    • At the first tick of a new bar iMA(...0) will be very close to iMA(....1) and will vary up and down as the candle forms. Probably not what you want. Use iMA(1) and iMA(2)
    • Are you sure you want to look at the previous bar low vs current bar high? That will usually be one direction.
    • There are no counted_bars in EA's
Reason: