Download MetaTrader 5

Sar & Bollinger Bands

To add comments, please log in or register
Tony Chavez
236
Tony Chavez  

For some reason it keeps placing the order at the end of the SAR run right before it switches over.


double UpperBand = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
   double MiddleBand =iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);
   double LowerBand = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
   double sar2 = iSAR(NULL, 0, 0.02, 0.2, 0);
   double sar1 = iSAR(NULL, 0, 0.02, 0.2, 2);
   
   int OrderCount=0;
   for(int pos=OrdersTotal()-1; pos>=0; pos--) 
     {
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() != Symbol()) continue;
      if(OrderSymbol() == Symbol())
         if(OrderType() == OP_BUY || OrderType() == OP_SELL) OrderCount++;
     }

   if(sar2 <= LowerBand && sar2 < sar1 && TrendPhase != 1 && OrderCount <1)
     {
      
         //TheCloser();
         TrendPhase = 1;
        
      if (MarginCheck > .6){
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-0.1,0,NULL,756,0,Green);
      }
     }
   if(sar2 >= UpperBand && sar2 > sar1  && TrendPhase != 2 && OrderCount <1)
     {

         TrendPhase = 2;
     
      if (MarginCheck > .6){
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+0.1,0,NULL,756,0,Red);
      }
     }
SAR Bollinger
whroeder1
15934
whroeder1  
Tony Chavez: For some reason it keeps placing the order at the end of the SAR run right before it switches over.
  1. Your image shows it sold when the PSAR went above and bought when it went below. Working fine.
  2. Your fixed SL is meaningless.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    • Do NOT use TickValue by itself - DeltaPerLot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
    Think about using the BB, PSAR, or last swing.
  3. You are not adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 00.010.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;
To add comments, please log in or register