1

I have a problem with my EA trades, now I will show you the code with a screenshot of a trade (it happens often) I see that I was definitely wrong for how the entry below must read I put an image where it explains what I have in mind

void OnTimer()
{
  //---
  if (currBars != Bars){
    calculate_price_levels();
    //debug_levels();
  
    check_nearest_levels();
  
    if (is_session()){
      if (Close[2] < Nearest_Up_Level && Close[1] >= Nearest_Up_Level && isAvailableOrder()){ 
        //Print("BUY entry, Nearest_Up_Level:",Nearest_Up_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);
    
        double lot = _get_lot_size (Stop_Loss);
        OpenTrade(Symbol(), OP_BUY, lot);
      }

      if (Close[2] > Nearest_Down_Level && Close[1] <= Nearest_Down_Level && isAvailableOrder()){
        //Print("SELL entry, Nearest_Down_Level:",Nearest_Down_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);

        double lot = _get_lot_size (Stop_Loss);
        OpenTrade(Symbol(), OP_SELL, lot);
      }
    }

    currBars = Bars;
  }

  if (Trailing_Stop > 0) trail_sl();
  // if (BE > 0) check_be();

  int trades_number = _get_number_of_trades();
  if (trades_number < Trades_Number_0) check_last_trade_result();

  Trades_Number_0 = trades_number;
}

void check_nearest_levels(){
  int size = ArraySize(Price_Levels);

  for (int i = 0; i < size; i++){
    if (Close[2] > Price_Levels[i] && Close[2] < Price_Levels[i + 1]){
      Nearest_Down_Level = Price_Levels[i];
      Nearest_Up_Level = Price_Levels[i + 1];

      BUY_TP_Price = 0;
      if (size > i + 2) BUY_TP_Price = Price_Levels[i + 2];
      else BUY_TP_Price = Nearest_Up_Level + StepPips * Point * mp;

      Next_BUY_TP_Price = 0;
      if (size > i + 3) Next_BUY_TP_Price = Price_Levels[i + 3];
      else Next_BUY_TP_Price = BUY_TP_Price + StepPips * Point * mp;

      SELL_TP_Price = 0;
      if (i >= 1) SELL_TP_Price = Price_Levels[i - 1];
      else SELL_TP_Price = Nearest_Down_Level - StepPips * Point * mp;

      Next_SELL_TP_Price = 0;
      if (i >= 2) Next_SELL_TP_Price = Price_Levels[i - 2];
      else Next_SELL_TP_Price = SELL_TP_Price - StepPips * Point * mp;

      break;
    }
  }
}

image 1

Example of what I want to do
https://i.stack.imgur.com/ec1ji.png

Yun
  • 3,056
  • 6
  • 9
  • 28
  • I have 2 questions: 1. Can you explain in words what is exactly in Price_Levels array and why you need it? 2. Seems to me you simply want to go short below the low of the previous bar, and go long above the high of the previous bar. Is it correct? – Investing TS Nov 04 '21 at 08:21

0 Answers0